Home | History | Annotate | Line # | Download | only in common
kern_sig_43.c revision 1.1
      1  1.1  christos /*	$NetBSD: kern_sig_43.c,v 1.1 1995/06/24 20:16:21 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.1  christos compat_43_sigblock(p, uap, retval)
     72  1.1  christos 	register struct proc *p;
     73  1.1  christos 	struct compat_43_sigblock_args /* {
     74  1.1  christos 		syscallarg(int) mask;
     75  1.1  christos 	} */ *uap;
     76  1.1  christos 	register_t *retval;
     77  1.1  christos {
     78  1.1  christos 
     79  1.1  christos 	(void) splhigh();
     80  1.1  christos 	*retval = p->p_sigmask;
     81  1.1  christos 	p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
     82  1.1  christos 	(void) spl0();
     83  1.1  christos 	return (0);
     84  1.1  christos }
     85  1.1  christos 
     86  1.1  christos 
     87  1.1  christos int
     88  1.1  christos compat_43_sigsetmask(p, uap, retval)
     89  1.1  christos 	struct proc *p;
     90  1.1  christos 	struct compat_43_sigsetmask_args /* {
     91  1.1  christos 		syscallarg(int) mask;
     92  1.1  christos 	} */ *uap;
     93  1.1  christos 	register_t *retval;
     94  1.1  christos {
     95  1.1  christos 
     96  1.1  christos 	(void) splhigh();
     97  1.1  christos 	*retval = p->p_sigmask;
     98  1.1  christos 	p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
     99  1.1  christos 	(void) spl0();
    100  1.1  christos 	return (0);
    101  1.1  christos }
    102  1.1  christos 
    103  1.1  christos 
    104  1.1  christos /* ARGSUSED */
    105  1.1  christos int
    106  1.1  christos compat_43_sigstack(p, uap, retval)
    107  1.1  christos 	struct proc *p;
    108  1.1  christos 	register struct compat_43_sigstack_args /* {
    109  1.1  christos 		syscallarg(struct sigstack *) nss;
    110  1.1  christos 		syscallarg(struct sigstack *) oss;
    111  1.1  christos 	} */ *uap;
    112  1.1  christos 	register_t *retval;
    113  1.1  christos {
    114  1.1  christos 	struct sigstack ss;
    115  1.1  christos 	struct sigacts *psp;
    116  1.1  christos 	int error = 0;
    117  1.1  christos 
    118  1.1  christos 	psp = p->p_sigacts;
    119  1.1  christos 	ss.ss_sp = psp->ps_sigstk.ss_base;
    120  1.1  christos 	ss.ss_onstack = psp->ps_sigstk.ss_flags & SA_ONSTACK;
    121  1.1  christos 	if (SCARG(uap, oss) && (error = copyout((caddr_t)&ss,
    122  1.1  christos 	    (caddr_t)SCARG(uap, oss), sizeof (struct sigstack))))
    123  1.1  christos 		return (error);
    124  1.1  christos 	if (SCARG(uap, nss) && (error = copyin((caddr_t)SCARG(uap, nss),
    125  1.1  christos 	    (caddr_t)&ss, sizeof (ss))) == 0) {
    126  1.1  christos 		psp->ps_sigstk.ss_base = ss.ss_sp;
    127  1.1  christos 		psp->ps_sigstk.ss_size = 0;
    128  1.1  christos 		psp->ps_sigstk.ss_flags |= ss.ss_onstack & SA_ONSTACK;
    129  1.1  christos 		psp->ps_flags |= SAS_ALTSTACK;
    130  1.1  christos 	}
    131  1.1  christos 	return (error);
    132  1.1  christos }
    133  1.1  christos 
    134  1.1  christos /*
    135  1.1  christos  * Generalized interface signal handler, 4.3-compatible.
    136  1.1  christos  */
    137  1.1  christos /* ARGSUSED */
    138  1.1  christos int
    139  1.1  christos compat_43_sigvec(p, uap, retval)
    140  1.1  christos 	struct proc *p;
    141  1.1  christos 	register struct compat_43_sigvec_args /* {
    142  1.1  christos 		syscallarg(int) signum;
    143  1.1  christos 		syscallarg(struct sigvec *) nsv;
    144  1.1  christos 		syscallarg(struct sigvec *) osv;
    145  1.1  christos 	} */ *uap;
    146  1.1  christos 	register_t *retval;
    147  1.1  christos {
    148  1.1  christos 	struct sigvec vec;
    149  1.1  christos 	register struct sigacts *ps = p->p_sigacts;
    150  1.1  christos 	register struct sigvec *sv;
    151  1.1  christos 	register int signum;
    152  1.1  christos 	int bit, error;
    153  1.1  christos 
    154  1.1  christos 	signum = SCARG(uap, signum);
    155  1.1  christos 	if (signum <= 0 || signum >= NSIG ||
    156  1.1  christos 	    signum == SIGKILL || signum == SIGSTOP)
    157  1.1  christos 		return (EINVAL);
    158  1.1  christos 	sv = &vec;
    159  1.1  christos 	if (SCARG(uap, osv)) {
    160  1.1  christos 		*(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
    161  1.1  christos 		sv->sv_mask = ps->ps_catchmask[signum];
    162  1.1  christos 		bit = sigmask(signum);
    163  1.1  christos 		sv->sv_flags = 0;
    164  1.1  christos 		if ((ps->ps_sigonstack & bit) != 0)
    165  1.1  christos 			sv->sv_flags |= SV_ONSTACK;
    166  1.1  christos 		if ((ps->ps_sigintr & bit) != 0)
    167  1.1  christos 			sv->sv_flags |= SV_INTERRUPT;
    168  1.1  christos 		if (p->p_flag & P_NOCLDSTOP)
    169  1.1  christos 			sv->sv_flags |= SA_NOCLDSTOP;
    170  1.1  christos 		if (error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
    171  1.1  christos 		    sizeof (vec)))
    172  1.1  christos 			return (error);
    173  1.1  christos 	}
    174  1.1  christos 	if (SCARG(uap, nsv)) {
    175  1.1  christos 		if (error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
    176  1.1  christos 		    sizeof (vec)))
    177  1.1  christos 			return (error);
    178  1.1  christos 		sv->sv_flags ^= SA_RESTART;	/* opposite of SV_INTERRUPT */
    179  1.1  christos 		setsigvec(p, signum, (struct sigaction *)sv);
    180  1.1  christos 	}
    181  1.1  christos 	return (0);
    182  1.1  christos }
    183  1.1  christos 
    184  1.1  christos 
    185  1.1  christos /* ARGSUSED */
    186  1.1  christos int
    187  1.1  christos compat_43_killpg(p, uap, retval)
    188  1.1  christos 	struct proc *p;
    189  1.1  christos 	register struct compat_43_killpg_args /* {
    190  1.1  christos 		syscallarg(int) pgid;
    191  1.1  christos 		syscallarg(int) signum;
    192  1.1  christos 	} */ *uap;
    193  1.1  christos 	register_t *retval;
    194  1.1  christos {
    195  1.1  christos 
    196  1.1  christos #ifdef COMPAT_09
    197  1.1  christos 	SCARG(uap, pgid) = (short) SCARG(uap, pgid);
    198  1.1  christos #endif
    199  1.1  christos 
    200  1.1  christos 	if ((u_int)SCARG(uap, signum) >= NSIG)
    201  1.1  christos 		return (EINVAL);
    202  1.1  christos 	return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
    203  1.1  christos }
    204