Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.49
      1  1.49      manu /*	$NetBSD: linux_signal.c,v 1.49 2005/11/23 16:14:57 manu 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.32     lukem 
     56  1.32     lukem #include <sys/cdefs.h>
     57  1.49      manu __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.49 2005/11/23 16:14:57 manu 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.1      fvdl #include <sys/proc.h>
     65   1.1      fvdl #include <sys/filedesc.h>
     66   1.1      fvdl #include <sys/ioctl.h>
     67   1.1      fvdl #include <sys/mount.h>
     68   1.1      fvdl #include <sys/kernel.h>
     69   1.1      fvdl #include <sys/signal.h>
     70   1.1      fvdl #include <sys/signalvar.h>
     71   1.1      fvdl #include <sys/malloc.h>
     72   1.1      fvdl 
     73  1.40   thorpej #include <sys/sa.h>
     74   1.1      fvdl #include <sys/syscallargs.h>
     75   1.1      fvdl 
     76  1.15  christos #include <compat/linux/common/linux_types.h>
     77  1.15  christos #include <compat/linux/common/linux_signal.h>
     78  1.49      manu #include <compat/linux/common/linux_exec.h> /* For emul_linux */
     79  1.49      manu #include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
     80  1.49      manu #include <compat/linux/common/linux_emuldata.h> /* for linux_emuldata */
     81  1.17       erh #include <compat/linux/common/linux_siginfo.h>
     82  1.45      fvdl #include <compat/linux/common/linux_sigevent.h>
     83  1.15  christos #include <compat/linux/common/linux_util.h>
     84  1.15  christos 
     85   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     86   1.1      fvdl 
     87  1.14       erh /* Locally used defines (in bsd<->linux conversion functions): */
     88  1.11     perry #define	linux_sigemptyset(s)	memset((s), 0, sizeof(*(s)))
     89  1.20     itohy #define	linux_sigismember(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     90  1.20     itohy 					& (1 << ((n) - 1) % LINUX__NSIG_BPW))
     91  1.20     itohy #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     92  1.20     itohy 					|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
     93   1.6   mycroft 
     94  1.36  christos #ifdef DEBUG_LINUX
     95  1.36  christos #define DPRINTF(a)	uprintf a
     96  1.36  christos #else
     97  1.36  christos #define DPRINTF(a)
     98  1.36  christos #endif
     99  1.36  christos 
    100  1.37  christos extern const int native_to_linux_signo[];
    101  1.37  christos extern const int linux_to_native_signo[];
    102   1.6   mycroft 
    103  1.14       erh /*
    104  1.20     itohy  * Convert between Linux and BSD signal sets.
    105  1.14       erh  */
    106  1.20     itohy #if LINUX__NSIG_WORDS > 1
    107   1.6   mycroft void
    108  1.33  christos linux_old_extra_to_native_sigset(bss, lss, extra)
    109  1.33  christos 	sigset_t *bss;
    110  1.14       erh 	const linux_old_sigset_t *lss;
    111  1.20     itohy 	const unsigned long *extra;
    112  1.20     itohy {
    113  1.20     itohy 	linux_sigset_t lsnew;
    114  1.20     itohy 
    115  1.20     itohy 	/* convert old sigset to new sigset */
    116  1.20     itohy 	linux_sigemptyset(&lsnew);
    117  1.20     itohy 	lsnew.sig[0] = *lss;
    118  1.20     itohy 	if (extra)
    119  1.33  christos 		memcpy(&lsnew.sig[1], extra,
    120  1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    121  1.20     itohy 
    122  1.33  christos 	linux_to_native_sigset(bss, &lsnew);
    123  1.20     itohy }
    124  1.20     itohy 
    125  1.20     itohy void
    126  1.33  christos native_to_linux_old_extra_sigset(lss, extra, bss)
    127  1.20     itohy 	linux_old_sigset_t *lss;
    128  1.20     itohy 	unsigned long *extra;
    129  1.33  christos 	const sigset_t *bss;
    130  1.20     itohy {
    131  1.20     itohy 	linux_sigset_t lsnew;
    132  1.20     itohy 
    133  1.33  christos 	native_to_linux_sigset(&lsnew, bss);
    134  1.20     itohy 
    135  1.20     itohy 	/* convert new sigset to old sigset */
    136  1.20     itohy 	*lss = lsnew.sig[0];
    137  1.20     itohy 	if (extra)
    138  1.33  christos 		memcpy(extra, &lsnew.sig[1],
    139  1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    140  1.20     itohy }
    141  1.43      manu #endif /* LINUX__NSIG_WORDS > 1 */
    142  1.20     itohy 
    143  1.20     itohy void
    144  1.33  christos linux_to_native_sigset(bss, lss)
    145  1.33  christos 	sigset_t *bss;
    146  1.20     itohy 	const linux_sigset_t *lss;
    147   1.1      fvdl {
    148   1.1      fvdl 	int i, newsig;
    149   1.1      fvdl 
    150   1.6   mycroft 	sigemptyset(bss);
    151  1.20     itohy 	for (i = 1; i < LINUX__NSIG; i++) {
    152   1.6   mycroft 		if (linux_sigismember(lss, i)) {
    153  1.37  christos 			newsig = linux_to_native_signo[i];
    154   1.1      fvdl 			if (newsig)
    155   1.6   mycroft 				sigaddset(bss, newsig);
    156   1.1      fvdl 		}
    157   1.1      fvdl 	}
    158   1.1      fvdl }
    159   1.1      fvdl 
    160   1.1      fvdl void
    161  1.33  christos native_to_linux_sigset(lss, bss)
    162  1.33  christos 	linux_sigset_t *lss;
    163   1.1      fvdl 	const sigset_t *bss;
    164   1.1      fvdl {
    165   1.1      fvdl 	int i, newsig;
    166  1.20     itohy 
    167   1.6   mycroft 	linux_sigemptyset(lss);
    168   1.6   mycroft 	for (i = 1; i < NSIG; i++) {
    169   1.6   mycroft 		if (sigismember(bss, i)) {
    170  1.37  christos 			newsig = native_to_linux_signo[i];
    171   1.1      fvdl 			if (newsig)
    172   1.6   mycroft 				linux_sigaddset(lss, newsig);
    173   1.1      fvdl 		}
    174   1.1      fvdl 	}
    175   1.1      fvdl }
    176   1.1      fvdl 
    177  1.34  christos unsigned int
    178  1.34  christos native_to_linux_sigflags(bsf)
    179  1.34  christos 	const int bsf;
    180  1.33  christos {
    181  1.34  christos 	unsigned int lsf = 0;
    182  1.34  christos 	if ((bsf & SA_NOCLDSTOP) != 0)
    183  1.34  christos 		lsf |= LINUX_SA_NOCLDSTOP;
    184  1.34  christos 	if ((bsf & SA_NOCLDWAIT) != 0)
    185  1.34  christos 		lsf |= LINUX_SA_NOCLDWAIT;
    186  1.34  christos 	if ((bsf & SA_ONSTACK) != 0)
    187  1.34  christos 		lsf |= LINUX_SA_ONSTACK;
    188  1.34  christos 	if ((bsf & SA_RESTART) != 0)
    189  1.34  christos 		lsf |= LINUX_SA_RESTART;
    190  1.34  christos 	if ((bsf & SA_NODEFER) != 0)
    191  1.34  christos 		lsf |= LINUX_SA_NOMASK;
    192  1.34  christos 	if ((bsf & SA_RESETHAND) != 0)
    193  1.34  christos 		lsf |= LINUX_SA_ONESHOT;
    194  1.34  christos 	if ((bsf & SA_SIGINFO) != 0)
    195  1.34  christos 		lsf |= LINUX_SA_SIGINFO;
    196  1.34  christos 	return lsf;
    197  1.33  christos }
    198  1.33  christos 
    199  1.34  christos int
    200  1.34  christos linux_to_native_sigflags(lsf)
    201  1.34  christos 	const unsigned long lsf;
    202  1.33  christos {
    203  1.34  christos 	int bsf = 0;
    204  1.34  christos 	if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
    205  1.34  christos 		bsf |= SA_NOCLDSTOP;
    206  1.34  christos 	if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
    207  1.34  christos 		bsf |= SA_NOCLDWAIT;
    208  1.34  christos 	if ((lsf & LINUX_SA_ONSTACK) != 0)
    209  1.34  christos 		bsf |= SA_ONSTACK;
    210  1.34  christos 	if ((lsf & LINUX_SA_RESTART) != 0)
    211  1.34  christos 		bsf |= SA_RESTART;
    212  1.34  christos 	if ((lsf & LINUX_SA_ONESHOT) != 0)
    213  1.34  christos 		bsf |= SA_RESETHAND;
    214  1.34  christos 	if ((lsf & LINUX_SA_NOMASK) != 0)
    215  1.34  christos 		bsf |= SA_NODEFER;
    216  1.34  christos 	if ((lsf & LINUX_SA_SIGINFO) != 0)
    217  1.34  christos 		bsf |= SA_SIGINFO;
    218  1.34  christos 	if ((lsf & ~LINUX_SA_ALLBITS) != 0)
    219  1.36  christos 		DPRINTF(("linux_old_to_native_sigflags: "
    220  1.36  christos 		    "%lx extra bits ignored\n", lsf));
    221  1.34  christos 	return bsf;
    222  1.33  christos }
    223  1.33  christos 
    224   1.1      fvdl /*
    225  1.46      manu  * Convert between Linux and BSD sigaction structures.
    226   1.1      fvdl  */
    227   1.1      fvdl void
    228  1.33  christos linux_old_to_native_sigaction(bsa, lsa)
    229  1.14       erh 	struct sigaction *bsa;
    230  1.33  christos 	const struct linux_old_sigaction *lsa;
    231  1.14       erh {
    232  1.39  christos 	bsa->sa_handler = lsa->linux_sa_handler;
    233  1.39  christos 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    234  1.39  christos 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    235  1.14       erh }
    236  1.14       erh 
    237  1.14       erh void
    238  1.33  christos native_to_linux_old_sigaction(lsa, bsa)
    239  1.14       erh 	struct linux_old_sigaction *lsa;
    240  1.33  christos 	const struct sigaction *bsa;
    241  1.14       erh {
    242  1.39  christos 	lsa->linux_sa_handler = bsa->sa_handler;
    243  1.39  christos 	native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    244  1.39  christos 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    245  1.34  christos #ifndef __alpha__
    246  1.39  christos 	lsa->linux_sa_restorer = NULL;
    247  1.34  christos #endif
    248  1.14       erh }
    249  1.14       erh 
    250  1.14       erh /* ...and the new sigaction conversion funcs. */
    251  1.14       erh void
    252  1.33  christos linux_to_native_sigaction(bsa, lsa)
    253   1.1      fvdl 	struct sigaction *bsa;
    254  1.33  christos 	const struct linux_sigaction *lsa;
    255   1.1      fvdl {
    256  1.39  christos 	bsa->sa_handler = lsa->linux_sa_handler;
    257  1.39  christos 	linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    258  1.39  christos 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    259   1.1      fvdl }
    260   1.1      fvdl 
    261   1.1      fvdl void
    262  1.33  christos native_to_linux_sigaction(lsa, bsa)
    263   1.1      fvdl 	struct linux_sigaction *lsa;
    264  1.33  christos 	const struct sigaction *bsa;
    265   1.1      fvdl {
    266  1.39  christos 	lsa->linux_sa_handler = bsa->sa_handler;
    267  1.39  christos 	native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    268  1.39  christos 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    269  1.34  christos #ifndef __alpha__
    270  1.39  christos 	lsa->linux_sa_restorer = NULL;
    271  1.34  christos #endif
    272   1.1      fvdl }
    273   1.1      fvdl 
    274  1.14       erh /* ----------------------------------------------------------------------- */
    275   1.1      fvdl 
    276   1.1      fvdl /*
    277   1.1      fvdl  * The Linux sigaction() system call. Do the usual conversions,
    278   1.1      fvdl  * and just call sigaction(). Some flags and values are silently
    279   1.1      fvdl  * ignored (see above).
    280   1.1      fvdl  */
    281   1.1      fvdl int
    282  1.40   thorpej linux_sys_rt_sigaction(l, v, retval)
    283  1.40   thorpej 	struct lwp *l;
    284   1.8   thorpej 	void *v;
    285   1.8   thorpej 	register_t *retval;
    286   1.8   thorpej {
    287  1.14       erh 	struct linux_sys_rt_sigaction_args /* {
    288   1.1      fvdl 		syscallarg(int) signum;
    289  1.12   mycroft 		syscallarg(const struct linux_sigaction *) nsa;
    290   1.1      fvdl 		syscallarg(struct linux_sigaction *) osa;
    291  1.14       erh 		syscallarg(size_t) sigsetsize;
    292   1.8   thorpej 	} */ *uap = v;
    293  1.40   thorpej 	struct proc *p = l->l_proc;
    294  1.12   mycroft 	struct linux_sigaction nlsa, olsa;
    295  1.12   mycroft 	struct sigaction nbsa, obsa;
    296  1.25      tron 	int error, sig;
    297  1.46      manu 	void *tramp = NULL;
    298  1.46      manu 	int vers = 0;
    299  1.47       mrg #if defined __amd64__
    300  1.46      manu 	struct sigacts *ps = p->p_sigacts;
    301  1.46      manu #endif
    302   1.1      fvdl 
    303  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    304  1.14       erh 		return (EINVAL);
    305  1.14       erh 
    306  1.12   mycroft 	if (SCARG(uap, nsa)) {
    307  1.12   mycroft 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    308  1.12   mycroft 		if (error)
    309  1.12   mycroft 			return (error);
    310  1.33  christos 		linux_to_native_sigaction(&nbsa, &nlsa);
    311  1.12   mycroft 	}
    312  1.46      manu 
    313  1.25      tron 	sig = SCARG(uap, signum);
    314  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    315  1.25      tron 		return (EINVAL);
    316  1.37  christos 	if (sig > 0 && !linux_to_native_signo[sig]) {
    317  1.29        tv 		/* Pretend that we did something useful for unknown signals. */
    318  1.29        tv 		obsa.sa_handler = SIG_IGN;
    319  1.29        tv 		sigemptyset(&obsa.sa_mask);
    320  1.29        tv 		obsa.sa_flags = 0;
    321  1.29        tv 	} else {
    322  1.46      manu #if defined __amd64__
    323  1.46      manu 		if (nlsa.linux_sa_flags & LINUX_SA_RESTORER) {
    324  1.46      manu 			if ((tramp = nlsa.linux_sa_restorer) != NULL)
    325  1.46      manu 				vers = 2; /* XXX arch dependant */
    326  1.46      manu 		}
    327  1.46      manu #endif
    328  1.46      manu 
    329  1.37  christos 		error = sigaction1(p, linux_to_native_signo[sig],
    330  1.38   thorpej 		    SCARG(uap, nsa) ? &nbsa : NULL,
    331  1.38   thorpej 		    SCARG(uap, osa) ? &obsa : NULL,
    332  1.46      manu 		    tramp, vers);
    333  1.29        tv 		if (error)
    334  1.29        tv 			return (error);
    335  1.29        tv 	}
    336  1.12   mycroft 	if (SCARG(uap, osa)) {
    337  1.33  christos 		native_to_linux_sigaction(&olsa, &obsa);
    338  1.46      manu 
    339  1.46      manu #if defined __amd64__
    340  1.46      manu 		if (ps->sa_sigdesc[sig].sd_vers != 0) {
    341  1.46      manu 			olsa.linux_sa_restorer = ps->sa_sigdesc[sig].sd_tramp;
    342  1.46      manu 			olsa.linux_sa_flags |= LINUX_SA_RESTORER;
    343  1.46      manu 		}
    344  1.46      manu #endif
    345  1.46      manu 
    346  1.12   mycroft 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    347  1.12   mycroft 		if (error)
    348  1.12   mycroft 			return (error);
    349   1.1      fvdl 	}
    350  1.12   mycroft 	return (0);
    351   1.1      fvdl }
    352   1.1      fvdl 
    353   1.1      fvdl int
    354  1.17       erh linux_sigprocmask1(p, how, set, oset)
    355  1.26  augustss 	struct proc *p;
    356  1.17       erh 	int how;
    357  1.17       erh 	const linux_old_sigset_t *set;
    358  1.17       erh 	linux_old_sigset_t *oset;
    359   1.8   thorpej {
    360  1.14       erh 	linux_old_sigset_t nlss, olss;
    361  1.12   mycroft 	sigset_t nbss, obss;
    362  1.12   mycroft 	int error;
    363   1.1      fvdl 
    364  1.17       erh 	switch (how) {
    365   1.1      fvdl 	case LINUX_SIG_BLOCK:
    366  1.12   mycroft 		how = SIG_BLOCK;
    367   1.1      fvdl 		break;
    368   1.1      fvdl 	case LINUX_SIG_UNBLOCK:
    369  1.12   mycroft 		how = SIG_UNBLOCK;
    370   1.1      fvdl 		break;
    371   1.1      fvdl 	case LINUX_SIG_SETMASK:
    372  1.12   mycroft 		how = SIG_SETMASK;
    373   1.1      fvdl 		break;
    374   1.1      fvdl 	default:
    375  1.12   mycroft 		return (EINVAL);
    376   1.1      fvdl 	}
    377   1.1      fvdl 
    378  1.17       erh 	if (set) {
    379  1.17       erh 		error = copyin(set, &nlss, sizeof(nlss));
    380  1.12   mycroft 		if (error)
    381  1.12   mycroft 			return (error);
    382  1.33  christos 		linux_old_to_native_sigset(&nbss, &nlss);
    383  1.12   mycroft 	}
    384  1.12   mycroft 	error = sigprocmask1(p, how,
    385  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    386  1.12   mycroft 	if (error)
    387  1.42     perry 		return (error);
    388  1.17       erh 	if (oset) {
    389  1.33  christos 		native_to_linux_old_sigset(&olss, &obss);
    390  1.17       erh 		error = copyout(&olss, oset, sizeof(olss));
    391  1.12   mycroft 		if (error)
    392  1.12   mycroft 			return (error);
    393  1.42     perry 	}
    394  1.12   mycroft 	return (error);
    395  1.17       erh }
    396  1.17       erh 
    397  1.17       erh int
    398  1.40   thorpej linux_sys_rt_sigprocmask(l, v, retval)
    399  1.40   thorpej 	struct lwp *l;
    400  1.17       erh 	void *v;
    401  1.17       erh 	register_t *retval;
    402  1.17       erh {
    403  1.17       erh 	struct linux_sys_rt_sigprocmask_args /* {
    404  1.17       erh 		syscallarg(int) how;
    405  1.17       erh 		syscallarg(const linux_sigset_t *) set;
    406  1.17       erh 		syscallarg(linux_sigset_t *) oset;
    407  1.17       erh 		syscallarg(size_t) sigsetsize;
    408  1.17       erh 	} */ *uap = v;
    409  1.40   thorpej 	struct proc *p = l->l_proc;
    410  1.24      fvdl 	linux_sigset_t nlss, olss, *oset;
    411  1.24      fvdl 	const linux_sigset_t *set;
    412  1.24      fvdl 	sigset_t nbss, obss;
    413  1.24      fvdl 	int error, how;
    414  1.24      fvdl 
    415  1.24      fvdl 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    416  1.24      fvdl 		return (EINVAL);
    417  1.24      fvdl 
    418  1.24      fvdl 	switch (SCARG(uap, how)) {
    419  1.24      fvdl 	case LINUX_SIG_BLOCK:
    420  1.24      fvdl 		how = SIG_BLOCK;
    421  1.24      fvdl 		break;
    422  1.24      fvdl 	case LINUX_SIG_UNBLOCK:
    423  1.24      fvdl 		how = SIG_UNBLOCK;
    424  1.24      fvdl 		break;
    425  1.24      fvdl 	case LINUX_SIG_SETMASK:
    426  1.24      fvdl 		how = SIG_SETMASK;
    427  1.24      fvdl 		break;
    428  1.24      fvdl 	default:
    429  1.24      fvdl 		return (EINVAL);
    430  1.17       erh 	}
    431  1.17       erh 
    432  1.24      fvdl 	set = SCARG(uap, set);
    433  1.24      fvdl 	oset = SCARG(uap, oset);
    434  1.24      fvdl 
    435  1.24      fvdl 	if (set) {
    436  1.24      fvdl 		error = copyin(set, &nlss, sizeof(nlss));
    437  1.24      fvdl 		if (error)
    438  1.24      fvdl 			return (error);
    439  1.33  christos 		linux_to_native_sigset(&nbss, &nlss);
    440  1.24      fvdl 	}
    441  1.24      fvdl 	error = sigprocmask1(p, how,
    442  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    443  1.28      tron 	if (!error && oset) {
    444  1.33  christos 		native_to_linux_sigset(&olss, &obss);
    445  1.24      fvdl 		error = copyout(&olss, oset, sizeof(olss));
    446  1.42     perry 	}
    447  1.24      fvdl 	return (error);
    448   1.1      fvdl }
    449   1.1      fvdl 
    450   1.1      fvdl int
    451  1.40   thorpej linux_sys_rt_sigpending(l, v, retval)
    452  1.40   thorpej 	struct lwp *l;
    453   1.9   mycroft 	void *v;
    454   1.1      fvdl 	register_t *retval;
    455   1.1      fvdl {
    456  1.14       erh 	struct linux_sys_rt_sigpending_args /* {
    457  1.14       erh 		syscallarg(linux_sigset_t *) set;
    458  1.14       erh 		syscallarg(size_t) sigsetsize;
    459  1.14       erh 	} */ *uap = v;
    460  1.40   thorpej 	struct proc *p = l->l_proc;
    461  1.12   mycroft 	sigset_t bss;
    462  1.12   mycroft 	linux_sigset_t lss;
    463   1.6   mycroft 
    464  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    465  1.14       erh 		return (EINVAL);
    466  1.14       erh 
    467  1.14       erh 	sigpending1(p, &bss);
    468  1.33  christos 	native_to_linux_sigset(&lss, &bss);
    469  1.14       erh 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    470   1.1      fvdl }
    471  1.24      fvdl 
    472  1.43      manu #ifndef __amd64__
    473   1.1      fvdl int
    474  1.40   thorpej linux_sys_sigpending(l, v, retval)
    475  1.40   thorpej 	struct lwp *l;
    476   1.8   thorpej 	void *v;
    477   1.8   thorpej 	register_t *retval;
    478   1.8   thorpej {
    479   1.9   mycroft 	struct linux_sys_sigpending_args /* {
    480  1.14       erh 		syscallarg(linux_old_sigset_t *) mask;
    481   1.8   thorpej 	} */ *uap = v;
    482  1.40   thorpej 	struct proc *p = l->l_proc;
    483  1.12   mycroft 	sigset_t bss;
    484  1.14       erh 	linux_old_sigset_t lss;
    485   1.1      fvdl 
    486  1.12   mycroft 	sigpending1(p, &bss);
    487  1.33  christos 	native_to_linux_old_sigset(&lss, &bss);
    488  1.12   mycroft 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    489   1.1      fvdl }
    490   1.1      fvdl 
    491   1.1      fvdl int
    492  1.40   thorpej linux_sys_sigsuspend(l, v, retval)
    493  1.40   thorpej 	struct lwp *l;
    494   1.8   thorpej 	void *v;
    495   1.8   thorpej 	register_t *retval;
    496   1.8   thorpej {
    497   1.9   mycroft 	struct linux_sys_sigsuspend_args /* {
    498   1.3      fvdl 		syscallarg(caddr_t) restart;
    499   1.3      fvdl 		syscallarg(int) oldmask;
    500   1.1      fvdl 		syscallarg(int) mask;
    501   1.8   thorpej 	} */ *uap = v;
    502  1.40   thorpej 	struct proc *p = l->l_proc;
    503  1.14       erh 	linux_old_sigset_t lss;
    504  1.14       erh 	sigset_t bss;
    505  1.14       erh 
    506  1.14       erh 	lss = SCARG(uap, mask);
    507  1.33  christos 	linux_old_to_native_sigset(&bss, &lss);
    508  1.14       erh 	return (sigsuspend1(p, &bss));
    509  1.14       erh }
    510  1.43      manu #endif /* __amd64__ */
    511  1.43      manu 
    512  1.14       erh int
    513  1.40   thorpej linux_sys_rt_sigsuspend(l, v, retval)
    514  1.40   thorpej 	struct lwp *l;
    515  1.14       erh 	void *v;
    516  1.14       erh 	register_t *retval;
    517  1.14       erh {
    518  1.14       erh 	struct linux_sys_rt_sigsuspend_args /* {
    519  1.14       erh 		syscallarg(linux_sigset_t *) unewset;
    520  1.14       erh 		syscallarg(size_t) sigsetsize;
    521  1.14       erh 	} */ *uap = v;
    522  1.40   thorpej 	struct proc *p = l->l_proc;
    523  1.12   mycroft 	linux_sigset_t lss;
    524  1.12   mycroft 	sigset_t bss;
    525  1.14       erh 	int error;
    526  1.14       erh 
    527  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    528  1.14       erh 		return (EINVAL);
    529  1.14       erh 
    530  1.14       erh 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    531  1.14       erh 	if (error)
    532  1.14       erh 		return (error);
    533  1.14       erh 
    534  1.33  christos 	linux_to_native_sigset(&bss, &lss);
    535  1.14       erh 
    536  1.12   mycroft 	return (sigsuspend1(p, &bss));
    537   1.3      fvdl }
    538   1.3      fvdl 
    539   1.3      fvdl /*
    540  1.14       erh  * Once more: only a signal conversion is needed.
    541  1.14       erh  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    542   1.3      fvdl  */
    543   1.3      fvdl int
    544  1.40   thorpej linux_sys_rt_queueinfo(l, v, retval)
    545  1.40   thorpej 	struct lwp *l;
    546  1.14       erh 	void *v;
    547   1.3      fvdl 	register_t *retval;
    548  1.14       erh {
    549  1.14       erh 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    550  1.14       erh #if 0
    551  1.14       erh 	struct linux_sys_rt_queueinfo_args /* {
    552  1.14       erh 		syscallarg(int) pid;
    553  1.14       erh 		syscallarg(int) signum;
    554  1.14       erh 		syscallarg(siginfo_t *) uinfo;
    555  1.14       erh 	} */ *uap = v;
    556  1.14       erh #endif
    557   1.3      fvdl 
    558  1.14       erh 	/* XXX To really implement this we need to	*/
    559  1.14       erh 	/* XXX keep a list of queued signals somewhere.	*/
    560  1.40   thorpej 	return (linux_sys_kill(l, v, retval));
    561   1.1      fvdl }
    562   1.1      fvdl 
    563   1.1      fvdl int
    564  1.40   thorpej linux_sys_kill(l, v, retval)
    565  1.40   thorpej 	struct lwp *l;
    566   1.8   thorpej 	void *v;
    567   1.8   thorpej 	register_t *retval;
    568   1.8   thorpej {
    569   1.9   mycroft 	struct linux_sys_kill_args /* {
    570   1.1      fvdl 		syscallarg(int) pid;
    571   1.1      fvdl 		syscallarg(int) signum;
    572   1.8   thorpej 	} */ *uap = v;
    573  1.40   thorpej 
    574   1.9   mycroft 	struct sys_kill_args ka;
    575  1.25      tron 	int sig;
    576   1.6   mycroft 
    577   1.6   mycroft 	SCARG(&ka, pid) = SCARG(uap, pid);
    578  1.25      tron 	sig = SCARG(uap, signum);
    579  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    580  1.25      tron 		return (EINVAL);
    581  1.37  christos 	SCARG(&ka, signum) = linux_to_native_signo[sig];
    582  1.40   thorpej 	return sys_kill(l, &ka, retval);
    583   1.1      fvdl }
    584  1.30  christos 
    585  1.30  christos #ifdef LINUX_SS_ONSTACK
    586  1.30  christos static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    587  1.30  christos     const struct linux_sigaltstack *));
    588  1.30  christos 
    589  1.30  christos static void
    590  1.30  christos linux_to_native_sigaltstack(bss, lss)
    591  1.30  christos 	struct sigaltstack *bss;
    592  1.30  christos 	const struct linux_sigaltstack *lss;
    593  1.30  christos {
    594  1.30  christos 	bss->ss_sp = lss->ss_sp;
    595  1.30  christos 	bss->ss_size = lss->ss_size;
    596  1.30  christos 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    597  1.30  christos 	    bss->ss_flags = SS_ONSTACK;
    598  1.30  christos 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    599  1.30  christos 	    bss->ss_flags = SS_DISABLE;
    600  1.30  christos 	else
    601  1.30  christos 	    bss->ss_flags = 0;
    602  1.30  christos }
    603  1.30  christos 
    604  1.41  christos void
    605  1.30  christos native_to_linux_sigaltstack(lss, bss)
    606  1.30  christos 	struct linux_sigaltstack *lss;
    607  1.30  christos 	const struct sigaltstack *bss;
    608  1.30  christos {
    609  1.30  christos 	lss->ss_sp = bss->ss_sp;
    610  1.30  christos 	lss->ss_size = bss->ss_size;
    611  1.30  christos 	if (bss->ss_flags & SS_ONSTACK)
    612  1.30  christos 	    lss->ss_flags = LINUX_SS_ONSTACK;
    613  1.30  christos 	else if (bss->ss_flags & SS_DISABLE)
    614  1.30  christos 	    lss->ss_flags = LINUX_SS_DISABLE;
    615  1.30  christos 	else
    616  1.30  christos 	    lss->ss_flags = 0;
    617  1.30  christos }
    618  1.30  christos 
    619  1.30  christos int
    620  1.40   thorpej linux_sys_sigaltstack(l, v, retval)
    621  1.40   thorpej 	struct lwp *l;
    622  1.30  christos 	void *v;
    623  1.30  christos 	register_t *retval;
    624  1.30  christos {
    625  1.30  christos 	struct linux_sys_sigaltstack_args /* {
    626  1.30  christos 		syscallarg(const struct linux_sigaltstack *) ss;
    627  1.30  christos 		syscallarg(struct linux_sigaltstack *) oss;
    628  1.30  christos 	} */ *uap = v;
    629  1.40   thorpej 	struct proc *p = l->l_proc;
    630  1.30  christos 	struct linux_sigaltstack ss;
    631  1.48  christos 	struct sigaltstack nss;
    632  1.30  christos 	int error;
    633  1.30  christos 
    634  1.48  christos 	if (SCARG(uap, oss)) {
    635  1.48  christos 		native_to_linux_sigaltstack(&ss, &p->p_sigctx.ps_sigstk);
    636  1.48  christos 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    637  1.48  christos 			return error;
    638  1.48  christos 	}
    639  1.48  christos 
    640  1.30  christos 	if (SCARG(uap, ss) != NULL) {
    641  1.30  christos 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    642  1.30  christos 			return error;
    643  1.30  christos 		linux_to_native_sigaltstack(&nss, &ss);
    644  1.30  christos 
    645  1.48  christos 		if (nss.ss_flags & ~SS_ALLBITS)
    646  1.48  christos 			return EINVAL;
    647  1.30  christos 
    648  1.48  christos 		if (nss.ss_flags & SS_DISABLE) {
    649  1.48  christos 			if (p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK)
    650  1.48  christos 				return EINVAL;
    651  1.48  christos 		} else {
    652  1.48  christos 			if (nss.ss_size < LINUX_MINSIGSTKSZ)
    653  1.48  christos 				return ENOMEM;
    654  1.48  christos 		}
    655  1.48  christos 		p->p_sigctx.ps_sigstk = nss;
    656  1.30  christos 	}
    657  1.48  christos 
    658  1.30  christos 	return 0;
    659  1.30  christos }
    660  1.44       jmc #endif /* LINUX_SS_ONSTACK */
    661  1.49      manu 
    662  1.49      manu #ifdef LINUX_NPTL
    663  1.49      manu int
    664  1.49      manu linux_sys_tkill(l, v, retval)
    665  1.49      manu 	struct lwp *l;
    666  1.49      manu 	void *v;
    667  1.49      manu 	register_t *retval;
    668  1.49      manu {
    669  1.49      manu 	struct linux_sys_tkill_args /* {
    670  1.49      manu 		syscallarg(int) tid;
    671  1.49      manu 		syscallarg(int) sig;
    672  1.49      manu 	} */ *uap = v;
    673  1.49      manu 	struct linux_sys_kill_args cup;
    674  1.49      manu 
    675  1.49      manu 	/* We use the PID as the TID ... */
    676  1.49      manu 	SCARG(&cup, pid) = SCARG(uap, tid);
    677  1.49      manu 	SCARG(&cup, signum) = SCARG(uap, sig);
    678  1.49      manu 
    679  1.49      manu 	return linux_sys_kill(l, &cup, retval);
    680  1.49      manu }
    681  1.49      manu 
    682  1.49      manu int
    683  1.49      manu linux_sys_tgkill(l, v, retval)
    684  1.49      manu 	struct lwp *l;
    685  1.49      manu 	void *v;
    686  1.49      manu 	register_t *retval;
    687  1.49      manu {
    688  1.49      manu 	struct linux_sys_tgkill_args /* {
    689  1.49      manu 		syscallarg(int) tgid;
    690  1.49      manu 		syscallarg(int) tid;
    691  1.49      manu 		syscallarg(int) sig;
    692  1.49      manu 	} */ *uap = v;
    693  1.49      manu 	struct linux_sys_kill_args cup;
    694  1.49      manu 	struct linux_emuldata *led;
    695  1.49      manu 	struct proc *p;
    696  1.49      manu 
    697  1.49      manu 	SCARG(&cup, pid) = SCARG(uap, tid);
    698  1.49      manu 	SCARG(&cup, signum) = SCARG(uap, sig);
    699  1.49      manu 
    700  1.49      manu 	if (SCARG(uap, tgid) == -1)
    701  1.49      manu 		return linux_sys_kill(l, &cup, retval);
    702  1.49      manu 
    703  1.49      manu 	/* We use the PID as the TID, but make sure the group ID is right */
    704  1.49      manu 	if ((p = pfind(SCARG(uap, tid))) == NULL)
    705  1.49      manu 		return ESRCH;
    706  1.49      manu 
    707  1.49      manu 	if (p->p_emul != &emul_linux)
    708  1.49      manu 		return ESRCH;
    709  1.49      manu 
    710  1.49      manu 	led = p->p_emuldata;
    711  1.49      manu 
    712  1.49      manu 	if (led->s->group_pid != SCARG(uap, tgid))
    713  1.49      manu 		return ESRCH;
    714  1.49      manu 
    715  1.49      manu 	return linux_sys_kill(l, &cup, retval);
    716  1.49      manu }
    717  1.49      manu #endif /* LINUX_NPTL */
    718