Home | History | Annotate | Line # | Download | only in kern
sys_syscall.c revision 1.7.2.2
      1 /*	$NetBSD: sys_syscall.c,v 1.7.2.2 2008/01/09 01:56:23 matt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by David Laight.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of The NetBSD Foundation nor the names of its
     19  *    contributors may be used to endorse or promote products derived
     20  *    from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  * POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: sys_syscall.c,v 1.7.2.2 2008/01/09 01:56:23 matt Exp $");
     37 
     38 #include <sys/syscall_stats.h>
     39 
     40 /*
     41  * MI indirect system call support.
     42  * Included from sys_indirect.c and compat/netbsd32/netbsd32_indirect.c
     43  *
     44  * SYS_SYSCALL is set to the required function name.
     45  */
     46 
     47 #define CONCAT(a,b) __CONCAT(a,b)
     48 
     49 int
     50 SYS_SYSCALL(struct lwp *l, const struct CONCAT(SYS_SYSCALL, _args) *uap,
     51     register_t *rval)
     52 {
     53 	/* {
     54 		syscallarg(int) code;
     55 		syscallarg(register_t) args[SYS_MAXSYSARGS];
     56 	} */
     57 	const struct sysent *callp;
     58 	struct proc *p = l->l_proc;
     59 	int code;
     60 	int error;
     61 #ifdef NETBSD32_SYSCALL
     62 	register_t args64[SYS_MAXSYSARGS];
     63 	int i, narg;
     64 	#define TRACE_ARGS args64
     65 #else
     66 	#define TRACE_ARGS &SCARG(uap, args[0])
     67 #endif
     68 
     69 	callp = p->p_emul->e_sysent;
     70 
     71 	code = SCARG(uap, code) & (SYS_NSYSENT - 1);
     72 	SYSCALL_COUNT(syscall_counts, code);
     73 	callp += code;
     74 
     75 	if (__predict_false(callp->sy_flags & SYCALL_INDIRECT))
     76 		return ENOSYS;
     77 
     78 	if (__predict_true(!p->p_trace_enabled))
     79 		return callp->sy_call(l, &uap->args, rval);
     80 
     81 #ifdef NETBSD32_SYSCALL
     82 	narg = callp->sy_argsize >> 2;
     83 	for (i = 0; i < narg; i++)
     84 		args64[i] = SCARG(uap, args[i]);
     85 #endif
     86 
     87 	error = trace_enter(code, code, NULL, TRACE_ARGS);
     88 	if (__predict_false(error != 0))
     89 		return error;
     90 	error = callp->sy_call(l, &uap->args, rval);
     91 	trace_exit(code, TRACE_ARGS, rval, error);
     92 	return error;
     93 
     94 	#undef TRACE_ARGS
     95 }
     96