Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.31.2.6
      1  1.31.2.6   nathanw /*	$NetBSD: linux_signal.c,v 1.31.2.6 2002/05/29 21:32:44 nathanw Exp $	*/
      2      1.16      fvdl /*-
      3      1.16      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      4       1.1      fvdl  * All rights reserved.
      5       1.1      fvdl  *
      6      1.16      fvdl  * This code is derived from software contributed to The NetBSD Foundation
      7      1.16      fvdl  * by Frank van der Linden and Eric Haszlakiewicz.
      8      1.16      fvdl  *
      9       1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     10       1.1      fvdl  * modification, are permitted provided that the following conditions
     11       1.1      fvdl  * are met:
     12       1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     13       1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     14       1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     16       1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     17       1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     18       1.1      fvdl  *    must display the following acknowledgement:
     19      1.16      fvdl  *	This product includes software developed by the NetBSD
     20      1.16      fvdl  *	Foundation, Inc. and its contributors.
     21      1.16      fvdl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22      1.16      fvdl  *    contributors may be used to endorse or promote products derived
     23      1.16      fvdl  *    from this software without specific prior written permission.
     24       1.1      fvdl  *
     25      1.16      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26      1.16      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27      1.16      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28      1.16      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29      1.16      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30      1.16      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31      1.16      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32      1.16      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33      1.16      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34      1.16      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35      1.16      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     36      1.16      fvdl  */
     37      1.16      fvdl /*
     38       1.1      fvdl  * heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
     39       1.1      fvdl  */
     40       1.1      fvdl 
     41      1.14       erh /*
     42      1.14       erh  *   Functions in multiarch:
     43      1.14       erh  *	linux_sys_signal	: linux_sig_notalpha.c
     44      1.14       erh  *	linux_sys_siggetmask	: linux_sig_notalpha.c
     45      1.14       erh  *	linux_sys_sigsetmask	: linux_sig_notalpha.c
     46      1.14       erh  *	linux_sys_pause		: linux_sig_notalpha.c
     47      1.14       erh  *	linux_sys_sigaction	: linux_sigaction.c
     48      1.14       erh  *
     49      1.14       erh  */
     50      1.14       erh 
     51      1.14       erh /*
     52      1.14       erh  *   Unimplemented:
     53      1.14       erh  *	linux_sys_rt_sigtimedwait	: sigsuspend w/timeout.
     54      1.14       erh  */
     55  1.31.2.2   nathanw 
     56  1.31.2.2   nathanw #include <sys/cdefs.h>
     57  1.31.2.6   nathanw __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.31.2.6 2002/05/29 21:32:44 nathanw Exp $");
     58      1.21  drochner 
     59      1.21  drochner #define COMPAT_LINUX 1
     60      1.14       erh 
     61       1.1      fvdl #include <sys/param.h>
     62       1.1      fvdl #include <sys/systm.h>
     63       1.1      fvdl #include <sys/namei.h>
     64  1.31.2.1   nathanw #include <sys/lwp.h>
     65       1.1      fvdl #include <sys/proc.h>
     66       1.1      fvdl #include <sys/filedesc.h>
     67       1.1      fvdl #include <sys/ioctl.h>
     68       1.1      fvdl #include <sys/mount.h>
     69       1.1      fvdl #include <sys/kernel.h>
     70       1.1      fvdl #include <sys/signal.h>
     71       1.1      fvdl #include <sys/signalvar.h>
     72       1.1      fvdl #include <sys/malloc.h>
     73       1.1      fvdl 
     74  1.31.2.6   nathanw #include <sys/sa.h>
     75       1.1      fvdl #include <sys/syscallargs.h>
     76       1.1      fvdl 
     77      1.15  christos #include <compat/linux/common/linux_types.h>
     78      1.15  christos #include <compat/linux/common/linux_signal.h>
     79      1.17       erh #include <compat/linux/common/linux_siginfo.h>
     80      1.15  christos #include <compat/linux/common/linux_util.h>
     81      1.15  christos 
     82       1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     83       1.1      fvdl 
     84      1.14       erh /* Locally used defines (in bsd<->linux conversion functions): */
     85      1.11     perry #define	linux_sigemptyset(s)	memset((s), 0, sizeof(*(s)))
     86      1.20     itohy #define	linux_sigismember(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     87      1.20     itohy 					& (1 << ((n) - 1) % LINUX__NSIG_BPW))
     88      1.20     itohy #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     89      1.20     itohy 					|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
     90       1.6   mycroft 
     91  1.31.2.4   nathanw #ifdef DEBUG_LINUX
     92  1.31.2.4   nathanw #define DPRINTF(a)	uprintf a
     93  1.31.2.4   nathanw #else
     94  1.31.2.4   nathanw #define DPRINTF(a)
     95  1.31.2.4   nathanw #endif
     96  1.31.2.4   nathanw 
     97  1.31.2.5   nathanw extern const int native_to_linux_signo[];
     98  1.31.2.5   nathanw extern const int linux_to_native_signo[];
     99       1.6   mycroft 
    100      1.14       erh /*
    101      1.20     itohy  * Convert between Linux and BSD signal sets.
    102      1.14       erh  */
    103      1.20     itohy #if LINUX__NSIG_WORDS > 1
    104       1.6   mycroft void
    105  1.31.2.3   nathanw linux_old_extra_to_native_sigset(bss, lss, extra)
    106  1.31.2.3   nathanw 	sigset_t *bss;
    107      1.14       erh 	const linux_old_sigset_t *lss;
    108      1.20     itohy 	const unsigned long *extra;
    109      1.20     itohy {
    110      1.20     itohy 	linux_sigset_t lsnew;
    111      1.20     itohy 
    112      1.20     itohy 	/* convert old sigset to new sigset */
    113      1.20     itohy 	linux_sigemptyset(&lsnew);
    114      1.20     itohy 	lsnew.sig[0] = *lss;
    115      1.20     itohy 	if (extra)
    116  1.31.2.3   nathanw 		memcpy(&lsnew.sig[1], extra,
    117  1.31.2.3   nathanw 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    118      1.20     itohy 
    119  1.31.2.3   nathanw 	linux_to_native_sigset(bss, &lsnew);
    120      1.20     itohy }
    121      1.20     itohy 
    122      1.20     itohy void
    123  1.31.2.3   nathanw native_to_linux_old_extra_sigset(lss, extra, bss)
    124      1.20     itohy 	linux_old_sigset_t *lss;
    125      1.20     itohy 	unsigned long *extra;
    126  1.31.2.3   nathanw 	const sigset_t *bss;
    127      1.20     itohy {
    128      1.20     itohy 	linux_sigset_t lsnew;
    129      1.20     itohy 
    130  1.31.2.3   nathanw 	native_to_linux_sigset(&lsnew, bss);
    131      1.20     itohy 
    132      1.20     itohy 	/* convert new sigset to old sigset */
    133      1.20     itohy 	*lss = lsnew.sig[0];
    134      1.20     itohy 	if (extra)
    135  1.31.2.3   nathanw 		memcpy(extra, &lsnew.sig[1],
    136  1.31.2.3   nathanw 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    137      1.20     itohy }
    138      1.20     itohy #endif
    139      1.20     itohy 
    140      1.20     itohy void
    141  1.31.2.3   nathanw linux_to_native_sigset(bss, lss)
    142       1.1      fvdl 	sigset_t *bss;
    143  1.31.2.3   nathanw 	const linux_sigset_t *lss;
    144       1.1      fvdl {
    145       1.1      fvdl 	int i, newsig;
    146       1.1      fvdl 
    147       1.6   mycroft 	sigemptyset(bss);
    148      1.20     itohy 	for (i = 1; i < LINUX__NSIG; i++) {
    149       1.6   mycroft 		if (linux_sigismember(lss, i)) {
    150  1.31.2.5   nathanw 			newsig = linux_to_native_signo[i];
    151       1.1      fvdl 			if (newsig)
    152       1.6   mycroft 				sigaddset(bss, newsig);
    153       1.1      fvdl 		}
    154       1.1      fvdl 	}
    155       1.1      fvdl }
    156       1.1      fvdl 
    157       1.1      fvdl void
    158  1.31.2.3   nathanw native_to_linux_sigset(lss, bss)
    159      1.20     itohy 	linux_sigset_t *lss;
    160  1.31.2.3   nathanw 	const sigset_t *bss;
    161       1.1      fvdl {
    162       1.1      fvdl 	int i, newsig;
    163      1.20     itohy 
    164       1.6   mycroft 	linux_sigemptyset(lss);
    165       1.6   mycroft 	for (i = 1; i < NSIG; i++) {
    166       1.6   mycroft 		if (sigismember(bss, i)) {
    167  1.31.2.5   nathanw 			newsig = native_to_linux_signo[i];
    168       1.1      fvdl 			if (newsig)
    169       1.6   mycroft 				linux_sigaddset(lss, newsig);
    170       1.1      fvdl 		}
    171       1.1      fvdl 	}
    172       1.1      fvdl }
    173       1.1      fvdl 
    174  1.31.2.3   nathanw unsigned int
    175  1.31.2.3   nathanw native_to_linux_sigflags(bsf)
    176  1.31.2.3   nathanw 	const int bsf;
    177  1.31.2.3   nathanw {
    178  1.31.2.3   nathanw 	unsigned int lsf = 0;
    179  1.31.2.3   nathanw 	if ((bsf & SA_NOCLDSTOP) != 0)
    180  1.31.2.3   nathanw 		lsf |= LINUX_SA_NOCLDSTOP;
    181  1.31.2.3   nathanw 	if ((bsf & SA_NOCLDWAIT) != 0)
    182  1.31.2.3   nathanw 		lsf |= LINUX_SA_NOCLDWAIT;
    183  1.31.2.3   nathanw 	if ((bsf & SA_ONSTACK) != 0)
    184  1.31.2.3   nathanw 		lsf |= LINUX_SA_ONSTACK;
    185  1.31.2.3   nathanw 	if ((bsf & SA_RESTART) != 0)
    186  1.31.2.3   nathanw 		lsf |= LINUX_SA_RESTART;
    187  1.31.2.3   nathanw 	if ((bsf & SA_NODEFER) != 0)
    188  1.31.2.3   nathanw 		lsf |= LINUX_SA_NOMASK;
    189  1.31.2.3   nathanw 	if ((bsf & SA_RESETHAND) != 0)
    190  1.31.2.3   nathanw 		lsf |= LINUX_SA_ONESHOT;
    191  1.31.2.3   nathanw 	if ((bsf & SA_SIGINFO) != 0)
    192  1.31.2.3   nathanw 		lsf |= LINUX_SA_SIGINFO;
    193  1.31.2.3   nathanw 	return lsf;
    194  1.31.2.3   nathanw }
    195  1.31.2.3   nathanw 
    196  1.31.2.3   nathanw int
    197  1.31.2.3   nathanw linux_to_native_sigflags(lsf)
    198  1.31.2.3   nathanw 	const unsigned long lsf;
    199  1.31.2.3   nathanw {
    200  1.31.2.3   nathanw 	int bsf = 0;
    201  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
    202  1.31.2.3   nathanw 		bsf |= SA_NOCLDSTOP;
    203  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
    204  1.31.2.3   nathanw 		bsf |= SA_NOCLDWAIT;
    205  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_ONSTACK) != 0)
    206  1.31.2.3   nathanw 		bsf |= SA_ONSTACK;
    207  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_RESTART) != 0)
    208  1.31.2.3   nathanw 		bsf |= SA_RESTART;
    209  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_ONESHOT) != 0)
    210  1.31.2.3   nathanw 		bsf |= SA_RESETHAND;
    211  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_NOMASK) != 0)
    212  1.31.2.3   nathanw 		bsf |= SA_NODEFER;
    213  1.31.2.3   nathanw 	if ((lsf & LINUX_SA_SIGINFO) != 0)
    214  1.31.2.3   nathanw 		bsf |= SA_SIGINFO;
    215  1.31.2.3   nathanw 	if ((lsf & ~LINUX_SA_ALLBITS) != 0)
    216  1.31.2.4   nathanw 		DPRINTF(("linux_old_to_native_sigflags: "
    217  1.31.2.4   nathanw 		    "%lx extra bits ignored\n", lsf));
    218  1.31.2.3   nathanw 	return bsf;
    219  1.31.2.3   nathanw }
    220  1.31.2.3   nathanw 
    221       1.1      fvdl /*
    222      1.14       erh  * Convert between Linux and BSD sigaction structures. Linux sometimes
    223      1.14       erh  * has one extra field (sa_restorer) which we don't support.
    224       1.1      fvdl  */
    225       1.1      fvdl void
    226  1.31.2.3   nathanw linux_old_to_native_sigaction(bsa, lsa)
    227      1.14       erh 	struct sigaction *bsa;
    228  1.31.2.3   nathanw 	const struct linux_old_sigaction *lsa;
    229      1.14       erh {
    230      1.14       erh 	bsa->sa_handler = lsa->sa_handler;
    231  1.31.2.3   nathanw 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    232  1.31.2.3   nathanw 	bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
    233  1.31.2.3   nathanw #ifndef __alpha__
    234  1.31.2.3   nathanw /*
    235  1.31.2.3   nathanw  * XXX: On the alpha sa_restorer is elsewhere.
    236  1.31.2.3   nathanw  */
    237  1.31.2.3   nathanw 	if (lsa->sa_restorer != NULL)
    238  1.31.2.4   nathanw 		DPRINTF(("linux_old_to_native_sigaction: "
    239  1.31.2.4   nathanw 		    "sa_restorer ignored\n"));
    240      1.14       erh #endif
    241      1.14       erh }
    242      1.14       erh 
    243      1.14       erh void
    244  1.31.2.3   nathanw native_to_linux_old_sigaction(lsa, bsa)
    245      1.14       erh 	struct linux_old_sigaction *lsa;
    246  1.31.2.3   nathanw 	const struct sigaction *bsa;
    247      1.14       erh {
    248      1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    249  1.31.2.3   nathanw 	native_to_linux_old_sigset(&lsa->sa_mask, &bsa->sa_mask);
    250  1.31.2.3   nathanw 	lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    251  1.31.2.3   nathanw #ifndef __alpha__
    252  1.31.2.3   nathanw 	lsa->sa_restorer = NULL;
    253  1.31.2.3   nathanw #endif
    254      1.14       erh }
    255      1.14       erh 
    256      1.14       erh /* ...and the new sigaction conversion funcs. */
    257      1.14       erh void
    258  1.31.2.3   nathanw linux_to_native_sigaction(bsa, lsa)
    259       1.1      fvdl 	struct sigaction *bsa;
    260  1.31.2.3   nathanw 	const struct linux_sigaction *lsa;
    261       1.1      fvdl {
    262       1.1      fvdl 	bsa->sa_handler = lsa->sa_handler;
    263  1.31.2.3   nathanw 	linux_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    264  1.31.2.3   nathanw 	bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
    265  1.31.2.3   nathanw #ifndef __alpha__
    266      1.12   mycroft 	if (lsa->sa_restorer != 0)
    267  1.31.2.4   nathanw 		DPRINTF(("linux_to_native_sigaction: sa_restorer ignored\n"));
    268      1.13        tv #endif
    269       1.1      fvdl }
    270       1.1      fvdl 
    271       1.1      fvdl void
    272  1.31.2.3   nathanw native_to_linux_sigaction(lsa, bsa)
    273       1.1      fvdl 	struct linux_sigaction *lsa;
    274  1.31.2.3   nathanw 	const struct sigaction *bsa;
    275       1.1      fvdl {
    276      1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    277  1.31.2.3   nathanw 	native_to_linux_sigset(&lsa->sa_mask, &bsa->sa_mask);
    278  1.31.2.3   nathanw 	lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    279  1.31.2.3   nathanw #ifndef __alpha__
    280  1.31.2.3   nathanw 	lsa->sa_restorer = NULL;
    281  1.31.2.3   nathanw #endif
    282       1.1      fvdl }
    283       1.1      fvdl 
    284      1.14       erh /* ----------------------------------------------------------------------- */
    285       1.1      fvdl 
    286       1.1      fvdl /*
    287       1.1      fvdl  * The Linux sigaction() system call. Do the usual conversions,
    288       1.1      fvdl  * and just call sigaction(). Some flags and values are silently
    289       1.1      fvdl  * ignored (see above).
    290       1.1      fvdl  */
    291       1.1      fvdl int
    292  1.31.2.1   nathanw linux_sys_rt_sigaction(l, v, retval)
    293  1.31.2.1   nathanw 	struct lwp *l;
    294       1.8   thorpej 	void *v;
    295       1.8   thorpej 	register_t *retval;
    296       1.8   thorpej {
    297      1.14       erh 	struct linux_sys_rt_sigaction_args /* {
    298       1.1      fvdl 		syscallarg(int) signum;
    299      1.12   mycroft 		syscallarg(const struct linux_sigaction *) nsa;
    300       1.1      fvdl 		syscallarg(struct linux_sigaction *) osa;
    301      1.14       erh 		syscallarg(size_t) sigsetsize;
    302       1.8   thorpej 	} */ *uap = v;
    303  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    304      1.12   mycroft 	struct linux_sigaction nlsa, olsa;
    305      1.12   mycroft 	struct sigaction nbsa, obsa;
    306      1.25      tron 	int error, sig;
    307       1.1      fvdl 
    308      1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    309      1.14       erh 		return (EINVAL);
    310      1.14       erh 
    311      1.12   mycroft 	if (SCARG(uap, nsa)) {
    312      1.12   mycroft 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    313      1.12   mycroft 		if (error)
    314      1.12   mycroft 			return (error);
    315  1.31.2.3   nathanw 		linux_to_native_sigaction(&nbsa, &nlsa);
    316      1.12   mycroft 	}
    317      1.25      tron 	sig = SCARG(uap, signum);
    318      1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    319      1.25      tron 		return (EINVAL);
    320  1.31.2.5   nathanw 	if (sig > 0 && !linux_to_native_signo[sig]) {
    321      1.29        tv 		/* Pretend that we did something useful for unknown signals. */
    322      1.29        tv 		obsa.sa_handler = SIG_IGN;
    323      1.29        tv 		sigemptyset(&obsa.sa_mask);
    324      1.29        tv 		obsa.sa_flags = 0;
    325      1.29        tv 	} else {
    326  1.31.2.5   nathanw 		error = sigaction1(p, linux_to_native_signo[sig],
    327      1.29        tv 		    SCARG(uap, nsa) ? &nbsa : NULL, SCARG(uap, osa) ? &obsa : NULL);
    328      1.29        tv 		if (error)
    329      1.29        tv 			return (error);
    330      1.29        tv 	}
    331      1.12   mycroft 	if (SCARG(uap, osa)) {
    332  1.31.2.3   nathanw 		native_to_linux_sigaction(&olsa, &obsa);
    333      1.12   mycroft 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    334      1.12   mycroft 		if (error)
    335      1.12   mycroft 			return (error);
    336       1.1      fvdl 	}
    337      1.12   mycroft 	return (0);
    338       1.1      fvdl }
    339       1.1      fvdl 
    340       1.1      fvdl int
    341      1.17       erh linux_sigprocmask1(p, how, set, oset)
    342      1.26  augustss 	struct proc *p;
    343      1.17       erh 	int how;
    344      1.17       erh 	const linux_old_sigset_t *set;
    345      1.17       erh 	linux_old_sigset_t *oset;
    346       1.8   thorpej {
    347      1.14       erh 	linux_old_sigset_t nlss, olss;
    348      1.12   mycroft 	sigset_t nbss, obss;
    349      1.12   mycroft 	int error;
    350       1.1      fvdl 
    351      1.17       erh 	switch (how) {
    352       1.1      fvdl 	case LINUX_SIG_BLOCK:
    353      1.12   mycroft 		how = SIG_BLOCK;
    354       1.1      fvdl 		break;
    355       1.1      fvdl 	case LINUX_SIG_UNBLOCK:
    356      1.12   mycroft 		how = SIG_UNBLOCK;
    357       1.1      fvdl 		break;
    358       1.1      fvdl 	case LINUX_SIG_SETMASK:
    359      1.12   mycroft 		how = SIG_SETMASK;
    360       1.1      fvdl 		break;
    361       1.1      fvdl 	default:
    362      1.12   mycroft 		return (EINVAL);
    363       1.1      fvdl 	}
    364       1.1      fvdl 
    365      1.17       erh 	if (set) {
    366      1.17       erh 		error = copyin(set, &nlss, sizeof(nlss));
    367      1.12   mycroft 		if (error)
    368      1.12   mycroft 			return (error);
    369  1.31.2.3   nathanw 		linux_old_to_native_sigset(&nbss, &nlss);
    370      1.12   mycroft 	}
    371      1.12   mycroft 	error = sigprocmask1(p, how,
    372      1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    373      1.12   mycroft 	if (error)
    374      1.12   mycroft 		return (error);
    375      1.17       erh 	if (oset) {
    376  1.31.2.3   nathanw 		native_to_linux_old_sigset(&olss, &obss);
    377      1.17       erh 		error = copyout(&olss, oset, sizeof(olss));
    378      1.12   mycroft 		if (error)
    379      1.12   mycroft 			return (error);
    380      1.12   mycroft 	}
    381      1.12   mycroft 	return (error);
    382      1.17       erh }
    383      1.17       erh 
    384      1.17       erh int
    385  1.31.2.1   nathanw linux_sys_rt_sigprocmask(l, v, retval)
    386  1.31.2.1   nathanw 	struct lwp *l;
    387      1.17       erh 	void *v;
    388      1.17       erh 	register_t *retval;
    389      1.17       erh {
    390      1.17       erh 	struct linux_sys_rt_sigprocmask_args /* {
    391      1.17       erh 		syscallarg(int) how;
    392      1.17       erh 		syscallarg(const linux_sigset_t *) set;
    393      1.17       erh 		syscallarg(linux_sigset_t *) oset;
    394      1.17       erh 		syscallarg(size_t) sigsetsize;
    395      1.17       erh 	} */ *uap = v;
    396  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    397      1.24      fvdl 	linux_sigset_t nlss, olss, *oset;
    398      1.24      fvdl 	const linux_sigset_t *set;
    399      1.24      fvdl 	sigset_t nbss, obss;
    400      1.24      fvdl 	int error, how;
    401      1.24      fvdl 
    402      1.24      fvdl 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    403      1.24      fvdl 		return (EINVAL);
    404      1.24      fvdl 
    405      1.24      fvdl 	switch (SCARG(uap, how)) {
    406      1.24      fvdl 	case LINUX_SIG_BLOCK:
    407      1.24      fvdl 		how = SIG_BLOCK;
    408      1.24      fvdl 		break;
    409      1.24      fvdl 	case LINUX_SIG_UNBLOCK:
    410      1.24      fvdl 		how = SIG_UNBLOCK;
    411      1.24      fvdl 		break;
    412      1.24      fvdl 	case LINUX_SIG_SETMASK:
    413      1.24      fvdl 		how = SIG_SETMASK;
    414      1.24      fvdl 		break;
    415      1.24      fvdl 	default:
    416      1.24      fvdl 		return (EINVAL);
    417      1.17       erh 	}
    418      1.17       erh 
    419      1.24      fvdl 	set = SCARG(uap, set);
    420      1.24      fvdl 	oset = SCARG(uap, oset);
    421      1.24      fvdl 
    422      1.24      fvdl 	if (set) {
    423      1.24      fvdl 		error = copyin(set, &nlss, sizeof(nlss));
    424      1.24      fvdl 		if (error)
    425      1.24      fvdl 			return (error);
    426  1.31.2.3   nathanw 		linux_to_native_sigset(&nbss, &nlss);
    427      1.24      fvdl 	}
    428      1.24      fvdl 	error = sigprocmask1(p, how,
    429      1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    430      1.28      tron 	if (!error && oset) {
    431  1.31.2.3   nathanw 		native_to_linux_sigset(&olss, &obss);
    432      1.24      fvdl 		error = copyout(&olss, oset, sizeof(olss));
    433      1.24      fvdl 	}
    434      1.24      fvdl 	return (error);
    435       1.1      fvdl }
    436       1.1      fvdl 
    437       1.1      fvdl int
    438  1.31.2.1   nathanw linux_sys_rt_sigpending(l, v, retval)
    439  1.31.2.1   nathanw 	struct lwp *l;
    440       1.9   mycroft 	void *v;
    441       1.1      fvdl 	register_t *retval;
    442       1.1      fvdl {
    443      1.14       erh 	struct linux_sys_rt_sigpending_args /* {
    444      1.14       erh 		syscallarg(linux_sigset_t *) set;
    445      1.14       erh 		syscallarg(size_t) sigsetsize;
    446      1.14       erh 	} */ *uap = v;
    447  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    448      1.12   mycroft 	sigset_t bss;
    449      1.12   mycroft 	linux_sigset_t lss;
    450       1.6   mycroft 
    451      1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    452      1.14       erh 		return (EINVAL);
    453      1.14       erh 
    454      1.14       erh 	sigpending1(p, &bss);
    455  1.31.2.3   nathanw 	native_to_linux_sigset(&lss, &bss);
    456      1.14       erh 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    457       1.1      fvdl }
    458      1.24      fvdl 
    459       1.1      fvdl int
    460  1.31.2.1   nathanw linux_sys_sigpending(l, v, retval)
    461  1.31.2.1   nathanw 	struct lwp *l;
    462       1.8   thorpej 	void *v;
    463       1.8   thorpej 	register_t *retval;
    464       1.8   thorpej {
    465       1.9   mycroft 	struct linux_sys_sigpending_args /* {
    466      1.14       erh 		syscallarg(linux_old_sigset_t *) mask;
    467       1.8   thorpej 	} */ *uap = v;
    468  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    469      1.12   mycroft 	sigset_t bss;
    470      1.14       erh 	linux_old_sigset_t lss;
    471       1.1      fvdl 
    472      1.12   mycroft 	sigpending1(p, &bss);
    473  1.31.2.3   nathanw 	native_to_linux_old_sigset(&lss, &bss);
    474      1.12   mycroft 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    475       1.1      fvdl }
    476       1.1      fvdl 
    477       1.1      fvdl int
    478  1.31.2.1   nathanw linux_sys_sigsuspend(l, v, retval)
    479  1.31.2.1   nathanw 	struct lwp *l;
    480       1.8   thorpej 	void *v;
    481       1.8   thorpej 	register_t *retval;
    482       1.8   thorpej {
    483       1.9   mycroft 	struct linux_sys_sigsuspend_args /* {
    484       1.3      fvdl 		syscallarg(caddr_t) restart;
    485       1.3      fvdl 		syscallarg(int) oldmask;
    486       1.1      fvdl 		syscallarg(int) mask;
    487       1.8   thorpej 	} */ *uap = v;
    488  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    489      1.14       erh 	linux_old_sigset_t lss;
    490      1.14       erh 	sigset_t bss;
    491      1.14       erh 
    492      1.14       erh 	lss = SCARG(uap, mask);
    493  1.31.2.3   nathanw 	linux_old_to_native_sigset(&bss, &lss);
    494      1.14       erh 	return (sigsuspend1(p, &bss));
    495      1.14       erh }
    496      1.14       erh int
    497  1.31.2.1   nathanw linux_sys_rt_sigsuspend(l, v, retval)
    498  1.31.2.1   nathanw 	struct lwp *l;
    499      1.14       erh 	void *v;
    500      1.14       erh 	register_t *retval;
    501      1.14       erh {
    502      1.14       erh 	struct linux_sys_rt_sigsuspend_args /* {
    503      1.14       erh 		syscallarg(linux_sigset_t *) unewset;
    504      1.14       erh 		syscallarg(size_t) sigsetsize;
    505      1.14       erh 	} */ *uap = v;
    506  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    507      1.12   mycroft 	linux_sigset_t lss;
    508      1.12   mycroft 	sigset_t bss;
    509      1.14       erh 	int error;
    510      1.14       erh 
    511      1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    512      1.14       erh 		return (EINVAL);
    513      1.14       erh 
    514      1.14       erh 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    515      1.14       erh 	if (error)
    516      1.14       erh 		return (error);
    517      1.14       erh 
    518  1.31.2.3   nathanw 	linux_to_native_sigset(&bss, &lss);
    519      1.14       erh 
    520      1.12   mycroft 	return (sigsuspend1(p, &bss));
    521       1.3      fvdl }
    522       1.3      fvdl 
    523       1.3      fvdl /*
    524      1.14       erh  * Once more: only a signal conversion is needed.
    525      1.14       erh  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    526       1.3      fvdl  */
    527       1.3      fvdl int
    528  1.31.2.1   nathanw linux_sys_rt_queueinfo(l, v, retval)
    529  1.31.2.1   nathanw 	struct lwp *l;
    530      1.14       erh 	void *v;
    531       1.3      fvdl 	register_t *retval;
    532      1.14       erh {
    533      1.14       erh 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    534      1.14       erh #if 0
    535      1.14       erh 	struct linux_sys_rt_queueinfo_args /* {
    536      1.14       erh 		syscallarg(int) pid;
    537      1.14       erh 		syscallarg(int) signum;
    538      1.14       erh 		syscallarg(siginfo_t *) uinfo;
    539      1.14       erh 	} */ *uap = v;
    540      1.14       erh #endif
    541       1.3      fvdl 
    542      1.14       erh 	/* XXX To really implement this we need to	*/
    543      1.14       erh 	/* XXX keep a list of queued signals somewhere.	*/
    544  1.31.2.1   nathanw 	return (linux_sys_kill(l, v, retval));
    545       1.1      fvdl }
    546       1.1      fvdl 
    547       1.1      fvdl int
    548  1.31.2.1   nathanw linux_sys_kill(l, v, retval)
    549  1.31.2.1   nathanw 	struct lwp *l;
    550       1.8   thorpej 	void *v;
    551       1.8   thorpej 	register_t *retval;
    552       1.8   thorpej {
    553       1.9   mycroft 	struct linux_sys_kill_args /* {
    554       1.1      fvdl 		syscallarg(int) pid;
    555       1.1      fvdl 		syscallarg(int) signum;
    556       1.8   thorpej 	} */ *uap = v;
    557  1.31.2.1   nathanw 
    558       1.9   mycroft 	struct sys_kill_args ka;
    559      1.25      tron 	int sig;
    560       1.6   mycroft 
    561       1.6   mycroft 	SCARG(&ka, pid) = SCARG(uap, pid);
    562      1.25      tron 	sig = SCARG(uap, signum);
    563      1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    564      1.25      tron 		return (EINVAL);
    565  1.31.2.5   nathanw 	SCARG(&ka, signum) = linux_to_native_signo[sig];
    566  1.31.2.1   nathanw 	return sys_kill(l, &ka, retval);
    567       1.1      fvdl }
    568      1.30  christos 
    569      1.30  christos #ifdef LINUX_SS_ONSTACK
    570      1.30  christos static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    571      1.30  christos     const struct linux_sigaltstack *));
    572      1.30  christos static void native_to_linux_sigaltstack __P((struct linux_sigaltstack *,
    573      1.30  christos     const struct sigaltstack *));
    574      1.30  christos 
    575      1.30  christos static void
    576      1.30  christos linux_to_native_sigaltstack(bss, lss)
    577      1.30  christos 	struct sigaltstack *bss;
    578      1.30  christos 	const struct linux_sigaltstack *lss;
    579      1.30  christos {
    580      1.30  christos 	bss->ss_sp = lss->ss_sp;
    581      1.30  christos 	bss->ss_size = lss->ss_size;
    582      1.30  christos 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    583      1.30  christos 	    bss->ss_flags = SS_ONSTACK;
    584      1.30  christos 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    585      1.30  christos 	    bss->ss_flags = SS_DISABLE;
    586      1.30  christos 	else
    587      1.30  christos 	    bss->ss_flags = 0;
    588      1.30  christos }
    589      1.30  christos 
    590      1.30  christos static void
    591      1.30  christos native_to_linux_sigaltstack(lss, bss)
    592      1.30  christos 	struct linux_sigaltstack *lss;
    593      1.30  christos 	const struct sigaltstack *bss;
    594      1.30  christos {
    595      1.30  christos 	lss->ss_sp = bss->ss_sp;
    596      1.30  christos 	lss->ss_size = bss->ss_size;
    597      1.30  christos 	if (bss->ss_flags & SS_ONSTACK)
    598      1.30  christos 	    lss->ss_flags = LINUX_SS_ONSTACK;
    599      1.30  christos 	else if (bss->ss_flags & SS_DISABLE)
    600      1.30  christos 	    lss->ss_flags = LINUX_SS_DISABLE;
    601      1.30  christos 	else
    602      1.30  christos 	    lss->ss_flags = 0;
    603      1.30  christos }
    604      1.30  christos 
    605      1.30  christos int
    606  1.31.2.1   nathanw linux_sys_sigaltstack(l, v, retval)
    607  1.31.2.1   nathanw 	struct lwp *l;
    608      1.30  christos 	void *v;
    609      1.30  christos 	register_t *retval;
    610      1.30  christos {
    611      1.30  christos 	struct linux_sys_sigaltstack_args /* {
    612      1.30  christos 		syscallarg(const struct linux_sigaltstack *) ss;
    613      1.30  christos 		syscallarg(struct linux_sigaltstack *) oss;
    614      1.30  christos 	} */ *uap = v;
    615  1.31.2.1   nathanw 	struct proc *p = l->l_proc;
    616      1.30  christos 	struct linux_sigaltstack ss;
    617      1.30  christos 	struct sigaltstack nss, oss;
    618      1.30  christos 	int error;
    619      1.30  christos 
    620      1.30  christos 	if (SCARG(uap, ss) != NULL) {
    621      1.30  christos 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    622      1.30  christos 			return error;
    623      1.30  christos 		linux_to_native_sigaltstack(&nss, &ss);
    624      1.30  christos 	}
    625      1.30  christos 
    626      1.30  christos 	error = sigaltstack1(p,
    627      1.30  christos 	    SCARG(uap, ss) ? &nss : NULL, SCARG(uap, oss) ? &oss : NULL);
    628      1.30  christos 	if (error)
    629      1.30  christos 		return error;
    630      1.30  christos 
    631      1.30  christos 	if (SCARG(uap, oss) != NULL) {
    632      1.30  christos 		native_to_linux_sigaltstack(&ss, &oss);
    633      1.30  christos 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    634      1.30  christos 			return error;
    635      1.30  christos 	}
    636      1.30  christos 	return 0;
    637      1.30  christos }
    638      1.30  christos #endif
    639