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