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