1 /* $NetBSD: kern_xxx.c,v 1.69 2008/04/21 12:56:31 ad Exp $ */
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)kern_xxx.c 8.3 (Berkeley) 2/14/95
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: kern_xxx.c,v 1.69 2008/04/21 12:56:31 ad Exp $");
37 #include "opt_syscall_debug.h"
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
43 #include <sys/reboot.h>
44 #include <sys/syscall.h>
45 #include <sys/sysctl.h>
46 #include <sys/mount.h>
47 #include <sys/syscall.h>
48 #include <sys/syscallargs.h>
49 #include <sys/kauth.h>
53 sys_reboot(struct lwp
*l
, const struct sys_reboot_args
*uap
, register_t
*retval
)
57 syscallarg(char *) bootstr;
60 char *bootstr
, bs
[128];
62 if ((error
= kauth_authorize_system(l
->l_cred
, KAUTH_SYSTEM_REBOOT
,
63 0, NULL
, NULL
, NULL
)) != 0)
67 * Only use the boot string if RB_STRING is set.
69 if ((SCARG(uap
, opt
) & RB_STRING
) &&
70 (error
= copyinstr(SCARG(uap
, bootstr
), bs
, sizeof(bs
), 0)) == 0)
75 * Not all ports use the bootstr currently.
78 cpu_reboot(SCARG(uap
, opt
), bootstr
);
79 KERNEL_UNLOCK_ONE(NULL
);
84 * Pull in the indirect syscall functions here.
85 * They are only actually used if the ports syscall entry code
86 * doesn't special-case SYS_SYSCALL and SYS___SYSCALL
88 * In some cases the generated code for the two functions is identical,
89 * but there isn't a MI way of determining that - so we don't try.
92 #define SYS_SYSCALL sys_syscall
93 #include "sys_syscall.c"
96 #define SYS_SYSCALL sys___syscall
97 #include "sys_syscall.c"
101 #define SCDEBUG_CALLS 0x0001 /* show calls */
102 #define SCDEBUG_RETURNS 0x0002 /* show returns */
103 #define SCDEBUG_ALL 0x0004 /* even syscalls that are implemented */
104 #define SCDEBUG_SHOWARGS 0x0008 /* show arguments to calls */
107 int scdebug
= SCDEBUG_CALLS
|SCDEBUG_RETURNS
|SCDEBUG_SHOWARGS
;
109 int scdebug
= SCDEBUG_CALLS
|SCDEBUG_RETURNS
|SCDEBUG_SHOWARGS
|SCDEBUG_ALL
;
113 scdebug_call(register_t code
, const register_t args
[])
115 struct lwp
*l
= curlwp
;
116 struct proc
*p
= l
->l_proc
;
117 const struct sysent
*sy
;
118 const struct emul
*em
;
121 if (!(scdebug
& SCDEBUG_CALLS
))
125 sy
= &em
->e_sysent
[code
];
126 if (!(scdebug
& SCDEBUG_ALL
|| (int)code
< 0
127 #ifndef __HAVE_MINIMAL_EMUL
128 || code
>= em
->e_nsysent
130 || sy
->sy_call
== sys_nosys
))
133 printf("proc %d (%s): %s num ", p
->p_pid
, p
->p_comm
, em
->e_name
);
135 #ifndef __HAVE_MINIMAL_EMUL
136 || code
>= em
->e_nsysent
139 printf("OUT OF RANGE (%ld)", (long)code
);
141 printf("%ld call: %s", (long)code
, em
->e_syscallnames
[code
]);
142 if (scdebug
& SCDEBUG_SHOWARGS
) {
144 for (i
= 0; i
< sy
->sy_argsize
/sizeof(register_t
); i
++)
145 printf("%s0x%lx", i
== 0 ? "" : ", ",
154 scdebug_ret(register_t code
, int error
, const register_t retval
[])
156 struct lwp
*l
= curlwp
;
157 struct proc
*p
= l
->l_proc
;
158 const struct sysent
*sy
;
159 const struct emul
*em
;
161 if (!(scdebug
& SCDEBUG_RETURNS
))
165 sy
= &em
->e_sysent
[code
];
166 if (!(scdebug
& SCDEBUG_ALL
|| (int)code
< 0
167 #ifndef __HAVE_MINIMAL_EMUL
168 || (int)code
>= em
->e_nsysent
170 || sy
->sy_call
== sys_nosys
))
173 printf("proc %d (%s): %s num ", p
->p_pid
, p
->p_comm
, em
->e_name
);
175 #ifndef __HAVE_MINIMAL_EMUL
176 || code
>= em
->e_nsysent
179 printf("OUT OF RANGE (%ld)", (long)code
);
181 printf("%ld ret: err = %d, rv = 0x%lx,0x%lx", (long)code
,
182 error
, (long)retval
[0], (long)retval
[1]);
185 #endif /* SYSCALL_DEBUG */