1 /* $OpenBSD: kern_xxx.c,v 1.4 1996/08/26 09:16:01 deraadt 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. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 37 */ 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 <vm/vm.h> 45 #include <sys/sysctl.h> 46 #include <sys/mount.h> 47 #include <sys/syscallargs.h> 48 49 /* ARGSUSED */ 50 int 51 sys_reboot(p, v, retval) 52 struct proc *p; 53 void *v; 54 register_t *retval; 55 { 56 struct sys_reboot_args /* { 57 syscallarg(int) opt; 58 } */ *uap = v; 59 int error; 60 61 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) 62 return (error); 63 boot(SCARG(uap, opt)); 64 return (0); 65 } 66 67 #ifdef SYSCALL_DEBUG 68 #define SCDEBUG_CALLS 0x0001 /* show calls */ 69 #define SCDEBUG_RETURNS 0x0002 /* show returns */ 70 #define SCDEBUG_ALL 0x0004 /* even syscalls that are implemented */ 71 #define SCDEBUG_SHOWARGS 0x0008 /* show arguments to calls */ 72 73 int scdebug = SCDEBUG_CALLS|SCDEBUG_RETURNS|SCDEBUG_SHOWARGS; 74 75 void 76 scdebug_call(p, code, args) 77 struct proc *p; 78 register_t code, args[]; 79 { 80 struct sysent *sy; 81 struct emul *em; 82 int i; 83 84 if (!(scdebug & SCDEBUG_CALLS)) 85 return; 86 87 em = p->p_emul; 88 sy = &em->e_sysent[code]; 89 if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent || 90 sy->sy_call == sys_nosys)) 91 return; 92 93 printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name); 94 if (code < 0 || code >= em->e_nsysent) 95 printf("OUT OF RANGE (%d)", code); 96 else { 97 printf("%d call: %s", code, em->e_syscallnames[code]); 98 if (scdebug & SCDEBUG_SHOWARGS) { 99 printf("("); 100 for (i = 0; i < sy->sy_argsize / sizeof(register_t); 101 i++) 102 printf("%s0x%lx", i == 0 ? "" : ", ", 103 (long)args[i]); 104 printf(")"); 105 } 106 } 107 printf("\n"); 108 } 109 110 void 111 scdebug_ret(p, code, error, retval) 112 struct proc *p; 113 register_t code; 114 int error; 115 register_t retval[]; 116 { 117 struct sysent *sy; 118 struct emul *em; 119 120 if (!(scdebug & SCDEBUG_RETURNS)) 121 return; 122 123 em = p->p_emul; 124 sy = &em->e_sysent[code]; 125 if (!(scdebug & SCDEBUG_ALL || code < 0 || code >= em->e_nsysent || 126 sy->sy_call == sys_nosys)) 127 return; 128 129 printf("proc %d (%s): %s num ", p->p_pid, p->p_comm, em->e_name); 130 if (code < 0 || code >= em->e_nsysent) 131 printf("OUT OF RANGE (%d)", code); 132 else 133 printf("%d ret: err = %d, rv = 0x%lx,0x%lx", code, 134 error, (long)retval[0], (long)retval[1]); 135 printf("\n"); 136 } 137 #endif /* SYSCALL_DEBUG */ 138