1 /* $NetBSD: sys_syscall.c,v 1.2 2007/12/11 12:16:34 lukem 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.2 2007/12/11 12:16:34 lukem 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, void *v, register_t *rval) 51 { 52 struct CONCAT(SYS_SYSCALL, _args) /* { 53 syscallarg(int) code; 54 syscallarg(register_t) args[SYS_MAXSYSARGS]; 55 } */ *uap = v; 56 const struct sysent *callp; 57 struct proc *p = l->l_proc; 58 int code; 59 int error; 60 #ifdef NETBSD32_SYSCALL 61 register_t args64[SYS_MAXSYSARGS]; 62 int i, narg; 63 #define TRACE_ARGS args64 64 #else 65 #define TRACE_ARGS &uap->args 66 #endif 67 68 callp = p->p_emul->e_sysent; 69 70 code = SCARG(uap, code) & (SYS_NSYSENT - 1); 71 SYSCALL_COUNT(syscall_counts, code); 72 callp += code; 73 74 if (__predict_false(callp->sy_flags & SYCALL_INDIRECT)) 75 return ENOSYS; 76 77 if (__predict_true(!p->p_trace_enabled)) 78 return callp->sy_call(l, &uap->args, rval); 79 80 #ifdef NETBSD32_SYSCALL 81 narg = callp->sy_argsize >> 2; 82 for (i = 0; i < narg; i++) 83 args64[i] = SCARG(uap, args[i]); 84 /* XXX systrace will not modify the correct arguments! */ 85 #endif 86 87 error = trace_enter(l, 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(l, code, TRACE_ARGS, rval, error); 92 return error; 93 94 #undef TRACE_ARGS 95 } 96