Line data Source code
1 : /* $OpenBSD: kern_xxx.c,v 1.35 2018/03/08 22:04:18 bluhm Exp $ */
2 : /* $NetBSD: kern_xxx.c,v 1.32 1996/04/22 01:38:41 christos Exp $ */
3 :
4 : /*
5 : * Copyright (c) 1982, 1986, 1989, 1993
6 : * The Regents of the University of California. All rights reserved.
7 : *
8 : * Redistribution and use in source and binary forms, with or without
9 : * modification, are permitted provided that the following conditions
10 : * are met:
11 : * 1. Redistributions of source code must retain the above copyright
12 : * notice, this list of conditions and the following disclaimer.
13 : * 2. Redistributions in binary form must reproduce the above copyright
14 : * notice, this list of conditions and the following disclaimer in the
15 : * documentation and/or other materials provided with the distribution.
16 : * 3. Neither the name of the University nor the names of its contributors
17 : * may be used to endorse or promote products derived from this software
18 : * without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 : * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 : * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 : * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 : * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 : * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 : * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 : * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 : * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 : * SUCH DAMAGE.
31 : *
32 : * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93
33 : */
34 :
35 : #include <sys/param.h>
36 : #include <sys/systm.h>
37 : #include <sys/kernel.h>
38 : #include <sys/reboot.h>
39 : #include <sys/sysctl.h>
40 : #include <sys/mount.h>
41 : #include <sys/syscallargs.h>
42 :
43 : int rebooting = 0;
44 :
45 : int
46 0 : sys_reboot(struct proc *p, void *v, register_t *retval)
47 : {
48 : struct sys_reboot_args /* {
49 : syscallarg(int) opt;
50 0 : } */ *uap = v;
51 : int error;
52 :
53 0 : if ((error = suser(p)) != 0)
54 0 : return (error);
55 :
56 : #ifdef MULTIPROCESSOR
57 0 : sched_stop_secondary_cpus();
58 0 : KASSERT(CPU_IS_PRIMARY(curcpu()));
59 : #endif
60 0 : reboot(SCARG(uap, opt));
61 : /* NOTREACHED */
62 : return (0);
63 : }
64 :
65 : __dead void
66 0 : reboot(int howto)
67 : {
68 0 : KASSERT((howto & RB_NOSYNC) || curproc != NULL);
69 :
70 0 : stop_periodic_resettodr();
71 :
72 0 : rebooting = 1;
73 :
74 0 : boot(howto);
75 : /* NOTREACHED */
76 : }
77 :
78 : #if !defined(NO_PROPOLICE)
79 : void __stack_smash_handler(char [], int __attribute__((unused)));
80 :
81 : void
82 0 : __stack_smash_handler(char func[], int damaged)
83 : {
84 0 : panic("smashed stack in %s", func);
85 : }
86 : #endif
87 :
88 : #ifdef SYSCALL_DEBUG
89 : #include <sys/proc.h>
90 :
91 : #define SCDEBUG_CALLS 0x0001 /* show calls */
92 : #define SCDEBUG_RETURNS 0x0002 /* show returns */
93 : #define SCDEBUG_ALL 0x0004 /* even syscalls that are implemented */
94 : #define SCDEBUG_SHOWARGS 0x0008 /* show arguments to calls */
95 :
96 : int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS;
97 :
98 : void
99 : scdebug_call(struct proc *p, register_t code, const register_t args[])
100 : {
101 : struct process *pr;
102 : struct sysent *sy;
103 : struct emul *em;
104 : int i;
105 :
106 : if (!(scdebug & SCDEBUG_CALLS))
107 : return;
108 :
109 : pr = p->p_p;
110 : em = pr->ps_emul;
111 : sy = &em->e_sysent[code];
112 : if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent ||
113 : sy->sy_call == sys_nosys))
114 : return;
115 :
116 : printf("proc %d (%s): %s num ", pr->ps_pid, pr->ps_comm, em->e_name);
117 : if (code < 0 || code >= em->e_nsysent)
118 : printf("OUT OF RANGE (%ld)", code);
119 : else {
120 : printf("%ld call: %s", code, em->e_syscallnames[code]);
121 : if (scdebug & SCDEBUG_SHOWARGS) {
122 : printf("(");
123 : for (i = 0; i < sy->sy_argsize / sizeof(register_t);
124 : i++)
125 : printf("%s0x%lx", i == 0 ? "" : ", ", args[i]);
126 : printf(")");
127 : }
128 : }
129 : printf("\n");
130 : }
131 :
132 : void
133 : scdebug_ret(struct proc *p, register_t code, int error,
134 : const register_t retval[])
135 : {
136 : struct process *pr;
137 : struct sysent *sy;
138 : struct emul *em;
139 :
140 : if (!(scdebug & SCDEBUG_RETURNS))
141 : return;
142 :
143 : pr = p->p_p;
144 : em = pr->ps_emul;
145 : sy = &em->e_sysent[code];
146 : if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent ||
147 : sy->sy_call == sys_nosys))
148 : return;
149 :
150 : printf("proc %d (%s): %s num ", pr->ps_pid, pr->ps_comm, em->e_name);
151 : if (code < 0 || code >= em->e_nsysent)
152 : printf("OUT OF RANGE (%ld)", code);
153 : else
154 : printf("%ld ret: err = %d, rv = 0x%lx,0x%lx", code,
155 : error, retval[0], retval[1]);
156 : printf("\n");
157 : }
158 : #endif /* SYSCALL_DEBUG */
|