1 /* $NetBSD: kern_sig_43.c,v 1.7 1996/03/14 19:31:47 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1982, 1986, 1989, 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 41 */ 42 43 #include <sys/param.h> 44 #include <sys/signalvar.h> 45 #include <sys/resourcevar.h> 46 #include <sys/namei.h> 47 #include <sys/vnode.h> 48 #include <sys/proc.h> 49 #include <sys/systm.h> 50 #include <sys/timeb.h> 51 #include <sys/times.h> 52 #include <sys/buf.h> 53 #include <sys/acct.h> 54 #include <sys/file.h> 55 #include <sys/kernel.h> 56 #include <sys/wait.h> 57 #include <sys/ktrace.h> 58 #include <sys/syslog.h> 59 #include <sys/stat.h> 60 #include <sys/core.h> 61 62 #include <sys/mount.h> 63 #include <sys/syscallargs.h> 64 65 #include <machine/cpu.h> 66 67 #include <vm/vm.h> 68 #include <sys/user.h> /* for coredump */ 69 70 int 71 compat_43_sys_sigblock(p, v, retval) 72 register struct proc *p; 73 void *v; 74 register_t *retval; 75 { 76 struct compat_43_sys_sigblock_args /* { 77 syscallarg(int) mask; 78 } */ *uap = v; 79 80 (void) splhigh(); 81 *retval = p->p_sigmask; 82 p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask; 83 (void) spl0(); 84 return (0); 85 } 86 87 88 int 89 compat_43_sys_sigsetmask(p, v, retval) 90 struct proc *p; 91 void *v; 92 register_t *retval; 93 { 94 struct compat_43_sys_sigsetmask_args /* { 95 syscallarg(int) mask; 96 } */ *uap = v; 97 98 (void) splhigh(); 99 *retval = p->p_sigmask; 100 p->p_sigmask = SCARG(uap, mask) &~ sigcantmask; 101 (void) spl0(); 102 return (0); 103 } 104 105 106 /* ARGSUSED */ 107 int 108 compat_43_sys_sigstack(p, v, retval) 109 struct proc *p; 110 void *v; 111 register_t *retval; 112 { 113 register struct compat_43_sys_sigstack_args /* { 114 syscallarg(struct sigstack *) nss; 115 syscallarg(struct sigstack *) oss; 116 } */ *uap = v; 117 struct sigstack ss; 118 struct sigacts *psp; 119 int error = 0; 120 121 psp = p->p_sigacts; 122 ss.ss_sp = psp->ps_sigstk.ss_sp; 123 ss.ss_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK; 124 if (SCARG(uap, oss) && (error = copyout((caddr_t)&ss, 125 (caddr_t)SCARG(uap, oss), sizeof (struct sigstack)))) 126 return (error); 127 if (SCARG(uap, nss) == 0) 128 return (0); 129 error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss, 130 sizeof (ss)); 131 if (error) 132 return (error); 133 psp->ps_flags |= SAS_ALTSTACK; 134 psp->ps_sigstk.ss_sp = ss.ss_sp; 135 psp->ps_sigstk.ss_size = 0; 136 psp->ps_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK; 137 return (0); 138 } 139 140 /* 141 * Generalized interface signal handler, 4.3-compatible. 142 */ 143 /* ARGSUSED */ 144 int 145 compat_43_sys_sigvec(p, v, retval) 146 struct proc *p; 147 void *v; 148 register_t *retval; 149 { 150 register struct compat_43_sys_sigvec_args /* { 151 syscallarg(int) signum; 152 syscallarg(struct sigvec *) nsv; 153 syscallarg(struct sigvec *) osv; 154 } */ *uap = v; 155 struct sigvec vec; 156 register struct sigacts *ps = p->p_sigacts; 157 register struct sigvec *sv; 158 register int signum; 159 int bit, error; 160 161 signum = SCARG(uap, signum); 162 if (signum <= 0 || signum >= NSIG || 163 signum == SIGKILL || signum == SIGSTOP) 164 return (EINVAL); 165 sv = &vec; 166 if (SCARG(uap, osv)) { 167 *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum]; 168 sv->sv_mask = ps->ps_catchmask[signum]; 169 bit = sigmask(signum); 170 sv->sv_flags = 0; 171 if ((ps->ps_sigonstack & bit) != 0) 172 sv->sv_flags |= SV_ONSTACK; 173 if ((ps->ps_sigintr & bit) != 0) 174 sv->sv_flags |= SV_INTERRUPT; 175 if ((ps->ps_sigreset & bit) != 0) 176 sv->sv_flags |= SV_RESETHAND; 177 if (p->p_flag & P_NOCLDSTOP) 178 sv->sv_flags |= SA_NOCLDSTOP; 179 sv->sv_mask &= ~bit; 180 error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv), 181 sizeof (vec)); 182 if (error) 183 return (error); 184 } 185 if (SCARG(uap, nsv)) { 186 error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv, 187 sizeof (vec)); 188 if (error) 189 return (error); 190 sv->sv_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */ 191 setsigvec(p, signum, (struct sigaction *)sv); 192 } 193 return (0); 194 } 195 196 197 /* ARGSUSED */ 198 int 199 compat_43_sys_killpg(p, v, retval) 200 struct proc *p; 201 void *v; 202 register_t *retval; 203 { 204 register struct compat_43_sys_killpg_args /* { 205 syscallarg(int) pgid; 206 syscallarg(int) signum; 207 } */ *uap = v; 208 209 #ifdef COMPAT_09 210 SCARG(uap, pgid) = (short) SCARG(uap, pgid); 211 #endif 212 213 if ((u_int)SCARG(uap, signum) >= NSIG) 214 return (EINVAL); 215 return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0)); 216 } 217