No empty .Rs/.Re
[netbsd-mini2440.git] / sys / kern / kern_xxx.c
blob66d5b0aa21c86c6ef9ddfb8e003a6e1161a673ee
1 /* $NetBSD: kern_xxx.c,v 1.69 2008/04/21 12:56:31 ad Exp $ */
3 /*
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
9 * are met:
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
29 * SUCH DAMAGE.
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>
42 #include <sys/proc.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>
51 /* ARGSUSED */
52 int
53 sys_reboot(struct lwp *l, const struct sys_reboot_args *uap, register_t *retval)
55 /* {
56 syscallarg(int) opt;
57 syscallarg(char *) bootstr;
58 } */
59 int error;
60 char *bootstr, bs[128];
62 if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_REBOOT,
63 0, NULL, NULL, NULL)) != 0)
64 return (error);
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)
71 bootstr = bs;
72 else
73 bootstr = NULL;
75 * Not all ports use the bootstr currently.
77 KERNEL_LOCK(1, NULL);
78 cpu_reboot(SCARG(uap, opt), bootstr);
79 KERNEL_UNLOCK_ONE(NULL);
80 return (0);
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"
94 #undef SYS_SYSCALL
96 #define SYS_SYSCALL sys___syscall
97 #include "sys_syscall.c"
98 #undef SYS_SYSCALL
100 #ifdef SYSCALL_DEBUG
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 */
106 #if 0
107 int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS;
108 #else
109 int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS|SCDEBUG_ALL;
110 #endif
112 void
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;
119 int i;
121 if (!(scdebug & SCDEBUG_CALLS))
122 return;
124 em = p->p_emul;
125 sy = &em->e_sysent[code];
126 if (!(scdebug & SCDEBUG_ALL || (int)code < 0
127 #ifndef __HAVE_MINIMAL_EMUL
128 || code >= em->e_nsysent
129 #endif
130 || sy->sy_call == sys_nosys))
131 return;
133 printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name);
134 if ((int)code < 0
135 #ifndef __HAVE_MINIMAL_EMUL
136 || code >= em->e_nsysent
137 #endif
139 printf("OUT OF RANGE (%ld)", (long)code);
140 else {
141 printf("%ld call: %s", (long)code, em->e_syscallnames[code]);
142 if (scdebug & SCDEBUG_SHOWARGS) {
143 printf("(");
144 for (i = 0; i < sy->sy_argsize/sizeof(register_t); i++)
145 printf("%s0x%lx", i == 0 ? "" : ", ",
146 (long)args[i]);
147 printf(")");
150 printf("\n");
153 void
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))
162 return;
164 em = p->p_emul;
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
169 #endif
170 || sy->sy_call == sys_nosys))
171 return;
173 printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name);
174 if ((int)code < 0
175 #ifndef __HAVE_MINIMAL_EMUL
176 || code >= em->e_nsysent
177 #endif
179 printf("OUT OF RANGE (%ld)", (long)code);
180 else
181 printf("%ld ret: err = %d, rv = 0x%lx,0x%lx", (long)code,
182 error, (long)retval[0], (long)retval[1]);
183 printf("\n");
185 #endif /* SYSCALL_DEBUG */