Home | History | Annotate | Line # | Download | only in common
kern_sig_43.c revision 1.8
      1 /*	$NetBSD: kern_sig_43.c,v 1.8 1998/07/05 08:49:44 jonathan 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 "opt_compat_netbsd.h"
     44 
     45 #include <sys/param.h>
     46 #include <sys/signalvar.h>
     47 #include <sys/resourcevar.h>
     48 #include <sys/namei.h>
     49 #include <sys/vnode.h>
     50 #include <sys/proc.h>
     51 #include <sys/systm.h>
     52 #include <sys/timeb.h>
     53 #include <sys/times.h>
     54 #include <sys/buf.h>
     55 #include <sys/acct.h>
     56 #include <sys/file.h>
     57 #include <sys/kernel.h>
     58 #include <sys/wait.h>
     59 #include <sys/ktrace.h>
     60 #include <sys/syslog.h>
     61 #include <sys/stat.h>
     62 #include <sys/core.h>
     63 
     64 #include <sys/mount.h>
     65 #include <sys/syscallargs.h>
     66 
     67 #include <machine/cpu.h>
     68 
     69 #include <vm/vm.h>
     70 #include <sys/user.h>		/* for coredump */
     71 
     72 int
     73 compat_43_sys_sigblock(p, v, retval)
     74 	register struct proc *p;
     75 	void *v;
     76 	register_t *retval;
     77 {
     78 	struct compat_43_sys_sigblock_args /* {
     79 		syscallarg(int) mask;
     80 	} */ *uap = v;
     81 
     82 	(void) splhigh();
     83 	*retval = p->p_sigmask;
     84 	p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
     85 	(void) spl0();
     86 	return (0);
     87 }
     88 
     89 
     90 int
     91 compat_43_sys_sigsetmask(p, v, retval)
     92 	struct proc *p;
     93 	void *v;
     94 	register_t *retval;
     95 {
     96 	struct compat_43_sys_sigsetmask_args /* {
     97 		syscallarg(int) mask;
     98 	} */ *uap = v;
     99 
    100 	(void) splhigh();
    101 	*retval = p->p_sigmask;
    102 	p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
    103 	(void) spl0();
    104 	return (0);
    105 }
    106 
    107 
    108 /* ARGSUSED */
    109 int
    110 compat_43_sys_sigstack(p, v, retval)
    111 	struct proc *p;
    112 	void *v;
    113 	register_t *retval;
    114 {
    115 	register struct compat_43_sys_sigstack_args /* {
    116 		syscallarg(struct sigstack *) nss;
    117 		syscallarg(struct sigstack *) oss;
    118 	} */ *uap = v;
    119 	struct sigstack ss;
    120 	struct sigacts *psp;
    121 	int error = 0;
    122 
    123 	psp = p->p_sigacts;
    124 	ss.ss_sp = psp->ps_sigstk.ss_sp;
    125 	ss.ss_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
    126 	if (SCARG(uap, oss) && (error = copyout((caddr_t)&ss,
    127 	    (caddr_t)SCARG(uap, oss), sizeof (struct sigstack))))
    128 		return (error);
    129 	if (SCARG(uap, nss) == 0)
    130 		return (0);
    131 	error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss,
    132 	    sizeof (ss));
    133 	if (error)
    134 		return (error);
    135 	psp->ps_flags |= SAS_ALTSTACK;
    136 	psp->ps_sigstk.ss_sp = ss.ss_sp;
    137 	psp->ps_sigstk.ss_size = 0;
    138 	psp->ps_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK;
    139 	return (0);
    140 }
    141 
    142 /*
    143  * Generalized interface signal handler, 4.3-compatible.
    144  */
    145 /* ARGSUSED */
    146 int
    147 compat_43_sys_sigvec(p, v, retval)
    148 	struct proc *p;
    149 	void *v;
    150 	register_t *retval;
    151 {
    152 	register struct compat_43_sys_sigvec_args /* {
    153 		syscallarg(int) signum;
    154 		syscallarg(struct sigvec *) nsv;
    155 		syscallarg(struct sigvec *) osv;
    156 	} */ *uap = v;
    157 	struct sigvec vec;
    158 	register struct sigacts *ps = p->p_sigacts;
    159 	register struct sigvec *sv;
    160 	register int signum;
    161 	int bit, error;
    162 
    163 	signum = SCARG(uap, signum);
    164 	if (signum <= 0 || signum >= NSIG ||
    165 	    signum == SIGKILL || signum == SIGSTOP)
    166 		return (EINVAL);
    167 	sv = &vec;
    168 	if (SCARG(uap, osv)) {
    169 		*(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
    170 		sv->sv_mask = ps->ps_catchmask[signum];
    171 		bit = sigmask(signum);
    172 		sv->sv_flags = 0;
    173 		if ((ps->ps_sigonstack & bit) != 0)
    174 			sv->sv_flags |= SV_ONSTACK;
    175 		if ((ps->ps_sigintr & bit) != 0)
    176 			sv->sv_flags |= SV_INTERRUPT;
    177 		if ((ps->ps_sigreset & bit) != 0)
    178 			sv->sv_flags |= SV_RESETHAND;
    179 		if (p->p_flag & P_NOCLDSTOP)
    180 			sv->sv_flags |= SA_NOCLDSTOP;
    181 		sv->sv_mask &= ~bit;
    182 		error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
    183 		    sizeof (vec));
    184 		if (error)
    185 			return (error);
    186 	}
    187 	if (SCARG(uap, nsv)) {
    188 		error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
    189 		    sizeof (vec));
    190 		if (error)
    191 			return (error);
    192 		sv->sv_flags ^= SA_RESTART;	/* opposite of SV_INTERRUPT */
    193 		setsigvec(p, signum, (struct sigaction *)sv);
    194 	}
    195 	return (0);
    196 }
    197 
    198 
    199 /* ARGSUSED */
    200 int
    201 compat_43_sys_killpg(p, v, retval)
    202 	struct proc *p;
    203 	void *v;
    204 	register_t *retval;
    205 {
    206 	register struct compat_43_sys_killpg_args /* {
    207 		syscallarg(int) pgid;
    208 		syscallarg(int) signum;
    209 	} */ *uap = v;
    210 
    211 #ifdef COMPAT_09
    212 	SCARG(uap, pgid) = (short) SCARG(uap, pgid);
    213 #endif
    214 
    215 	if ((u_int)SCARG(uap, signum) >= NSIG)
    216 		return (EINVAL);
    217 	return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
    218 }
    219