Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.33
      1  1.33  christos /*	$NetBSD: linux_signal.c,v 1.33 2002/02/15 16:48:03 christos 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.33  christos __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.33 2002/02/15 16:48:03 christos 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.1      fvdl #include <sys/syscallargs.h>
     74   1.1      fvdl 
     75  1.15  christos #include <compat/linux/common/linux_types.h>
     76  1.15  christos #include <compat/linux/common/linux_signal.h>
     77  1.17       erh #include <compat/linux/common/linux_siginfo.h>
     78  1.15  christos #include <compat/linux/common/linux_util.h>
     79  1.15  christos 
     80   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     81   1.1      fvdl 
     82  1.14       erh /* Locally used defines (in bsd<->linux conversion functions): */
     83  1.11     perry #define	linux_sigemptyset(s)	memset((s), 0, sizeof(*(s)))
     84  1.20     itohy #define	linux_sigismember(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     85  1.20     itohy 					& (1 << ((n) - 1) % LINUX__NSIG_BPW))
     86  1.20     itohy #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     87  1.20     itohy 					|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
     88   1.6   mycroft 
     89  1.14       erh /* Note: linux_to_native_sig[] is in <arch>/linux_sigarray.c */
     90  1.31  jdolecek const int native_to_linux_sig[NSIG] = {
     91   1.6   mycroft 	0,
     92   1.6   mycroft 	LINUX_SIGHUP,
     93   1.6   mycroft 	LINUX_SIGINT,
     94   1.6   mycroft 	LINUX_SIGQUIT,
     95   1.6   mycroft 	LINUX_SIGILL,
     96   1.6   mycroft 	LINUX_SIGTRAP,
     97   1.6   mycroft 	LINUX_SIGABRT,
     98  1.12   mycroft 	0,			/* SIGEMT */
     99   1.6   mycroft 	LINUX_SIGFPE,
    100   1.6   mycroft 	LINUX_SIGKILL,
    101   1.6   mycroft 	LINUX_SIGBUS,
    102   1.6   mycroft 	LINUX_SIGSEGV,
    103  1.23      tron 	0,			/* SIGSYS */
    104   1.6   mycroft 	LINUX_SIGPIPE,
    105   1.6   mycroft 	LINUX_SIGALRM,
    106   1.6   mycroft 	LINUX_SIGTERM,
    107   1.6   mycroft 	LINUX_SIGURG,
    108   1.6   mycroft 	LINUX_SIGSTOP,
    109   1.6   mycroft 	LINUX_SIGTSTP,
    110   1.6   mycroft 	LINUX_SIGCONT,
    111   1.6   mycroft 	LINUX_SIGCHLD,
    112   1.6   mycroft 	LINUX_SIGTTIN,
    113   1.6   mycroft 	LINUX_SIGTTOU,
    114   1.6   mycroft 	LINUX_SIGIO,
    115   1.6   mycroft 	LINUX_SIGXCPU,
    116   1.6   mycroft 	LINUX_SIGXFSZ,
    117   1.6   mycroft 	LINUX_SIGVTALRM,
    118   1.6   mycroft 	LINUX_SIGPROF,
    119   1.6   mycroft 	LINUX_SIGWINCH,
    120  1.12   mycroft 	0,			/* SIGINFO */
    121   1.6   mycroft 	LINUX_SIGUSR1,
    122   1.6   mycroft 	LINUX_SIGUSR2,
    123  1.12   mycroft 	LINUX_SIGPWR,
    124   1.6   mycroft };
    125   1.6   mycroft 
    126  1.14       erh /*
    127  1.20     itohy  * Convert between Linux and BSD signal sets.
    128  1.14       erh  */
    129  1.20     itohy #if LINUX__NSIG_WORDS > 1
    130   1.6   mycroft void
    131  1.33  christos linux_old_extra_to_native_sigset(bss, lss, extra)
    132  1.33  christos 	sigset_t *bss;
    133  1.14       erh 	const linux_old_sigset_t *lss;
    134  1.20     itohy 	const unsigned long *extra;
    135  1.20     itohy {
    136  1.20     itohy 	linux_sigset_t lsnew;
    137  1.20     itohy 
    138  1.20     itohy 	/* convert old sigset to new sigset */
    139  1.20     itohy 	linux_sigemptyset(&lsnew);
    140  1.20     itohy 	lsnew.sig[0] = *lss;
    141  1.20     itohy 	if (extra)
    142  1.33  christos 		memcpy(&lsnew.sig[1], extra,
    143  1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    144  1.20     itohy 
    145  1.33  christos 	linux_to_native_sigset(bss, &lsnew);
    146  1.20     itohy }
    147  1.20     itohy 
    148  1.20     itohy void
    149  1.33  christos native_to_linux_old_extra_sigset(lss, extra, bss)
    150  1.20     itohy 	linux_old_sigset_t *lss;
    151  1.20     itohy 	unsigned long *extra;
    152  1.33  christos 	const sigset_t *bss;
    153  1.20     itohy {
    154  1.20     itohy 	linux_sigset_t lsnew;
    155  1.20     itohy 
    156  1.33  christos 	native_to_linux_sigset(&lsnew, bss);
    157  1.20     itohy 
    158  1.20     itohy 	/* convert new sigset to old sigset */
    159  1.20     itohy 	*lss = lsnew.sig[0];
    160  1.20     itohy 	if (extra)
    161  1.33  christos 		memcpy(extra, &lsnew.sig[1],
    162  1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    163  1.20     itohy }
    164  1.20     itohy #endif
    165  1.20     itohy 
    166  1.20     itohy void
    167  1.33  christos linux_to_native_sigset(bss, lss)
    168  1.33  christos 	sigset_t *bss;
    169  1.20     itohy 	const linux_sigset_t *lss;
    170   1.1      fvdl {
    171   1.1      fvdl 	int i, newsig;
    172   1.1      fvdl 
    173   1.6   mycroft 	sigemptyset(bss);
    174  1.20     itohy 	for (i = 1; i < LINUX__NSIG; i++) {
    175   1.6   mycroft 		if (linux_sigismember(lss, i)) {
    176  1.12   mycroft 			newsig = linux_to_native_sig[i];
    177   1.1      fvdl 			if (newsig)
    178   1.6   mycroft 				sigaddset(bss, newsig);
    179   1.1      fvdl 		}
    180   1.1      fvdl 	}
    181   1.1      fvdl }
    182   1.1      fvdl 
    183   1.1      fvdl void
    184  1.33  christos native_to_linux_sigset(lss, bss)
    185  1.33  christos 	linux_sigset_t *lss;
    186   1.1      fvdl 	const sigset_t *bss;
    187   1.1      fvdl {
    188   1.1      fvdl 	int i, newsig;
    189  1.20     itohy 
    190   1.6   mycroft 	linux_sigemptyset(lss);
    191   1.6   mycroft 	for (i = 1; i < NSIG; i++) {
    192   1.6   mycroft 		if (sigismember(bss, i)) {
    193  1.12   mycroft 			newsig = native_to_linux_sig[i];
    194   1.1      fvdl 			if (newsig)
    195   1.6   mycroft 				linux_sigaddset(lss, newsig);
    196   1.1      fvdl 		}
    197   1.1      fvdl 	}
    198   1.1      fvdl }
    199   1.1      fvdl 
    200  1.33  christos void
    201  1.33  christos native_to_linux_sigflags(lsf, bsf)
    202  1.33  christos 	unsigned long *lsf;
    203  1.33  christos 	const int *bsf;
    204  1.33  christos {
    205  1.33  christos 	*lsf = 0;
    206  1.33  christos 	if ((*bsf & SA_NOCLDSTOP) != 0)
    207  1.33  christos 		*lsf |= LINUX_SA_NOCLDSTOP;
    208  1.33  christos 	if ((*bsf & SA_NOCLDWAIT) != 0)
    209  1.33  christos 		*lsf |= LINUX_SA_NOCLDWAIT;
    210  1.33  christos 	if ((*bsf & SA_ONSTACK) != 0)
    211  1.33  christos 		*lsf |= LINUX_SA_ONSTACK;
    212  1.33  christos 	if ((*bsf & SA_RESTART) != 0)
    213  1.33  christos 		*lsf |= LINUX_SA_RESTART;
    214  1.33  christos 	if ((*bsf & SA_NODEFER) != 0)
    215  1.33  christos 		*lsf |= LINUX_SA_NOMASK;
    216  1.33  christos 	if ((*bsf & SA_RESETHAND) != 0)
    217  1.33  christos 		*lsf |= LINUX_SA_ONESHOT;
    218  1.33  christos 	if ((*bsf & SA_SIGINFO) != 0)
    219  1.33  christos 		*lsf |= LINUX_SA_SIGINFO;
    220  1.33  christos }
    221  1.33  christos 
    222  1.33  christos void
    223  1.33  christos linux_to_native_sigflags(bsf, lsf)
    224  1.33  christos 	int *bsf;
    225  1.33  christos 	const unsigned long *lsf;
    226  1.33  christos {
    227  1.33  christos 	*bsf = 0;
    228  1.33  christos 	if ((*lsf & LINUX_SA_NOCLDSTOP) != 0)
    229  1.33  christos 		*bsf |= SA_NOCLDSTOP;
    230  1.33  christos 	if ((*lsf & LINUX_SA_NOCLDWAIT) != 0)
    231  1.33  christos 		*bsf |= SA_NOCLDWAIT;
    232  1.33  christos 	if ((*lsf & LINUX_SA_ONSTACK) != 0)
    233  1.33  christos 		*bsf |= SA_ONSTACK;
    234  1.33  christos 	if ((*lsf & LINUX_SA_RESTART) != 0)
    235  1.33  christos 		*bsf |= SA_RESTART;
    236  1.33  christos 	if ((*lsf & LINUX_SA_ONESHOT) != 0)
    237  1.33  christos 		*bsf |= SA_RESETHAND;
    238  1.33  christos 	if ((*lsf & LINUX_SA_NOMASK) != 0)
    239  1.33  christos 		*bsf |= SA_NODEFER;
    240  1.33  christos 	if ((*lsf & LINUX_SA_SIGINFO) != 0)
    241  1.33  christos 		*bsf |= SA_SIGINFO;
    242  1.33  christos #ifdef DEBUG_LINUX
    243  1.33  christos 	if ((*lsf & ~LINUX_SA_ALLBITS) != 0)
    244  1.33  christos 		uprintf(
    245  1.33  christos 		    "linux_old_to_native_sigflags: %lx extra bits ignored\n",
    246  1.33  christos 		    *lsf);
    247  1.33  christos #endif
    248  1.33  christos }
    249  1.33  christos 
    250   1.1      fvdl /*
    251  1.14       erh  * Convert between Linux and BSD sigaction structures. Linux sometimes
    252  1.14       erh  * has one extra field (sa_restorer) which we don't support.
    253   1.1      fvdl  */
    254   1.1      fvdl void
    255  1.33  christos linux_old_to_native_sigaction(bsa, lsa)
    256  1.14       erh 	struct sigaction *bsa;
    257  1.33  christos 	const struct linux_old_sigaction *lsa;
    258  1.14       erh {
    259  1.14       erh 	bsa->sa_handler = lsa->sa_handler;
    260  1.33  christos 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    261  1.33  christos 	linux_to_native_sigflags(&bsa->sa_flags, &lsa->sa_mask);
    262  1.22  jdolecek #ifdef DEBUG_LINUX
    263  1.33  christos 	if (lsa->sa_restorer != NULL)
    264  1.33  christos 		uprintf("linux_old_to_native_sigaction: sa_restorer ignored\n");
    265  1.14       erh #endif
    266  1.14       erh }
    267  1.14       erh 
    268  1.14       erh void
    269  1.33  christos native_to_linux_old_sigaction(lsa, bsa)
    270  1.14       erh 	struct linux_old_sigaction *lsa;
    271  1.33  christos 	const struct sigaction *bsa;
    272  1.14       erh {
    273  1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    274  1.33  christos 	native_to_linux_old_sigset(&lsa->sa_mask, &bsa->sa_mask);
    275  1.33  christos 	native_to_linux_sigflags(&lsa->sa_flags, &bsa->sa_flags);
    276  1.33  christos 	lsa->sa_restorer = NULL;
    277  1.14       erh }
    278  1.14       erh 
    279  1.14       erh /* ...and the new sigaction conversion funcs. */
    280  1.14       erh void
    281  1.33  christos linux_to_native_sigaction(bsa, lsa)
    282   1.1      fvdl 	struct sigaction *bsa;
    283  1.33  christos 	const struct linux_sigaction *lsa;
    284   1.1      fvdl {
    285   1.1      fvdl 	bsa->sa_handler = lsa->sa_handler;
    286  1.33  christos 	linux_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    287  1.33  christos 	linux_to_native_sigflags(&bsa->sa_flags, &lsa->sa_flags);
    288  1.22  jdolecek #ifdef DEBUG_LINUX
    289  1.12   mycroft 	if (lsa->sa_restorer != 0)
    290  1.33  christos 		uprintf("linux_to_native_sigaction: sa_restorer ignored\n");
    291  1.13        tv #endif
    292   1.1      fvdl }
    293   1.1      fvdl 
    294   1.1      fvdl void
    295  1.33  christos native_to_linux_sigaction(lsa, bsa)
    296   1.1      fvdl 	struct linux_sigaction *lsa;
    297  1.33  christos 	const struct sigaction *bsa;
    298   1.1      fvdl {
    299  1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    300  1.33  christos 	native_to_linux_sigset(&lsa->sa_mask, &bsa->sa_mask);
    301  1.33  christos 	native_to_linux_sigflags(&lsa->sa_flags, &bsa->sa_flags);
    302  1.33  christos 	lsa->sa_restorer = NULL;
    303   1.1      fvdl }
    304   1.1      fvdl 
    305  1.14       erh /* ----------------------------------------------------------------------- */
    306   1.1      fvdl 
    307   1.1      fvdl /*
    308   1.1      fvdl  * The Linux sigaction() system call. Do the usual conversions,
    309   1.1      fvdl  * and just call sigaction(). Some flags and values are silently
    310   1.1      fvdl  * ignored (see above).
    311   1.1      fvdl  */
    312   1.1      fvdl int
    313  1.14       erh linux_sys_rt_sigaction(p, v, retval)
    314  1.26  augustss 	struct proc *p;
    315   1.8   thorpej 	void *v;
    316   1.8   thorpej 	register_t *retval;
    317   1.8   thorpej {
    318  1.14       erh 	struct linux_sys_rt_sigaction_args /* {
    319   1.1      fvdl 		syscallarg(int) signum;
    320  1.12   mycroft 		syscallarg(const struct linux_sigaction *) nsa;
    321   1.1      fvdl 		syscallarg(struct linux_sigaction *) osa;
    322  1.14       erh 		syscallarg(size_t) sigsetsize;
    323   1.8   thorpej 	} */ *uap = v;
    324  1.12   mycroft 	struct linux_sigaction nlsa, olsa;
    325  1.12   mycroft 	struct sigaction nbsa, obsa;
    326  1.25      tron 	int error, sig;
    327   1.1      fvdl 
    328  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    329  1.14       erh 		return (EINVAL);
    330  1.14       erh 
    331  1.12   mycroft 	if (SCARG(uap, nsa)) {
    332  1.12   mycroft 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    333  1.12   mycroft 		if (error)
    334  1.12   mycroft 			return (error);
    335  1.33  christos 		linux_to_native_sigaction(&nbsa, &nlsa);
    336  1.12   mycroft 	}
    337  1.25      tron 	sig = SCARG(uap, signum);
    338  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    339  1.25      tron 		return (EINVAL);
    340  1.29        tv 	if (sig > 0 && !linux_to_native_sig[sig]) {
    341  1.29        tv 		/* Pretend that we did something useful for unknown signals. */
    342  1.29        tv 		obsa.sa_handler = SIG_IGN;
    343  1.29        tv 		sigemptyset(&obsa.sa_mask);
    344  1.29        tv 		obsa.sa_flags = 0;
    345  1.29        tv 	} else {
    346  1.29        tv 		error = sigaction1(p, linux_to_native_sig[sig],
    347  1.29        tv 		    SCARG(uap, nsa) ? &nbsa : NULL, SCARG(uap, osa) ? &obsa : NULL);
    348  1.29        tv 		if (error)
    349  1.29        tv 			return (error);
    350  1.29        tv 	}
    351  1.12   mycroft 	if (SCARG(uap, osa)) {
    352  1.33  christos 		native_to_linux_sigaction(&olsa, &obsa);
    353  1.12   mycroft 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    354  1.12   mycroft 		if (error)
    355  1.12   mycroft 			return (error);
    356   1.1      fvdl 	}
    357  1.12   mycroft 	return (0);
    358   1.1      fvdl }
    359   1.1      fvdl 
    360   1.1      fvdl int
    361  1.17       erh linux_sigprocmask1(p, how, set, oset)
    362  1.26  augustss 	struct proc *p;
    363  1.17       erh 	int how;
    364  1.17       erh 	const linux_old_sigset_t *set;
    365  1.17       erh 	linux_old_sigset_t *oset;
    366   1.8   thorpej {
    367  1.14       erh 	linux_old_sigset_t nlss, olss;
    368  1.12   mycroft 	sigset_t nbss, obss;
    369  1.12   mycroft 	int error;
    370   1.1      fvdl 
    371  1.17       erh 	switch (how) {
    372   1.1      fvdl 	case LINUX_SIG_BLOCK:
    373  1.12   mycroft 		how = SIG_BLOCK;
    374   1.1      fvdl 		break;
    375   1.1      fvdl 	case LINUX_SIG_UNBLOCK:
    376  1.12   mycroft 		how = SIG_UNBLOCK;
    377   1.1      fvdl 		break;
    378   1.1      fvdl 	case LINUX_SIG_SETMASK:
    379  1.12   mycroft 		how = SIG_SETMASK;
    380   1.1      fvdl 		break;
    381   1.1      fvdl 	default:
    382  1.12   mycroft 		return (EINVAL);
    383   1.1      fvdl 	}
    384   1.1      fvdl 
    385  1.17       erh 	if (set) {
    386  1.17       erh 		error = copyin(set, &nlss, sizeof(nlss));
    387  1.12   mycroft 		if (error)
    388  1.12   mycroft 			return (error);
    389  1.33  christos 		linux_old_to_native_sigset(&nbss, &nlss);
    390  1.12   mycroft 	}
    391  1.12   mycroft 	error = sigprocmask1(p, how,
    392  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    393  1.12   mycroft 	if (error)
    394  1.12   mycroft 		return (error);
    395  1.17       erh 	if (oset) {
    396  1.33  christos 		native_to_linux_old_sigset(&olss, &obss);
    397  1.17       erh 		error = copyout(&olss, oset, sizeof(olss));
    398  1.12   mycroft 		if (error)
    399  1.12   mycroft 			return (error);
    400  1.12   mycroft 	}
    401  1.12   mycroft 	return (error);
    402  1.17       erh }
    403  1.17       erh 
    404  1.17       erh int
    405  1.17       erh linux_sys_rt_sigprocmask(p, v, retval)
    406  1.26  augustss 	struct proc *p;
    407  1.17       erh 	void *v;
    408  1.17       erh 	register_t *retval;
    409  1.17       erh {
    410  1.17       erh 	struct linux_sys_rt_sigprocmask_args /* {
    411  1.17       erh 		syscallarg(int) how;
    412  1.17       erh 		syscallarg(const linux_sigset_t *) set;
    413  1.17       erh 		syscallarg(linux_sigset_t *) oset;
    414  1.17       erh 		syscallarg(size_t) sigsetsize;
    415  1.17       erh 	} */ *uap = v;
    416  1.17       erh 
    417  1.24      fvdl 	linux_sigset_t nlss, olss, *oset;
    418  1.24      fvdl 	const linux_sigset_t *set;
    419  1.24      fvdl 	sigset_t nbss, obss;
    420  1.24      fvdl 	int error, how;
    421  1.24      fvdl 
    422  1.24      fvdl 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    423  1.24      fvdl 		return (EINVAL);
    424  1.24      fvdl 
    425  1.24      fvdl 	switch (SCARG(uap, how)) {
    426  1.24      fvdl 	case LINUX_SIG_BLOCK:
    427  1.24      fvdl 		how = SIG_BLOCK;
    428  1.24      fvdl 		break;
    429  1.24      fvdl 	case LINUX_SIG_UNBLOCK:
    430  1.24      fvdl 		how = SIG_UNBLOCK;
    431  1.24      fvdl 		break;
    432  1.24      fvdl 	case LINUX_SIG_SETMASK:
    433  1.24      fvdl 		how = SIG_SETMASK;
    434  1.24      fvdl 		break;
    435  1.24      fvdl 	default:
    436  1.24      fvdl 		return (EINVAL);
    437  1.17       erh 	}
    438  1.17       erh 
    439  1.24      fvdl 	set = SCARG(uap, set);
    440  1.24      fvdl 	oset = SCARG(uap, oset);
    441  1.24      fvdl 
    442  1.24      fvdl 	if (set) {
    443  1.24      fvdl 		error = copyin(set, &nlss, sizeof(nlss));
    444  1.24      fvdl 		if (error)
    445  1.24      fvdl 			return (error);
    446  1.33  christos 		linux_to_native_sigset(&nbss, &nlss);
    447  1.24      fvdl 	}
    448  1.24      fvdl 	error = sigprocmask1(p, how,
    449  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    450  1.28      tron 	if (!error && oset) {
    451  1.33  christos 		native_to_linux_sigset(&olss, &obss);
    452  1.24      fvdl 		error = copyout(&olss, oset, sizeof(olss));
    453  1.24      fvdl 	}
    454  1.24      fvdl 	return (error);
    455   1.1      fvdl }
    456   1.1      fvdl 
    457   1.1      fvdl int
    458  1.14       erh linux_sys_rt_sigpending(p, v, retval)
    459  1.26  augustss 	struct proc *p;
    460   1.9   mycroft 	void *v;
    461   1.1      fvdl 	register_t *retval;
    462   1.1      fvdl {
    463  1.14       erh 	struct linux_sys_rt_sigpending_args /* {
    464  1.14       erh 		syscallarg(linux_sigset_t *) set;
    465  1.14       erh 		syscallarg(size_t) sigsetsize;
    466  1.14       erh 	} */ *uap = v;
    467  1.12   mycroft 	sigset_t bss;
    468  1.12   mycroft 	linux_sigset_t lss;
    469   1.6   mycroft 
    470  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    471  1.14       erh 		return (EINVAL);
    472  1.14       erh 
    473  1.14       erh 	sigpending1(p, &bss);
    474  1.33  christos 	native_to_linux_sigset(&lss, &bss);
    475  1.14       erh 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    476   1.1      fvdl }
    477  1.24      fvdl 
    478   1.1      fvdl int
    479   1.9   mycroft linux_sys_sigpending(p, v, retval)
    480  1.26  augustss 	struct proc *p;
    481   1.8   thorpej 	void *v;
    482   1.8   thorpej 	register_t *retval;
    483   1.8   thorpej {
    484   1.9   mycroft 	struct linux_sys_sigpending_args /* {
    485  1.14       erh 		syscallarg(linux_old_sigset_t *) mask;
    486   1.8   thorpej 	} */ *uap = v;
    487  1.12   mycroft 	sigset_t bss;
    488  1.14       erh 	linux_old_sigset_t lss;
    489   1.1      fvdl 
    490  1.12   mycroft 	sigpending1(p, &bss);
    491  1.33  christos 	native_to_linux_old_sigset(&lss, &bss);
    492  1.12   mycroft 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    493   1.1      fvdl }
    494   1.1      fvdl 
    495   1.1      fvdl int
    496   1.9   mycroft linux_sys_sigsuspend(p, v, retval)
    497  1.26  augustss 	struct proc *p;
    498   1.8   thorpej 	void *v;
    499   1.8   thorpej 	register_t *retval;
    500   1.8   thorpej {
    501   1.9   mycroft 	struct linux_sys_sigsuspend_args /* {
    502   1.3      fvdl 		syscallarg(caddr_t) restart;
    503   1.3      fvdl 		syscallarg(int) oldmask;
    504   1.1      fvdl 		syscallarg(int) mask;
    505   1.8   thorpej 	} */ *uap = v;
    506  1.14       erh 	linux_old_sigset_t lss;
    507  1.14       erh 	sigset_t bss;
    508  1.14       erh 
    509  1.14       erh 	lss = SCARG(uap, mask);
    510  1.33  christos 	linux_old_to_native_sigset(&bss, &lss);
    511  1.14       erh 	return (sigsuspend1(p, &bss));
    512  1.14       erh }
    513  1.14       erh int
    514  1.14       erh linux_sys_rt_sigsuspend(p, v, retval)
    515  1.26  augustss 	struct proc *p;
    516  1.14       erh 	void *v;
    517  1.14       erh 	register_t *retval;
    518  1.14       erh {
    519  1.14       erh 	struct linux_sys_rt_sigsuspend_args /* {
    520  1.14       erh 		syscallarg(linux_sigset_t *) unewset;
    521  1.14       erh 		syscallarg(size_t) sigsetsize;
    522  1.14       erh 	} */ *uap = v;
    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.14       erh linux_sys_rt_queueinfo(p, v, retval)
    545  1.26  augustss 	struct proc *p;
    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.14       erh 	return (linux_sys_kill(p, v, retval));
    561   1.1      fvdl }
    562   1.1      fvdl 
    563   1.1      fvdl int
    564   1.9   mycroft linux_sys_kill(p, v, retval)
    565  1.26  augustss 	struct proc *p;
    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.9   mycroft 	struct sys_kill_args ka;
    574  1.25      tron 	int sig;
    575   1.6   mycroft 
    576   1.6   mycroft 	SCARG(&ka, pid) = SCARG(uap, pid);
    577  1.25      tron 	sig = SCARG(uap, signum);
    578  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    579  1.25      tron 		return (EINVAL);
    580  1.25      tron 	SCARG(&ka, signum) = linux_to_native_sig[sig];
    581   1.9   mycroft 	return sys_kill(p, &ka, retval);
    582   1.1      fvdl }
    583  1.30  christos 
    584  1.30  christos #ifdef LINUX_SS_ONSTACK
    585  1.30  christos static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    586  1.30  christos     const struct linux_sigaltstack *));
    587  1.30  christos static void native_to_linux_sigaltstack __P((struct linux_sigaltstack *,
    588  1.30  christos     const struct sigaltstack *));
    589  1.30  christos 
    590  1.30  christos static void
    591  1.30  christos linux_to_native_sigaltstack(bss, lss)
    592  1.30  christos 	struct sigaltstack *bss;
    593  1.30  christos 	const struct linux_sigaltstack *lss;
    594  1.30  christos {
    595  1.30  christos 	bss->ss_sp = lss->ss_sp;
    596  1.30  christos 	bss->ss_size = lss->ss_size;
    597  1.30  christos 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    598  1.30  christos 	    bss->ss_flags = SS_ONSTACK;
    599  1.30  christos 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    600  1.30  christos 	    bss->ss_flags = SS_DISABLE;
    601  1.30  christos 	else
    602  1.30  christos 	    bss->ss_flags = 0;
    603  1.30  christos }
    604  1.30  christos 
    605  1.30  christos static void
    606  1.30  christos native_to_linux_sigaltstack(lss, bss)
    607  1.30  christos 	struct linux_sigaltstack *lss;
    608  1.30  christos 	const struct sigaltstack *bss;
    609  1.30  christos {
    610  1.30  christos 	lss->ss_sp = bss->ss_sp;
    611  1.30  christos 	lss->ss_size = bss->ss_size;
    612  1.30  christos 	if (bss->ss_flags & SS_ONSTACK)
    613  1.30  christos 	    lss->ss_flags = LINUX_SS_ONSTACK;
    614  1.30  christos 	else if (bss->ss_flags & SS_DISABLE)
    615  1.30  christos 	    lss->ss_flags = LINUX_SS_DISABLE;
    616  1.30  christos 	else
    617  1.30  christos 	    lss->ss_flags = 0;
    618  1.30  christos }
    619  1.30  christos 
    620  1.30  christos int
    621  1.30  christos linux_sys_sigaltstack(p, v, retval)
    622  1.30  christos 	struct proc *p;
    623  1.30  christos 	void *v;
    624  1.30  christos 	register_t *retval;
    625  1.30  christos {
    626  1.30  christos 	struct linux_sys_sigaltstack_args /* {
    627  1.30  christos 		syscallarg(const struct linux_sigaltstack *) ss;
    628  1.30  christos 		syscallarg(struct linux_sigaltstack *) oss;
    629  1.30  christos 	} */ *uap = v;
    630  1.30  christos 	struct linux_sigaltstack ss;
    631  1.30  christos 	struct sigaltstack nss, oss;
    632  1.30  christos 	int error;
    633  1.30  christos 
    634  1.30  christos 	if (SCARG(uap, ss) != NULL) {
    635  1.30  christos 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    636  1.30  christos 			return error;
    637  1.30  christos 		linux_to_native_sigaltstack(&nss, &ss);
    638  1.30  christos 	}
    639  1.30  christos 
    640  1.30  christos 	error = sigaltstack1(p,
    641  1.30  christos 	    SCARG(uap, ss) ? &nss : NULL, SCARG(uap, oss) ? &oss : NULL);
    642  1.30  christos 	if (error)
    643  1.30  christos 		return error;
    644  1.30  christos 
    645  1.30  christos 	if (SCARG(uap, oss) != NULL) {
    646  1.30  christos 		native_to_linux_sigaltstack(&ss, &oss);
    647  1.30  christos 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    648  1.30  christos 			return error;
    649  1.30  christos 	}
    650  1.30  christos 	return 0;
    651  1.30  christos }
    652  1.30  christos #endif
    653