sys_syscall.c revision 1.1.8.4 1 /* $NetBSD: sys_syscall.c,v 1.1.8.4 2008/02/18 21:06:47 mjf 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.1.8.4 2008/02/18 21:06:47 mjf 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 int narg;
62 #ifdef NETBSD32_SYSCALL
63 register_t args64[SYS_MAXSYSARGS];
64 int i;
65 #define TRACE_ARGS args64
66 #else
67 #define TRACE_ARGS &SCARG(uap, args[0])
68 #endif
69
70 callp = p->p_emul->e_sysent;
71
72 code = SCARG(uap, code) & (SYS_NSYSENT - 1);
73 SYSCALL_COUNT(syscall_counts, code);
74 callp += code;
75
76 if (__predict_false(callp->sy_flags & SYCALL_INDIRECT))
77 return ENOSYS;
78
79 if (__predict_true(!p->p_trace_enabled))
80 return callp->sy_call(l, &uap->args, rval);
81
82 narg = callp->sy_narg;
83 #ifdef NETBSD32_SYSCALL
84 for (i = 0; i < narg; i++)
85 args64[i] = SCARG(uap, args[i]);
86 #endif
87
88 error = trace_enter(code, TRACE_ARGS, narg);
89 if (__predict_false(error != 0))
90 return error;
91 error = callp->sy_call(l, &uap->args, rval);
92 trace_exit(code, rval, error);
93 return error;
94
95 #undef TRACE_ARGS
96 }
97