Home | History | Annotate | Line # | Download | only in common
kern_sig_43.c revision 1.15.2.2
      1  1.15.2.2  jdolecek /*	$NetBSD: kern_sig_43.c,v 1.15.2.2 2002/09/06 08:43:00 jdolecek Exp $	*/
      2       1.1  christos 
      3       1.9   mycroft /*-
      4       1.9   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.9   mycroft  * All rights reserved.
      6       1.9   mycroft  *
      7       1.9   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8       1.9   mycroft  * by Charles M. Hannum.
      9       1.1  christos  *
     10       1.1  christos  * Redistribution and use in source and binary forms, with or without
     11       1.1  christos  * modification, are permitted provided that the following conditions
     12       1.1  christos  * are met:
     13       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14       1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15       1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  christos  *    documentation and/or other materials provided with the distribution.
     18       1.1  christos  * 3. All advertising materials mentioning features or use of this software
     19       1.1  christos  *    must display the following acknowledgement:
     20       1.9   mycroft  *        This product includes software developed by the NetBSD
     21       1.9   mycroft  *        Foundation, Inc. and its contributors.
     22       1.9   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.9   mycroft  *    contributors may be used to endorse or promote products derived
     24       1.9   mycroft  *    from this software without specific prior written permission.
     25       1.1  christos  *
     26       1.9   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.9   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.9   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.9   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.9   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.9   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.9   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.9   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.9   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.9   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.9   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1  christos  */
     38  1.15.2.1   thorpej 
     39  1.15.2.1   thorpej #include <sys/cdefs.h>
     40  1.15.2.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: kern_sig_43.c,v 1.15.2.2 2002/09/06 08:43:00 jdolecek Exp $");
     41       1.8  jonathan 
     42      1.15       mrg #if defined(_KERNEL_OPT)
     43       1.8  jonathan #include "opt_compat_netbsd.h"
     44      1.14  jdolecek #endif
     45       1.1  christos 
     46       1.1  christos #include <sys/param.h>
     47       1.1  christos #include <sys/signalvar.h>
     48       1.1  christos #include <sys/resourcevar.h>
     49       1.1  christos #include <sys/namei.h>
     50       1.1  christos #include <sys/vnode.h>
     51       1.1  christos #include <sys/proc.h>
     52       1.1  christos #include <sys/systm.h>
     53       1.1  christos #include <sys/timeb.h>
     54       1.1  christos #include <sys/times.h>
     55       1.1  christos #include <sys/buf.h>
     56       1.1  christos #include <sys/acct.h>
     57       1.1  christos #include <sys/file.h>
     58       1.1  christos #include <sys/kernel.h>
     59       1.1  christos #include <sys/wait.h>
     60       1.1  christos #include <sys/ktrace.h>
     61       1.1  christos #include <sys/syslog.h>
     62       1.1  christos #include <sys/stat.h>
     63       1.1  christos #include <sys/core.h>
     64       1.1  christos 
     65       1.1  christos #include <sys/mount.h>
     66       1.1  christos #include <sys/syscallargs.h>
     67       1.1  christos 
     68       1.1  christos #include <machine/cpu.h>
     69       1.1  christos 
     70       1.1  christos #include <sys/user.h>		/* for coredump */
     71       1.1  christos 
     72       1.9   mycroft void compat_43_sigmask_to_sigset __P((const int *, sigset_t *));
     73       1.9   mycroft void compat_43_sigset_to_sigmask __P((const sigset_t *, int *));
     74       1.9   mycroft void compat_43_sigvec_to_sigaction __P((const struct sigvec *, struct sigaction *));
     75       1.9   mycroft void compat_43_sigaction_to_sigvec __P((const struct sigaction *, struct sigvec *));
     76       1.9   mycroft void compat_43_sigstack_to_sigaltstack __P((const struct sigstack *, struct sigaltstack *));
     77       1.9   mycroft void compat_43_sigaltstack_to_sigstack __P((const struct sigaltstack *, struct sigstack *));
     78       1.9   mycroft 
     79       1.9   mycroft void
     80       1.9   mycroft compat_43_sigmask_to_sigset(sm, ss)
     81       1.9   mycroft 	const int *sm;
     82       1.9   mycroft 	sigset_t *ss;
     83       1.9   mycroft {
     84       1.9   mycroft 
     85       1.9   mycroft 	ss->__bits[0] = *sm;
     86       1.9   mycroft 	ss->__bits[1] = 0;
     87       1.9   mycroft 	ss->__bits[2] = 0;
     88       1.9   mycroft 	ss->__bits[3] = 0;
     89       1.9   mycroft }
     90       1.9   mycroft 
     91       1.9   mycroft void
     92       1.9   mycroft compat_43_sigset_to_sigmask(ss, sm)
     93       1.9   mycroft 	const sigset_t *ss;
     94       1.9   mycroft 	int *sm;
     95       1.9   mycroft {
     96       1.9   mycroft 
     97       1.9   mycroft 	*sm = ss->__bits[0];
     98       1.9   mycroft }
     99       1.9   mycroft 
    100       1.9   mycroft void
    101       1.9   mycroft compat_43_sigvec_to_sigaction(sv, sa)
    102       1.9   mycroft 	const struct sigvec *sv;
    103       1.9   mycroft 	struct sigaction *sa;
    104       1.9   mycroft {
    105       1.9   mycroft 	sa->sa_handler = sv->sv_handler;
    106       1.9   mycroft 	compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask);
    107       1.9   mycroft 	sa->sa_flags = sv->sv_flags ^ SA_RESTART;
    108       1.9   mycroft }
    109       1.9   mycroft 
    110       1.9   mycroft void
    111       1.9   mycroft compat_43_sigaction_to_sigvec(sa, sv)
    112       1.9   mycroft 	const struct sigaction *sa;
    113       1.9   mycroft 	struct sigvec *sv;
    114       1.9   mycroft {
    115       1.9   mycroft 	sv->sv_handler = sa->sa_handler;
    116       1.9   mycroft 	compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask);
    117       1.9   mycroft 	sv->sv_flags = sa->sa_flags ^ SA_RESTART;
    118       1.9   mycroft }
    119       1.9   mycroft 
    120       1.9   mycroft void
    121       1.9   mycroft compat_43_sigstack_to_sigaltstack(ss, sa)
    122       1.9   mycroft 	const struct sigstack *ss;
    123       1.9   mycroft 	struct sigaltstack *sa;
    124       1.9   mycroft {
    125       1.9   mycroft 	sa->ss_sp = ss->ss_sp;
    126      1.11  christos 	sa->ss_size = SIGSTKSZ;	/* Use the recommended size */
    127       1.9   mycroft 	sa->ss_flags = 0;
    128       1.9   mycroft 	if (ss->ss_onstack)
    129       1.9   mycroft 		sa->ss_flags |= SS_ONSTACK;
    130       1.9   mycroft }
    131       1.9   mycroft 
    132       1.9   mycroft void
    133       1.9   mycroft compat_43_sigaltstack_to_sigstack(sa, ss)
    134       1.9   mycroft 	const struct sigaltstack *sa;
    135       1.9   mycroft 	struct sigstack *ss;
    136       1.9   mycroft {
    137       1.9   mycroft 	ss->ss_sp = sa->ss_sp;
    138       1.9   mycroft 	if (sa->ss_flags & SS_ONSTACK)
    139       1.9   mycroft 		ss->ss_onstack = 1;
    140       1.9   mycroft 	else
    141       1.9   mycroft 		ss->ss_onstack = 0;
    142       1.9   mycroft }
    143       1.9   mycroft 
    144       1.1  christos int
    145       1.5   mycroft compat_43_sys_sigblock(p, v, retval)
    146      1.12  augustss 	struct proc *p;
    147       1.4   thorpej 	void *v;
    148       1.4   thorpej 	register_t *retval;
    149       1.4   thorpej {
    150       1.5   mycroft 	struct compat_43_sys_sigblock_args /* {
    151       1.1  christos 		syscallarg(int) mask;
    152       1.4   thorpej 	} */ *uap = v;
    153       1.9   mycroft 	int nsm, osm;
    154       1.9   mycroft 	sigset_t nss, oss;
    155       1.9   mycroft 	int error;
    156       1.9   mycroft 
    157       1.9   mycroft 	nsm = SCARG(uap, mask);
    158       1.9   mycroft 	compat_43_sigmask_to_sigset(&nsm, &nss);
    159       1.9   mycroft 	error = sigprocmask1(p, SIG_BLOCK, &nss, &oss);
    160       1.9   mycroft 	if (error)
    161       1.9   mycroft 		return (error);
    162       1.9   mycroft 	compat_43_sigset_to_sigmask(&oss, &osm);
    163       1.9   mycroft 	*retval = osm;
    164       1.1  christos 	return (0);
    165       1.1  christos }
    166       1.1  christos 
    167       1.1  christos int
    168       1.5   mycroft compat_43_sys_sigsetmask(p, v, retval)
    169       1.1  christos 	struct proc *p;
    170       1.4   thorpej 	void *v;
    171       1.4   thorpej 	register_t *retval;
    172       1.4   thorpej {
    173       1.5   mycroft 	struct compat_43_sys_sigsetmask_args /* {
    174       1.1  christos 		syscallarg(int) mask;
    175       1.4   thorpej 	} */ *uap = v;
    176       1.9   mycroft 	int nsm, osm;
    177       1.9   mycroft 	sigset_t nss, oss;
    178       1.9   mycroft 	int error;
    179       1.9   mycroft 
    180       1.9   mycroft 	nsm = SCARG(uap, mask);
    181       1.9   mycroft 	compat_43_sigmask_to_sigset(&nsm, &nss);
    182       1.9   mycroft 	error = sigprocmask1(p, SIG_SETMASK, &nss, &oss);
    183       1.9   mycroft 	if (error)
    184       1.9   mycroft 		return (error);
    185       1.9   mycroft 	compat_43_sigset_to_sigmask(&oss, &osm);
    186       1.9   mycroft 	*retval = osm;
    187       1.1  christos 	return (0);
    188       1.1  christos }
    189       1.1  christos 
    190       1.1  christos /* ARGSUSED */
    191       1.1  christos int
    192       1.5   mycroft compat_43_sys_sigstack(p, v, retval)
    193       1.1  christos 	struct proc *p;
    194       1.4   thorpej 	void *v;
    195       1.4   thorpej 	register_t *retval;
    196       1.4   thorpej {
    197      1.12  augustss 	struct compat_43_sys_sigstack_args /* {
    198       1.1  christos 		syscallarg(struct sigstack *) nss;
    199       1.1  christos 		syscallarg(struct sigstack *) oss;
    200       1.4   thorpej 	} */ *uap = v;
    201       1.9   mycroft 	struct sigstack nss, oss;
    202       1.9   mycroft 	struct sigaltstack nsa, osa;
    203       1.9   mycroft 	int error;
    204       1.9   mycroft 
    205       1.9   mycroft 	if (SCARG(uap, nss)) {
    206       1.9   mycroft 		error = copyin(SCARG(uap, nss), &nss, sizeof(nss));
    207       1.9   mycroft 		if (error)
    208       1.9   mycroft 			return (error);
    209       1.9   mycroft 		compat_43_sigstack_to_sigaltstack(&nss, &nsa);
    210       1.9   mycroft 	}
    211       1.9   mycroft 	error = sigaltstack1(p,
    212       1.9   mycroft 	    SCARG(uap, nss) ? &nsa : 0, SCARG(uap, oss) ? &osa : 0);
    213       1.7  christos 	if (error)
    214       1.3   mycroft 		return (error);
    215       1.9   mycroft 	if (SCARG(uap, oss)) {
    216       1.9   mycroft 		compat_43_sigaltstack_to_sigstack(&osa, &oss);
    217      1.10        pk 		error = copyout(&oss, SCARG(uap, oss), sizeof(oss));
    218       1.9   mycroft 		if (error)
    219       1.9   mycroft 			return (error);
    220       1.9   mycroft 	}
    221       1.3   mycroft 	return (0);
    222       1.1  christos }
    223       1.1  christos 
    224       1.1  christos /*
    225       1.1  christos  * Generalized interface signal handler, 4.3-compatible.
    226       1.1  christos  */
    227       1.1  christos /* ARGSUSED */
    228       1.1  christos int
    229       1.5   mycroft compat_43_sys_sigvec(p, v, retval)
    230       1.1  christos 	struct proc *p;
    231       1.4   thorpej 	void *v;
    232       1.4   thorpej 	register_t *retval;
    233       1.4   thorpej {
    234      1.12  augustss 	struct compat_43_sys_sigvec_args /* {
    235       1.1  christos 		syscallarg(int) signum;
    236       1.9   mycroft 		syscallarg(const struct sigvec *) nsv;
    237       1.1  christos 		syscallarg(struct sigvec *) osv;
    238       1.4   thorpej 	} */ *uap = v;
    239       1.9   mycroft 	struct sigvec nsv, osv;
    240       1.9   mycroft 	struct sigaction nsa, osa;
    241       1.9   mycroft 	int error;
    242       1.9   mycroft 
    243       1.9   mycroft 	if (SCARG(uap, nsv)) {
    244       1.9   mycroft 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
    245       1.7  christos 		if (error)
    246       1.1  christos 			return (error);
    247       1.9   mycroft 		compat_43_sigvec_to_sigaction(&nsv, &nsa);
    248       1.1  christos 	}
    249       1.9   mycroft 	error = sigaction1(p, SCARG(uap, signum),
    250  1.15.2.2  jdolecek 	    SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
    251  1.15.2.2  jdolecek 	    NULL, 0);
    252       1.9   mycroft 	if (error)
    253       1.9   mycroft 		return (error);
    254       1.9   mycroft 	if (SCARG(uap, osv)) {
    255       1.9   mycroft 		compat_43_sigaction_to_sigvec(&osa, &osv);
    256      1.10        pk 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
    257       1.7  christos 		if (error)
    258       1.1  christos 			return (error);
    259       1.1  christos 	}
    260       1.1  christos 	return (0);
    261       1.1  christos }
    262       1.1  christos 
    263       1.1  christos 
    264       1.1  christos /* ARGSUSED */
    265       1.1  christos int
    266       1.5   mycroft compat_43_sys_killpg(p, v, retval)
    267       1.1  christos 	struct proc *p;
    268       1.4   thorpej 	void *v;
    269       1.4   thorpej 	register_t *retval;
    270       1.4   thorpej {
    271      1.12  augustss 	struct compat_43_sys_killpg_args /* {
    272       1.1  christos 		syscallarg(int) pgid;
    273       1.1  christos 		syscallarg(int) signum;
    274       1.4   thorpej 	} */ *uap = v;
    275       1.1  christos 
    276       1.1  christos #ifdef COMPAT_09
    277       1.1  christos 	SCARG(uap, pgid) = (short) SCARG(uap, pgid);
    278       1.1  christos #endif
    279       1.1  christos 
    280       1.1  christos 	if ((u_int)SCARG(uap, signum) >= NSIG)
    281       1.1  christos 		return (EINVAL);
    282       1.1  christos 	return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
    283       1.1  christos }
    284