Home | History | Annotate | Line # | Download | only in common
kern_sig_13.c revision 1.15
      1  1.15       dsl /*	$NetBSD: kern_sig_13.c,v 1.15 2007/06/16 20:04:28 dsl Exp $	*/
      2   1.1    kleink 
      3   1.1    kleink /*-
      4   1.3   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1    kleink  * All rights reserved.
      6   1.1    kleink  *
      7   1.1    kleink  * This code is derived from software contributed to The NetBSD Foundation
      8   1.3   mycroft  * by Charles M. Hannum.
      9   1.1    kleink  *
     10   1.1    kleink  * Redistribution and use in source and binary forms, with or without
     11   1.1    kleink  * modification, are permitted provided that the following conditions
     12   1.1    kleink  * are met:
     13   1.1    kleink  * 1. Redistributions of source code must retain the above copyright
     14   1.1    kleink  *    notice, this list of conditions and the following disclaimer.
     15   1.1    kleink  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    kleink  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    kleink  *    documentation and/or other materials provided with the distribution.
     18   1.1    kleink  * 3. All advertising materials mentioning features or use of this software
     19   1.1    kleink  *    must display the following acknowledgement:
     20   1.1    kleink  *        This product includes software developed by the NetBSD
     21   1.1    kleink  *        Foundation, Inc. and its contributors.
     22   1.1    kleink  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1    kleink  *    contributors may be used to endorse or promote products derived
     24   1.1    kleink  *    from this software without specific prior written permission.
     25   1.1    kleink  *
     26   1.1    kleink  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1    kleink  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1    kleink  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1    kleink  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1    kleink  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1    kleink  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1    kleink  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1    kleink  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1    kleink  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1    kleink  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1    kleink  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    kleink  */
     38   1.6     lukem 
     39   1.6     lukem #include <sys/cdefs.h>
     40  1.15       dsl __KERNEL_RCSID(0, "$NetBSD: kern_sig_13.c,v 1.15 2007/06/16 20:04:28 dsl Exp $");
     41   1.1    kleink 
     42   1.1    kleink #include <sys/param.h>
     43   1.1    kleink #include <sys/proc.h>
     44   1.1    kleink #include <sys/signal.h>
     45   1.3   mycroft #include <sys/signalvar.h>
     46   1.1    kleink #include <sys/systm.h>
     47   1.1    kleink 
     48   1.1    kleink #include <sys/mount.h>
     49   1.1    kleink #include <sys/syscallargs.h>
     50   1.1    kleink 
     51   1.2    kleink #include <machine/limits.h>
     52   1.2    kleink 
     53  1.10  christos #include <compat/sys/signal.h>
     54  1.10  christos #include <compat/sys/signalvar.h>
     55   1.1    kleink #include <compat/common/compat_util.h>
     56  1.15       dsl #include <compat/common/compat_sigaltstack.h>
     57   1.3   mycroft 
     58   1.3   mycroft void
     59   1.3   mycroft native_sigset13_to_sigset(oss, ss)
     60   1.3   mycroft 	const sigset13_t *oss;
     61   1.3   mycroft 	sigset_t *ss;
     62   1.3   mycroft {
     63   1.3   mycroft 
     64   1.3   mycroft 	ss->__bits[0] = *oss;
     65   1.3   mycroft 	ss->__bits[1] = 0;
     66   1.3   mycroft 	ss->__bits[2] = 0;
     67   1.3   mycroft 	ss->__bits[3] = 0;
     68   1.3   mycroft }
     69   1.3   mycroft 
     70   1.3   mycroft void
     71   1.3   mycroft native_sigset_to_sigset13(ss, oss)
     72   1.3   mycroft 	const sigset_t *ss;
     73   1.3   mycroft 	sigset13_t *oss;
     74   1.3   mycroft {
     75   1.3   mycroft 
     76   1.3   mycroft 	*oss = ss->__bits[0];
     77   1.3   mycroft }
     78   1.3   mycroft 
     79   1.3   mycroft void
     80   1.3   mycroft native_sigaction13_to_sigaction(osa, sa)
     81   1.3   mycroft 	const struct sigaction13 *osa;
     82   1.3   mycroft 	struct sigaction *sa;
     83   1.3   mycroft {
     84   1.3   mycroft 
     85   1.8  christos 	sa->sa_handler = osa->osa_handler;
     86   1.8  christos 	native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask);
     87   1.8  christos 	sa->sa_flags = osa->osa_flags;
     88   1.3   mycroft }
     89   1.3   mycroft 
     90   1.3   mycroft void
     91   1.3   mycroft native_sigaction_to_sigaction13(sa, osa)
     92   1.3   mycroft 	const struct sigaction *sa;
     93   1.3   mycroft 	struct sigaction13 *osa;
     94   1.3   mycroft {
     95   1.3   mycroft 
     96   1.8  christos 	osa->osa_handler = sa->sa_handler;
     97   1.8  christos 	native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask);
     98   1.8  christos 	osa->osa_flags = sa->sa_flags;
     99   1.3   mycroft }
    100   1.3   mycroft 
    101   1.1    kleink int
    102  1.13  christos compat_13_sys_sigaltstack(struct lwp *l, void *v, register_t *retval)
    103   1.1    kleink {
    104   1.1    kleink 	struct compat_13_sys_sigaltstack_args /* {
    105   1.1    kleink 		syscallarg(const struct sigaltstack13 *) nss;
    106   1.1    kleink 		syscallarg(struct sigaltstack13 *) oss;
    107   1.1    kleink 	} */ *uap = v;
    108  1.15       dsl 	compat_sigaltstack(uap, sigaltstack13, SS_ONSTACK, SS_DISABLE);
    109   1.3   mycroft }
    110   1.1    kleink 
    111   1.3   mycroft int
    112  1.13  christos compat_13_sys_sigaction(struct lwp *l, void *v, register_t *retval)
    113   1.3   mycroft {
    114   1.3   mycroft 	struct compat_13_sys_sigaction_args /* {
    115   1.3   mycroft 		syscallarg(int) signum;
    116   1.3   mycroft 		syscallarg(const struct sigaction13 *) nsa;
    117   1.3   mycroft 		syscallarg(struct sigaction13 *) osa;
    118   1.3   mycroft 	} */ *uap = v;
    119   1.3   mycroft 	struct sigaction13 nesa, oesa;
    120   1.3   mycroft 	struct sigaction nbsa, obsa;
    121   1.3   mycroft 	int error;
    122   1.1    kleink 
    123   1.3   mycroft 	if (SCARG(uap, nsa)) {
    124   1.3   mycroft 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
    125   1.3   mycroft 		if (error)
    126   1.1    kleink 			return (error);
    127   1.3   mycroft 		native_sigaction13_to_sigaction(&nesa, &nbsa);
    128   1.3   mycroft 	}
    129  1.14        ad 	error = sigaction1(l, SCARG(uap, signum),
    130   1.7   thorpej 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
    131   1.7   thorpej 	    NULL, 0);
    132   1.3   mycroft 	if (error)
    133   1.3   mycroft 		return (error);
    134   1.3   mycroft 	if (SCARG(uap, osa)) {
    135   1.3   mycroft 		native_sigaction_to_sigaction13(&obsa, &oesa);
    136   1.3   mycroft 		error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
    137   1.3   mycroft 		if (error)
    138   1.1    kleink 			return (error);
    139   1.3   mycroft 	}
    140   1.3   mycroft 	return (0);
    141   1.3   mycroft }
    142   1.1    kleink 
    143   1.3   mycroft int
    144   1.9   thorpej compat_13_sys_sigprocmask(struct lwp *l, void *v, register_t *retval)
    145   1.3   mycroft {
    146   1.3   mycroft 	struct compat_13_sys_sigprocmask_args /* {
    147   1.3   mycroft 		syscallarg(int) how;
    148   1.3   mycroft 		syscallarg(int) mask;
    149   1.3   mycroft 	} */ *uap = v;
    150   1.9   thorpej 	struct proc *p = l->l_proc;
    151   1.3   mycroft 	sigset13_t ness, oess;
    152   1.3   mycroft 	sigset_t nbss, obss;
    153   1.3   mycroft 	int error;
    154   1.1    kleink 
    155   1.3   mycroft 	ness = SCARG(uap, mask);
    156   1.3   mycroft 	native_sigset13_to_sigset(&ness, &nbss);
    157  1.14        ad 	mutex_enter(&p->p_smutex);
    158  1.14        ad 	error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss);
    159  1.14        ad 	mutex_exit(&p->p_smutex);
    160   1.3   mycroft 	if (error)
    161   1.1    kleink 		return (error);
    162   1.3   mycroft 	native_sigset_to_sigset13(&obss, &oess);
    163   1.3   mycroft 	*retval = oess;
    164   1.3   mycroft 	return (0);
    165   1.3   mycroft }
    166   1.1    kleink 
    167   1.3   mycroft int
    168  1.13  christos compat_13_sys_sigpending(struct lwp *l, void *v, register_t *retval)
    169   1.3   mycroft {
    170   1.3   mycroft 	sigset13_t ess;
    171   1.3   mycroft 	sigset_t bss;
    172   1.1    kleink 
    173  1.14        ad 	sigpending1(l, &bss);
    174   1.3   mycroft 	native_sigset_to_sigset13(&bss, &ess);
    175   1.3   mycroft 	*retval = ess;
    176   1.1    kleink 	return (0);
    177   1.3   mycroft }
    178   1.3   mycroft 
    179   1.3   mycroft int
    180  1.13  christos compat_13_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
    181   1.3   mycroft {
    182   1.3   mycroft 	struct compat_13_sys_sigsuspend_args /* {
    183   1.3   mycroft 		syscallarg(sigset13_t) mask;
    184   1.3   mycroft 	} */ *uap = v;
    185   1.3   mycroft 	sigset13_t ess;
    186   1.3   mycroft 	sigset_t bss;
    187   1.3   mycroft 
    188   1.3   mycroft 	ess = SCARG(uap, mask);
    189   1.3   mycroft 	native_sigset13_to_sigset(&ess, &bss);
    190  1.14        ad 	return (sigsuspend1(l, &bss));
    191   1.1    kleink }
    192