FreeBSD/Linux Kernel Cross Reference
sys/kern/kern_xxx.c
1 /* $NetBSD: kern_xxx.c,v 1.54 2005/02/26 21:34:55 perry Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
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.
18 *
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.
30 *
31 * @(#)kern_xxx.c 8.3 (Berkeley) 2/14/95
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: kern_xxx.c,v 1.54 2005/02/26 21:34:55 perry Exp $");
36
37 #include "opt_syscall_debug.h"
38
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/sa.h>
48 #include <sys/syscallargs.h>
49
50 /* ARGSUSED */
51 int
52 sys_reboot(l, v, retval)
53 struct lwp *l;
54 void *v;
55 register_t *retval;
56 {
57 struct sys_reboot_args /* {
58 syscallarg(int) opt;
59 syscallarg(char *) bootstr;
60 } */ *uap = v;
61 struct proc *p = l->l_proc;
62 int error;
63 char *bootstr, bs[128];
64
65 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
66 return (error);
67
68 /*
69 * Only use the boot string if RB_STRING is set.
70 */
71 if ((SCARG(uap, opt) & RB_STRING) &&
72 (error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0)) == 0)
73 bootstr = bs;
74 else
75 bootstr = NULL;
76 /*
77 * Not all ports use the bootstr currently.
78 */
79 cpu_reboot(SCARG(uap, opt), bootstr);
80 return (0);
81 }
82
83 #ifdef SYSCALL_DEBUG
84 #define SCDEBUG_CALLS 0x0001 /* show calls */
85 #define SCDEBUG_RETURNS 0x0002 /* show returns */
86 #define SCDEBUG_ALL 0x0004 /* even syscalls that are implemented */
87 #define SCDEBUG_SHOWARGS 0x0008 /* show arguments to calls */
88
89 #if 0
90 int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS;
91 #else
92 int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS|SCDEBUG_ALL;
93 #endif
94
95 void
96 scdebug_call(l, code, args)
97 struct lwp *l;
98 register_t code, args[];
99 {
100 struct proc *p = l->l_proc;
101 const struct sysent *sy;
102 const struct emul *em;
103 int i;
104
105 if (!(scdebug & SCDEBUG_CALLS))
106 return;
107
108 em = p->p_emul;
109 sy = &em->e_sysent[code];
110 if (!(scdebug & SCDEBUG_ALL || code < 0
111 #ifndef __HAVE_MINIMAL_EMUL
112 || code >= em->e_nsysent
113 #endif
114 || sy->sy_call == sys_nosys))
115 return;
116
117 printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name);
118 if (code < 0
119 #ifndef __HAVE_MINIMAL_EMUL
120 || code >= em->e_nsysent
121 #endif
122 )
123 printf("OUT OF RANGE (%ld)", (long)code);
124 else {
125 printf("%ld call: %s", (long)code, em->e_syscallnames[code]);
126 if (scdebug & SCDEBUG_SHOWARGS) {
127 printf("(");
128 for (i = 0; i < sy->sy_argsize/sizeof(register_t); i++)
129 printf("%s0x%lx", i == 0 ? "" : ", ",
130 (long)args[i]);
131 printf(")");
132 }
133 }
134 printf("\n");
135 }
136
137 void
138 scdebug_ret(l, code, error, retval)
139 struct lwp *l;
140 register_t code;
141 int error;
142 register_t retval[];
143 {
144 struct proc *p = l->l_proc;
145 const struct sysent *sy;
146 const struct emul *em;
147
148 if (!(scdebug & SCDEBUG_RETURNS))
149 return;
150
151 em = p->p_emul;
152 sy = &em->e_sysent[code];
153 if (!(scdebug & SCDEBUG_ALL || code < 0
154 #ifndef __HAVE_MINIMAL_EMUL
155 || code >= em->e_nsysent
156 #endif
157 || sy->sy_call == sys_nosys))
158 return;
159
160 printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name);
161 if (code < 0
162 #ifndef __HAVE_MINIMAL_EMUL
163 || code >= em->e_nsysent
164 #endif
165 )
166 printf("OUT OF RANGE (%ld)", (long)code);
167 else
168 printf("%ld ret: err = %d, rv = 0x%lx,0x%lx", (long)code,
169 error, (long)retval[0], (long)retval[1]);
170 printf("\n");
171 }
172 #endif /* SYSCALL_DEBUG */
Cache object: d949f69b69835a3114c513ab7981917e
|