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