Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.36
      1  1.36  christos /*	$NetBSD: linux_signal.c,v 1.36 2002/03/22 17:14:19 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.36  christos __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.36 2002/03/22 17:14:19 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.36  christos #ifdef DEBUG_LINUX
     90  1.36  christos #define DPRINTF(a)	uprintf a
     91  1.36  christos #else
     92  1.36  christos #define DPRINTF(a)
     93  1.36  christos #endif
     94  1.36  christos 
     95  1.35  christos #ifndef LINUX_SIGINFO
     96  1.35  christos #define LINUX_SIGINFO	0
     97  1.35  christos #endif
     98  1.35  christos #ifndef LINUX_SIGEMT
     99  1.35  christos #define LINUX_SIGEMT	0
    100  1.35  christos #endif
    101  1.14       erh /* Note: linux_to_native_sig[] is in <arch>/linux_sigarray.c */
    102  1.35  christos const int native_to_linux_sig[] = {
    103  1.35  christos 	0,			/* 0 */
    104  1.35  christos 	LINUX_SIGHUP,		/* 1 */
    105  1.35  christos 	LINUX_SIGINT,		/* 2 */
    106  1.35  christos 	LINUX_SIGQUIT,		/* 3 */
    107  1.35  christos 	LINUX_SIGILL,		/* 4 */
    108  1.35  christos 	LINUX_SIGTRAP,		/* 5 */
    109  1.35  christos 	LINUX_SIGABRT,		/* 6 */
    110  1.35  christos 	LINUX_SIGEMT,		/* 7 */
    111  1.35  christos 	LINUX_SIGFPE,		/* 8 */
    112  1.35  christos 	LINUX_SIGKILL,		/* 9 */
    113  1.35  christos 	LINUX_SIGBUS,		/* 10 */
    114  1.35  christos 	LINUX_SIGSEGV,		/* 11 */
    115  1.35  christos 	LINUX_SIGSYS,		/* 12 */
    116  1.35  christos 	LINUX_SIGPIPE,		/* 13 */
    117  1.35  christos 	LINUX_SIGALRM,		/* 14 */
    118  1.35  christos 	LINUX_SIGTERM,		/* 15 */
    119  1.35  christos 	LINUX_SIGURG,		/* 16 */
    120  1.35  christos 	LINUX_SIGSTOP,		/* 17 */
    121  1.35  christos 	LINUX_SIGTSTP,		/* 18 */
    122  1.35  christos 	LINUX_SIGCONT,		/* 19 */
    123  1.35  christos 	LINUX_SIGCHLD,		/* 20 */
    124  1.35  christos 	LINUX_SIGTTIN,		/* 21 */
    125  1.35  christos 	LINUX_SIGTTOU,		/* 22 */
    126  1.35  christos 	LINUX_SIGIO,		/* 23 */
    127  1.35  christos 	LINUX_SIGXCPU,		/* 24 */
    128  1.35  christos 	LINUX_SIGXFSZ,		/* 25 */
    129  1.35  christos 	LINUX_SIGVTALRM,	/* 26 */
    130  1.35  christos 	LINUX_SIGPROF,		/* 27 */
    131  1.35  christos 	LINUX_SIGWINCH,		/* 28 */
    132  1.35  christos 	LINUX_SIGINFO,		/* 29 */
    133  1.35  christos 	LINUX_SIGUSR1,		/* 30 */
    134  1.35  christos 	LINUX_SIGUSR2,		/* 31 */
    135  1.35  christos 	LINUX_SIGPWR,		/* 32 */
    136  1.35  christos 	LINUX_SIGRTMIN + 0,	/* 33 */
    137  1.35  christos 	LINUX_SIGRTMIN + 1,	/* 34 */
    138  1.35  christos 	LINUX_SIGRTMIN + 2,	/* 35 */
    139  1.35  christos 	LINUX_SIGRTMIN + 3,	/* 36 */
    140  1.35  christos 	LINUX_SIGRTMIN + 4,	/* 37 */
    141  1.35  christos 	LINUX_SIGRTMIN + 5,	/* 38 */
    142  1.35  christos 	LINUX_SIGRTMIN + 6,	/* 39 */
    143  1.35  christos 	LINUX_SIGRTMIN + 7,	/* 40 */
    144  1.35  christos 	LINUX_SIGRTMIN + 8,	/* 41 */
    145  1.35  christos 	LINUX_SIGRTMIN + 9,	/* 42 */
    146  1.35  christos 	LINUX_SIGRTMIN + 10,	/* 43 */
    147  1.35  christos 	LINUX_SIGRTMIN + 11,	/* 44 */
    148  1.35  christos 	LINUX_SIGRTMIN + 12,	/* 45 */
    149  1.35  christos 	LINUX_SIGRTMIN + 13,	/* 46 */
    150  1.35  christos 	LINUX_SIGRTMIN + 14,	/* 47 */
    151  1.35  christos 	LINUX_SIGRTMIN + 15,	/* 48 */
    152  1.35  christos 	LINUX_SIGRTMIN + 16,	/* 49 */
    153  1.35  christos 	LINUX_SIGRTMIN + 17,	/* 50 */
    154  1.35  christos 	LINUX_SIGRTMIN + 18,	/* 51 */
    155  1.35  christos 	LINUX_SIGRTMIN + 19,	/* 52 */
    156  1.35  christos 	LINUX_SIGRTMIN + 20,	/* 53 */
    157  1.35  christos 	LINUX_SIGRTMIN + 21,	/* 54 */
    158  1.35  christos 	LINUX_SIGRTMIN + 22,	/* 55 */
    159  1.35  christos 	LINUX_SIGRTMIN + 23,	/* 56 */
    160  1.35  christos 	LINUX_SIGRTMIN + 24,	/* 57 */
    161  1.35  christos 	LINUX_SIGRTMIN + 25,	/* 58 */
    162  1.35  christos 	LINUX_SIGRTMIN + 26,	/* 59 */
    163  1.35  christos 	LINUX_SIGRTMIN + 27,	/* 60 */
    164  1.35  christos 	LINUX_SIGRTMIN + 28,	/* 61 */
    165  1.35  christos 	LINUX_SIGRTMIN + 29,	/* 62 */
    166  1.35  christos 	LINUX_SIGRTMIN + 30,	/* 63 */
    167  1.35  christos 
    168   1.6   mycroft };
    169   1.6   mycroft 
    170  1.14       erh /*
    171  1.20     itohy  * Convert between Linux and BSD signal sets.
    172  1.14       erh  */
    173  1.20     itohy #if LINUX__NSIG_WORDS > 1
    174   1.6   mycroft void
    175  1.33  christos linux_old_extra_to_native_sigset(bss, lss, extra)
    176  1.33  christos 	sigset_t *bss;
    177  1.14       erh 	const linux_old_sigset_t *lss;
    178  1.20     itohy 	const unsigned long *extra;
    179  1.20     itohy {
    180  1.20     itohy 	linux_sigset_t lsnew;
    181  1.20     itohy 
    182  1.20     itohy 	/* convert old sigset to new sigset */
    183  1.20     itohy 	linux_sigemptyset(&lsnew);
    184  1.20     itohy 	lsnew.sig[0] = *lss;
    185  1.20     itohy 	if (extra)
    186  1.33  christos 		memcpy(&lsnew.sig[1], extra,
    187  1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    188  1.20     itohy 
    189  1.33  christos 	linux_to_native_sigset(bss, &lsnew);
    190  1.20     itohy }
    191  1.20     itohy 
    192  1.20     itohy void
    193  1.33  christos native_to_linux_old_extra_sigset(lss, extra, bss)
    194  1.20     itohy 	linux_old_sigset_t *lss;
    195  1.20     itohy 	unsigned long *extra;
    196  1.33  christos 	const sigset_t *bss;
    197  1.20     itohy {
    198  1.20     itohy 	linux_sigset_t lsnew;
    199  1.20     itohy 
    200  1.33  christos 	native_to_linux_sigset(&lsnew, bss);
    201  1.20     itohy 
    202  1.20     itohy 	/* convert new sigset to old sigset */
    203  1.20     itohy 	*lss = lsnew.sig[0];
    204  1.20     itohy 	if (extra)
    205  1.33  christos 		memcpy(extra, &lsnew.sig[1],
    206  1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    207  1.20     itohy }
    208  1.20     itohy #endif
    209  1.20     itohy 
    210  1.20     itohy void
    211  1.33  christos linux_to_native_sigset(bss, lss)
    212  1.33  christos 	sigset_t *bss;
    213  1.20     itohy 	const linux_sigset_t *lss;
    214   1.1      fvdl {
    215   1.1      fvdl 	int i, newsig;
    216   1.1      fvdl 
    217   1.6   mycroft 	sigemptyset(bss);
    218  1.20     itohy 	for (i = 1; i < LINUX__NSIG; i++) {
    219   1.6   mycroft 		if (linux_sigismember(lss, i)) {
    220  1.12   mycroft 			newsig = linux_to_native_sig[i];
    221   1.1      fvdl 			if (newsig)
    222   1.6   mycroft 				sigaddset(bss, newsig);
    223   1.1      fvdl 		}
    224   1.1      fvdl 	}
    225   1.1      fvdl }
    226   1.1      fvdl 
    227   1.1      fvdl void
    228  1.33  christos native_to_linux_sigset(lss, bss)
    229  1.33  christos 	linux_sigset_t *lss;
    230   1.1      fvdl 	const sigset_t *bss;
    231   1.1      fvdl {
    232   1.1      fvdl 	int i, newsig;
    233  1.20     itohy 
    234   1.6   mycroft 	linux_sigemptyset(lss);
    235   1.6   mycroft 	for (i = 1; i < NSIG; i++) {
    236   1.6   mycroft 		if (sigismember(bss, i)) {
    237  1.12   mycroft 			newsig = native_to_linux_sig[i];
    238   1.1      fvdl 			if (newsig)
    239   1.6   mycroft 				linux_sigaddset(lss, newsig);
    240   1.1      fvdl 		}
    241   1.1      fvdl 	}
    242   1.1      fvdl }
    243   1.1      fvdl 
    244  1.34  christos unsigned int
    245  1.34  christos native_to_linux_sigflags(bsf)
    246  1.34  christos 	const int bsf;
    247  1.33  christos {
    248  1.34  christos 	unsigned int lsf = 0;
    249  1.34  christos 	if ((bsf & SA_NOCLDSTOP) != 0)
    250  1.34  christos 		lsf |= LINUX_SA_NOCLDSTOP;
    251  1.34  christos 	if ((bsf & SA_NOCLDWAIT) != 0)
    252  1.34  christos 		lsf |= LINUX_SA_NOCLDWAIT;
    253  1.34  christos 	if ((bsf & SA_ONSTACK) != 0)
    254  1.34  christos 		lsf |= LINUX_SA_ONSTACK;
    255  1.34  christos 	if ((bsf & SA_RESTART) != 0)
    256  1.34  christos 		lsf |= LINUX_SA_RESTART;
    257  1.34  christos 	if ((bsf & SA_NODEFER) != 0)
    258  1.34  christos 		lsf |= LINUX_SA_NOMASK;
    259  1.34  christos 	if ((bsf & SA_RESETHAND) != 0)
    260  1.34  christos 		lsf |= LINUX_SA_ONESHOT;
    261  1.34  christos 	if ((bsf & SA_SIGINFO) != 0)
    262  1.34  christos 		lsf |= LINUX_SA_SIGINFO;
    263  1.34  christos 	return lsf;
    264  1.33  christos }
    265  1.33  christos 
    266  1.34  christos int
    267  1.34  christos linux_to_native_sigflags(lsf)
    268  1.34  christos 	const unsigned long lsf;
    269  1.33  christos {
    270  1.34  christos 	int bsf = 0;
    271  1.34  christos 	if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
    272  1.34  christos 		bsf |= SA_NOCLDSTOP;
    273  1.34  christos 	if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
    274  1.34  christos 		bsf |= SA_NOCLDWAIT;
    275  1.34  christos 	if ((lsf & LINUX_SA_ONSTACK) != 0)
    276  1.34  christos 		bsf |= SA_ONSTACK;
    277  1.34  christos 	if ((lsf & LINUX_SA_RESTART) != 0)
    278  1.34  christos 		bsf |= SA_RESTART;
    279  1.34  christos 	if ((lsf & LINUX_SA_ONESHOT) != 0)
    280  1.34  christos 		bsf |= SA_RESETHAND;
    281  1.34  christos 	if ((lsf & LINUX_SA_NOMASK) != 0)
    282  1.34  christos 		bsf |= SA_NODEFER;
    283  1.34  christos 	if ((lsf & LINUX_SA_SIGINFO) != 0)
    284  1.34  christos 		bsf |= SA_SIGINFO;
    285  1.34  christos 	if ((lsf & ~LINUX_SA_ALLBITS) != 0)
    286  1.36  christos 		DPRINTF(("linux_old_to_native_sigflags: "
    287  1.36  christos 		    "%lx extra bits ignored\n", lsf));
    288  1.34  christos 	return bsf;
    289  1.33  christos }
    290  1.33  christos 
    291   1.1      fvdl /*
    292  1.14       erh  * Convert between Linux and BSD sigaction structures. Linux sometimes
    293  1.14       erh  * has one extra field (sa_restorer) which we don't support.
    294   1.1      fvdl  */
    295   1.1      fvdl void
    296  1.33  christos linux_old_to_native_sigaction(bsa, lsa)
    297  1.14       erh 	struct sigaction *bsa;
    298  1.33  christos 	const struct linux_old_sigaction *lsa;
    299  1.14       erh {
    300  1.14       erh 	bsa->sa_handler = lsa->sa_handler;
    301  1.33  christos 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    302  1.34  christos 	bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
    303  1.34  christos #ifndef __alpha__
    304  1.34  christos /*
    305  1.34  christos  * XXX: On the alpha sa_restorer is elsewhere.
    306  1.34  christos  */
    307  1.33  christos 	if (lsa->sa_restorer != NULL)
    308  1.36  christos 		DPRINTF(("linux_old_to_native_sigaction: "
    309  1.36  christos 		    "sa_restorer ignored\n"));
    310  1.34  christos #endif
    311  1.14       erh }
    312  1.14       erh 
    313  1.14       erh void
    314  1.33  christos native_to_linux_old_sigaction(lsa, bsa)
    315  1.14       erh 	struct linux_old_sigaction *lsa;
    316  1.33  christos 	const struct sigaction *bsa;
    317  1.14       erh {
    318  1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    319  1.33  christos 	native_to_linux_old_sigset(&lsa->sa_mask, &bsa->sa_mask);
    320  1.34  christos 	lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    321  1.34  christos #ifndef __alpha__
    322  1.33  christos 	lsa->sa_restorer = NULL;
    323  1.34  christos #endif
    324  1.14       erh }
    325  1.14       erh 
    326  1.14       erh /* ...and the new sigaction conversion funcs. */
    327  1.14       erh void
    328  1.33  christos linux_to_native_sigaction(bsa, lsa)
    329   1.1      fvdl 	struct sigaction *bsa;
    330  1.33  christos 	const struct linux_sigaction *lsa;
    331   1.1      fvdl {
    332   1.1      fvdl 	bsa->sa_handler = lsa->sa_handler;
    333  1.33  christos 	linux_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    334  1.34  christos 	bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
    335  1.34  christos #ifndef __alpha__
    336  1.12   mycroft 	if (lsa->sa_restorer != 0)
    337  1.36  christos 		DPRINTF(("linux_to_native_sigaction: sa_restorer ignored\n"));
    338  1.34  christos #endif
    339   1.1      fvdl }
    340   1.1      fvdl 
    341   1.1      fvdl void
    342  1.33  christos native_to_linux_sigaction(lsa, bsa)
    343   1.1      fvdl 	struct linux_sigaction *lsa;
    344  1.33  christos 	const struct sigaction *bsa;
    345   1.1      fvdl {
    346  1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    347  1.33  christos 	native_to_linux_sigset(&lsa->sa_mask, &bsa->sa_mask);
    348  1.34  christos 	lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    349  1.34  christos #ifndef __alpha__
    350  1.33  christos 	lsa->sa_restorer = NULL;
    351  1.34  christos #endif
    352   1.1      fvdl }
    353   1.1      fvdl 
    354  1.14       erh /* ----------------------------------------------------------------------- */
    355   1.1      fvdl 
    356   1.1      fvdl /*
    357   1.1      fvdl  * The Linux sigaction() system call. Do the usual conversions,
    358   1.1      fvdl  * and just call sigaction(). Some flags and values are silently
    359   1.1      fvdl  * ignored (see above).
    360   1.1      fvdl  */
    361   1.1      fvdl int
    362  1.14       erh linux_sys_rt_sigaction(p, v, retval)
    363  1.26  augustss 	struct proc *p;
    364   1.8   thorpej 	void *v;
    365   1.8   thorpej 	register_t *retval;
    366   1.8   thorpej {
    367  1.14       erh 	struct linux_sys_rt_sigaction_args /* {
    368   1.1      fvdl 		syscallarg(int) signum;
    369  1.12   mycroft 		syscallarg(const struct linux_sigaction *) nsa;
    370   1.1      fvdl 		syscallarg(struct linux_sigaction *) osa;
    371  1.14       erh 		syscallarg(size_t) sigsetsize;
    372   1.8   thorpej 	} */ *uap = v;
    373  1.12   mycroft 	struct linux_sigaction nlsa, olsa;
    374  1.12   mycroft 	struct sigaction nbsa, obsa;
    375  1.25      tron 	int error, sig;
    376   1.1      fvdl 
    377  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    378  1.14       erh 		return (EINVAL);
    379  1.14       erh 
    380  1.12   mycroft 	if (SCARG(uap, nsa)) {
    381  1.12   mycroft 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    382  1.12   mycroft 		if (error)
    383  1.12   mycroft 			return (error);
    384  1.33  christos 		linux_to_native_sigaction(&nbsa, &nlsa);
    385  1.12   mycroft 	}
    386  1.25      tron 	sig = SCARG(uap, signum);
    387  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    388  1.25      tron 		return (EINVAL);
    389  1.29        tv 	if (sig > 0 && !linux_to_native_sig[sig]) {
    390  1.29        tv 		/* Pretend that we did something useful for unknown signals. */
    391  1.29        tv 		obsa.sa_handler = SIG_IGN;
    392  1.29        tv 		sigemptyset(&obsa.sa_mask);
    393  1.29        tv 		obsa.sa_flags = 0;
    394  1.29        tv 	} else {
    395  1.29        tv 		error = sigaction1(p, linux_to_native_sig[sig],
    396  1.29        tv 		    SCARG(uap, nsa) ? &nbsa : NULL, SCARG(uap, osa) ? &obsa : NULL);
    397  1.29        tv 		if (error)
    398  1.29        tv 			return (error);
    399  1.29        tv 	}
    400  1.12   mycroft 	if (SCARG(uap, osa)) {
    401  1.33  christos 		native_to_linux_sigaction(&olsa, &obsa);
    402  1.12   mycroft 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    403  1.12   mycroft 		if (error)
    404  1.12   mycroft 			return (error);
    405   1.1      fvdl 	}
    406  1.12   mycroft 	return (0);
    407   1.1      fvdl }
    408   1.1      fvdl 
    409   1.1      fvdl int
    410  1.17       erh linux_sigprocmask1(p, how, set, oset)
    411  1.26  augustss 	struct proc *p;
    412  1.17       erh 	int how;
    413  1.17       erh 	const linux_old_sigset_t *set;
    414  1.17       erh 	linux_old_sigset_t *oset;
    415   1.8   thorpej {
    416  1.14       erh 	linux_old_sigset_t nlss, olss;
    417  1.12   mycroft 	sigset_t nbss, obss;
    418  1.12   mycroft 	int error;
    419   1.1      fvdl 
    420  1.17       erh 	switch (how) {
    421   1.1      fvdl 	case LINUX_SIG_BLOCK:
    422  1.12   mycroft 		how = SIG_BLOCK;
    423   1.1      fvdl 		break;
    424   1.1      fvdl 	case LINUX_SIG_UNBLOCK:
    425  1.12   mycroft 		how = SIG_UNBLOCK;
    426   1.1      fvdl 		break;
    427   1.1      fvdl 	case LINUX_SIG_SETMASK:
    428  1.12   mycroft 		how = SIG_SETMASK;
    429   1.1      fvdl 		break;
    430   1.1      fvdl 	default:
    431  1.12   mycroft 		return (EINVAL);
    432   1.1      fvdl 	}
    433   1.1      fvdl 
    434  1.17       erh 	if (set) {
    435  1.17       erh 		error = copyin(set, &nlss, sizeof(nlss));
    436  1.12   mycroft 		if (error)
    437  1.12   mycroft 			return (error);
    438  1.33  christos 		linux_old_to_native_sigset(&nbss, &nlss);
    439  1.12   mycroft 	}
    440  1.12   mycroft 	error = sigprocmask1(p, how,
    441  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    442  1.12   mycroft 	if (error)
    443  1.12   mycroft 		return (error);
    444  1.17       erh 	if (oset) {
    445  1.33  christos 		native_to_linux_old_sigset(&olss, &obss);
    446  1.17       erh 		error = copyout(&olss, oset, sizeof(olss));
    447  1.12   mycroft 		if (error)
    448  1.12   mycroft 			return (error);
    449  1.12   mycroft 	}
    450  1.12   mycroft 	return (error);
    451  1.17       erh }
    452  1.17       erh 
    453  1.17       erh int
    454  1.17       erh linux_sys_rt_sigprocmask(p, v, retval)
    455  1.26  augustss 	struct proc *p;
    456  1.17       erh 	void *v;
    457  1.17       erh 	register_t *retval;
    458  1.17       erh {
    459  1.17       erh 	struct linux_sys_rt_sigprocmask_args /* {
    460  1.17       erh 		syscallarg(int) how;
    461  1.17       erh 		syscallarg(const linux_sigset_t *) set;
    462  1.17       erh 		syscallarg(linux_sigset_t *) oset;
    463  1.17       erh 		syscallarg(size_t) sigsetsize;
    464  1.17       erh 	} */ *uap = v;
    465  1.17       erh 
    466  1.24      fvdl 	linux_sigset_t nlss, olss, *oset;
    467  1.24      fvdl 	const linux_sigset_t *set;
    468  1.24      fvdl 	sigset_t nbss, obss;
    469  1.24      fvdl 	int error, how;
    470  1.24      fvdl 
    471  1.24      fvdl 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    472  1.24      fvdl 		return (EINVAL);
    473  1.24      fvdl 
    474  1.24      fvdl 	switch (SCARG(uap, how)) {
    475  1.24      fvdl 	case LINUX_SIG_BLOCK:
    476  1.24      fvdl 		how = SIG_BLOCK;
    477  1.24      fvdl 		break;
    478  1.24      fvdl 	case LINUX_SIG_UNBLOCK:
    479  1.24      fvdl 		how = SIG_UNBLOCK;
    480  1.24      fvdl 		break;
    481  1.24      fvdl 	case LINUX_SIG_SETMASK:
    482  1.24      fvdl 		how = SIG_SETMASK;
    483  1.24      fvdl 		break;
    484  1.24      fvdl 	default:
    485  1.24      fvdl 		return (EINVAL);
    486  1.17       erh 	}
    487  1.17       erh 
    488  1.24      fvdl 	set = SCARG(uap, set);
    489  1.24      fvdl 	oset = SCARG(uap, oset);
    490  1.24      fvdl 
    491  1.24      fvdl 	if (set) {
    492  1.24      fvdl 		error = copyin(set, &nlss, sizeof(nlss));
    493  1.24      fvdl 		if (error)
    494  1.24      fvdl 			return (error);
    495  1.33  christos 		linux_to_native_sigset(&nbss, &nlss);
    496  1.24      fvdl 	}
    497  1.24      fvdl 	error = sigprocmask1(p, how,
    498  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    499  1.28      tron 	if (!error && oset) {
    500  1.33  christos 		native_to_linux_sigset(&olss, &obss);
    501  1.24      fvdl 		error = copyout(&olss, oset, sizeof(olss));
    502  1.24      fvdl 	}
    503  1.24      fvdl 	return (error);
    504   1.1      fvdl }
    505   1.1      fvdl 
    506   1.1      fvdl int
    507  1.14       erh linux_sys_rt_sigpending(p, v, retval)
    508  1.26  augustss 	struct proc *p;
    509   1.9   mycroft 	void *v;
    510   1.1      fvdl 	register_t *retval;
    511   1.1      fvdl {
    512  1.14       erh 	struct linux_sys_rt_sigpending_args /* {
    513  1.14       erh 		syscallarg(linux_sigset_t *) set;
    514  1.14       erh 		syscallarg(size_t) sigsetsize;
    515  1.14       erh 	} */ *uap = v;
    516  1.12   mycroft 	sigset_t bss;
    517  1.12   mycroft 	linux_sigset_t lss;
    518   1.6   mycroft 
    519  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    520  1.14       erh 		return (EINVAL);
    521  1.14       erh 
    522  1.14       erh 	sigpending1(p, &bss);
    523  1.33  christos 	native_to_linux_sigset(&lss, &bss);
    524  1.14       erh 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    525   1.1      fvdl }
    526  1.24      fvdl 
    527   1.1      fvdl int
    528   1.9   mycroft linux_sys_sigpending(p, v, retval)
    529  1.26  augustss 	struct proc *p;
    530   1.8   thorpej 	void *v;
    531   1.8   thorpej 	register_t *retval;
    532   1.8   thorpej {
    533   1.9   mycroft 	struct linux_sys_sigpending_args /* {
    534  1.14       erh 		syscallarg(linux_old_sigset_t *) mask;
    535   1.8   thorpej 	} */ *uap = v;
    536  1.12   mycroft 	sigset_t bss;
    537  1.14       erh 	linux_old_sigset_t lss;
    538   1.1      fvdl 
    539  1.12   mycroft 	sigpending1(p, &bss);
    540  1.33  christos 	native_to_linux_old_sigset(&lss, &bss);
    541  1.12   mycroft 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    542   1.1      fvdl }
    543   1.1      fvdl 
    544   1.1      fvdl int
    545   1.9   mycroft linux_sys_sigsuspend(p, v, retval)
    546  1.26  augustss 	struct proc *p;
    547   1.8   thorpej 	void *v;
    548   1.8   thorpej 	register_t *retval;
    549   1.8   thorpej {
    550   1.9   mycroft 	struct linux_sys_sigsuspend_args /* {
    551   1.3      fvdl 		syscallarg(caddr_t) restart;
    552   1.3      fvdl 		syscallarg(int) oldmask;
    553   1.1      fvdl 		syscallarg(int) mask;
    554   1.8   thorpej 	} */ *uap = v;
    555  1.14       erh 	linux_old_sigset_t lss;
    556  1.14       erh 	sigset_t bss;
    557  1.14       erh 
    558  1.14       erh 	lss = SCARG(uap, mask);
    559  1.33  christos 	linux_old_to_native_sigset(&bss, &lss);
    560  1.14       erh 	return (sigsuspend1(p, &bss));
    561  1.14       erh }
    562  1.14       erh int
    563  1.14       erh linux_sys_rt_sigsuspend(p, v, retval)
    564  1.26  augustss 	struct proc *p;
    565  1.14       erh 	void *v;
    566  1.14       erh 	register_t *retval;
    567  1.14       erh {
    568  1.14       erh 	struct linux_sys_rt_sigsuspend_args /* {
    569  1.14       erh 		syscallarg(linux_sigset_t *) unewset;
    570  1.14       erh 		syscallarg(size_t) sigsetsize;
    571  1.14       erh 	} */ *uap = v;
    572  1.12   mycroft 	linux_sigset_t lss;
    573  1.12   mycroft 	sigset_t bss;
    574  1.14       erh 	int error;
    575  1.14       erh 
    576  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    577  1.14       erh 		return (EINVAL);
    578  1.14       erh 
    579  1.14       erh 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    580  1.14       erh 	if (error)
    581  1.14       erh 		return (error);
    582  1.14       erh 
    583  1.33  christos 	linux_to_native_sigset(&bss, &lss);
    584  1.14       erh 
    585  1.12   mycroft 	return (sigsuspend1(p, &bss));
    586   1.3      fvdl }
    587   1.3      fvdl 
    588   1.3      fvdl /*
    589  1.14       erh  * Once more: only a signal conversion is needed.
    590  1.14       erh  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    591   1.3      fvdl  */
    592   1.3      fvdl int
    593  1.14       erh linux_sys_rt_queueinfo(p, v, retval)
    594  1.26  augustss 	struct proc *p;
    595  1.14       erh 	void *v;
    596   1.3      fvdl 	register_t *retval;
    597  1.14       erh {
    598  1.14       erh 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    599  1.14       erh #if 0
    600  1.14       erh 	struct linux_sys_rt_queueinfo_args /* {
    601  1.14       erh 		syscallarg(int) pid;
    602  1.14       erh 		syscallarg(int) signum;
    603  1.14       erh 		syscallarg(siginfo_t *) uinfo;
    604  1.14       erh 	} */ *uap = v;
    605  1.14       erh #endif
    606   1.3      fvdl 
    607  1.14       erh 	/* XXX To really implement this we need to	*/
    608  1.14       erh 	/* XXX keep a list of queued signals somewhere.	*/
    609  1.14       erh 	return (linux_sys_kill(p, v, retval));
    610   1.1      fvdl }
    611   1.1      fvdl 
    612   1.1      fvdl int
    613   1.9   mycroft linux_sys_kill(p, v, retval)
    614  1.26  augustss 	struct proc *p;
    615   1.8   thorpej 	void *v;
    616   1.8   thorpej 	register_t *retval;
    617   1.8   thorpej {
    618   1.9   mycroft 	struct linux_sys_kill_args /* {
    619   1.1      fvdl 		syscallarg(int) pid;
    620   1.1      fvdl 		syscallarg(int) signum;
    621   1.8   thorpej 	} */ *uap = v;
    622   1.9   mycroft 	struct sys_kill_args ka;
    623  1.25      tron 	int sig;
    624   1.6   mycroft 
    625   1.6   mycroft 	SCARG(&ka, pid) = SCARG(uap, pid);
    626  1.25      tron 	sig = SCARG(uap, signum);
    627  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    628  1.25      tron 		return (EINVAL);
    629  1.25      tron 	SCARG(&ka, signum) = linux_to_native_sig[sig];
    630   1.9   mycroft 	return sys_kill(p, &ka, retval);
    631   1.1      fvdl }
    632  1.30  christos 
    633  1.30  christos #ifdef LINUX_SS_ONSTACK
    634  1.30  christos static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    635  1.30  christos     const struct linux_sigaltstack *));
    636  1.30  christos static void native_to_linux_sigaltstack __P((struct linux_sigaltstack *,
    637  1.30  christos     const struct sigaltstack *));
    638  1.30  christos 
    639  1.30  christos static void
    640  1.30  christos linux_to_native_sigaltstack(bss, lss)
    641  1.30  christos 	struct sigaltstack *bss;
    642  1.30  christos 	const struct linux_sigaltstack *lss;
    643  1.30  christos {
    644  1.30  christos 	bss->ss_sp = lss->ss_sp;
    645  1.30  christos 	bss->ss_size = lss->ss_size;
    646  1.30  christos 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    647  1.30  christos 	    bss->ss_flags = SS_ONSTACK;
    648  1.30  christos 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    649  1.30  christos 	    bss->ss_flags = SS_DISABLE;
    650  1.30  christos 	else
    651  1.30  christos 	    bss->ss_flags = 0;
    652  1.30  christos }
    653  1.30  christos 
    654  1.30  christos static void
    655  1.30  christos native_to_linux_sigaltstack(lss, bss)
    656  1.30  christos 	struct linux_sigaltstack *lss;
    657  1.30  christos 	const struct sigaltstack *bss;
    658  1.30  christos {
    659  1.30  christos 	lss->ss_sp = bss->ss_sp;
    660  1.30  christos 	lss->ss_size = bss->ss_size;
    661  1.30  christos 	if (bss->ss_flags & SS_ONSTACK)
    662  1.30  christos 	    lss->ss_flags = LINUX_SS_ONSTACK;
    663  1.30  christos 	else if (bss->ss_flags & SS_DISABLE)
    664  1.30  christos 	    lss->ss_flags = LINUX_SS_DISABLE;
    665  1.30  christos 	else
    666  1.30  christos 	    lss->ss_flags = 0;
    667  1.30  christos }
    668  1.30  christos 
    669  1.30  christos int
    670  1.30  christos linux_sys_sigaltstack(p, v, retval)
    671  1.30  christos 	struct proc *p;
    672  1.30  christos 	void *v;
    673  1.30  christos 	register_t *retval;
    674  1.30  christos {
    675  1.30  christos 	struct linux_sys_sigaltstack_args /* {
    676  1.30  christos 		syscallarg(const struct linux_sigaltstack *) ss;
    677  1.30  christos 		syscallarg(struct linux_sigaltstack *) oss;
    678  1.30  christos 	} */ *uap = v;
    679  1.30  christos 	struct linux_sigaltstack ss;
    680  1.30  christos 	struct sigaltstack nss, oss;
    681  1.30  christos 	int error;
    682  1.30  christos 
    683  1.30  christos 	if (SCARG(uap, ss) != NULL) {
    684  1.30  christos 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    685  1.30  christos 			return error;
    686  1.30  christos 		linux_to_native_sigaltstack(&nss, &ss);
    687  1.30  christos 	}
    688  1.30  christos 
    689  1.30  christos 	error = sigaltstack1(p,
    690  1.30  christos 	    SCARG(uap, ss) ? &nss : NULL, SCARG(uap, oss) ? &oss : NULL);
    691  1.30  christos 	if (error)
    692  1.30  christos 		return error;
    693  1.30  christos 
    694  1.30  christos 	if (SCARG(uap, oss) != NULL) {
    695  1.30  christos 		native_to_linux_sigaltstack(&ss, &oss);
    696  1.30  christos 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    697  1.30  christos 			return error;
    698  1.30  christos 	}
    699  1.30  christos 	return 0;
    700  1.30  christos }
    701  1.30  christos #endif
    702