Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.29
      1  1.29        tv /*	$NetBSD: linux_signal.c,v 1.29 2000/08/09 20:20:49 tv 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.21  drochner 
     56  1.21  drochner #define COMPAT_LINUX 1
     57  1.14       erh 
     58   1.1      fvdl #include <sys/param.h>
     59   1.1      fvdl #include <sys/systm.h>
     60   1.1      fvdl #include <sys/namei.h>
     61   1.1      fvdl #include <sys/proc.h>
     62   1.1      fvdl #include <sys/filedesc.h>
     63   1.1      fvdl #include <sys/ioctl.h>
     64   1.1      fvdl #include <sys/mount.h>
     65   1.1      fvdl #include <sys/kernel.h>
     66   1.1      fvdl #include <sys/signal.h>
     67   1.1      fvdl #include <sys/signalvar.h>
     68   1.1      fvdl #include <sys/malloc.h>
     69   1.1      fvdl 
     70   1.1      fvdl #include <sys/syscallargs.h>
     71   1.1      fvdl 
     72  1.15  christos #include <compat/linux/common/linux_types.h>
     73  1.15  christos #include <compat/linux/common/linux_signal.h>
     74  1.17       erh #include <compat/linux/common/linux_siginfo.h>
     75  1.15  christos #include <compat/linux/common/linux_util.h>
     76  1.15  christos 
     77   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     78   1.1      fvdl 
     79  1.14       erh /* Locally used defines (in bsd<->linux conversion functions): */
     80  1.11     perry #define	linux_sigemptyset(s)	memset((s), 0, sizeof(*(s)))
     81  1.20     itohy #define	linux_sigismember(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     82  1.20     itohy 					& (1 << ((n) - 1) % LINUX__NSIG_BPW))
     83  1.20     itohy #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     84  1.20     itohy 					|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
     85   1.6   mycroft 
     86  1.14       erh /* Note: linux_to_native_sig[] is in <arch>/linux_sigarray.c */
     87  1.12   mycroft int native_to_linux_sig[NSIG] = {
     88   1.6   mycroft 	0,
     89   1.6   mycroft 	LINUX_SIGHUP,
     90   1.6   mycroft 	LINUX_SIGINT,
     91   1.6   mycroft 	LINUX_SIGQUIT,
     92   1.6   mycroft 	LINUX_SIGILL,
     93   1.6   mycroft 	LINUX_SIGTRAP,
     94   1.6   mycroft 	LINUX_SIGABRT,
     95  1.12   mycroft 	0,			/* SIGEMT */
     96   1.6   mycroft 	LINUX_SIGFPE,
     97   1.6   mycroft 	LINUX_SIGKILL,
     98   1.6   mycroft 	LINUX_SIGBUS,
     99   1.6   mycroft 	LINUX_SIGSEGV,
    100  1.23      tron 	0,			/* SIGSYS */
    101   1.6   mycroft 	LINUX_SIGPIPE,
    102   1.6   mycroft 	LINUX_SIGALRM,
    103   1.6   mycroft 	LINUX_SIGTERM,
    104   1.6   mycroft 	LINUX_SIGURG,
    105   1.6   mycroft 	LINUX_SIGSTOP,
    106   1.6   mycroft 	LINUX_SIGTSTP,
    107   1.6   mycroft 	LINUX_SIGCONT,
    108   1.6   mycroft 	LINUX_SIGCHLD,
    109   1.6   mycroft 	LINUX_SIGTTIN,
    110   1.6   mycroft 	LINUX_SIGTTOU,
    111   1.6   mycroft 	LINUX_SIGIO,
    112   1.6   mycroft 	LINUX_SIGXCPU,
    113   1.6   mycroft 	LINUX_SIGXFSZ,
    114   1.6   mycroft 	LINUX_SIGVTALRM,
    115   1.6   mycroft 	LINUX_SIGPROF,
    116   1.6   mycroft 	LINUX_SIGWINCH,
    117  1.12   mycroft 	0,			/* SIGINFO */
    118   1.6   mycroft 	LINUX_SIGUSR1,
    119   1.6   mycroft 	LINUX_SIGUSR2,
    120  1.12   mycroft 	LINUX_SIGPWR,
    121   1.6   mycroft };
    122   1.6   mycroft 
    123  1.14       erh /*
    124  1.20     itohy  * Convert between Linux and BSD signal sets.
    125  1.14       erh  */
    126  1.20     itohy #if LINUX__NSIG_WORDS > 1
    127   1.6   mycroft void
    128  1.20     itohy linux_old_extra_to_native_sigset(lss, extra, bss)
    129  1.14       erh 	const linux_old_sigset_t *lss;
    130  1.20     itohy 	const unsigned long *extra;
    131  1.20     itohy 	sigset_t *bss;
    132  1.20     itohy {
    133  1.20     itohy 	linux_sigset_t lsnew;
    134  1.20     itohy 
    135  1.20     itohy 	/* convert old sigset to new sigset */
    136  1.20     itohy 	linux_sigemptyset(&lsnew);
    137  1.20     itohy 	lsnew.sig[0] = *lss;
    138  1.20     itohy 	if (extra)
    139  1.20     itohy 		bcopy(extra, &lsnew.sig[1],
    140  1.20     itohy 			sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    141  1.20     itohy 
    142  1.20     itohy 	linux_to_native_sigset(&lsnew, bss);
    143  1.20     itohy }
    144  1.20     itohy 
    145  1.20     itohy void
    146  1.20     itohy native_to_linux_old_extra_sigset(bss, lss, extra)
    147  1.20     itohy 	const sigset_t *bss;
    148  1.20     itohy 	linux_old_sigset_t *lss;
    149  1.20     itohy 	unsigned long *extra;
    150  1.20     itohy {
    151  1.20     itohy 	linux_sigset_t lsnew;
    152  1.20     itohy 
    153  1.20     itohy 	native_to_linux_sigset(bss, &lsnew);
    154  1.20     itohy 
    155  1.20     itohy 	/* convert new sigset to old sigset */
    156  1.20     itohy 	*lss = lsnew.sig[0];
    157  1.20     itohy 	if (extra)
    158  1.20     itohy 		bcopy(&lsnew.sig[1], extra,
    159  1.20     itohy 			sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    160  1.20     itohy }
    161  1.20     itohy #endif
    162  1.20     itohy 
    163  1.20     itohy void
    164  1.20     itohy linux_to_native_sigset(lss, bss)
    165  1.20     itohy 	const linux_sigset_t *lss;
    166   1.1      fvdl 	sigset_t *bss;
    167   1.1      fvdl {
    168   1.1      fvdl 	int i, newsig;
    169   1.1      fvdl 
    170   1.6   mycroft 	sigemptyset(bss);
    171  1.20     itohy 	for (i = 1; i < LINUX__NSIG; i++) {
    172   1.6   mycroft 		if (linux_sigismember(lss, i)) {
    173  1.12   mycroft 			newsig = linux_to_native_sig[i];
    174   1.1      fvdl 			if (newsig)
    175   1.6   mycroft 				sigaddset(bss, newsig);
    176   1.1      fvdl 		}
    177   1.1      fvdl 	}
    178   1.1      fvdl }
    179   1.1      fvdl 
    180   1.1      fvdl void
    181  1.20     itohy native_to_linux_sigset(bss, lss)
    182   1.1      fvdl 	const sigset_t *bss;
    183  1.20     itohy 	linux_sigset_t *lss;
    184   1.1      fvdl {
    185   1.1      fvdl 	int i, newsig;
    186  1.20     itohy 
    187   1.6   mycroft 	linux_sigemptyset(lss);
    188   1.6   mycroft 	for (i = 1; i < NSIG; i++) {
    189   1.6   mycroft 		if (sigismember(bss, i)) {
    190  1.12   mycroft 			newsig = native_to_linux_sig[i];
    191   1.1      fvdl 			if (newsig)
    192   1.6   mycroft 				linux_sigaddset(lss, newsig);
    193   1.1      fvdl 		}
    194   1.1      fvdl 	}
    195   1.1      fvdl }
    196   1.1      fvdl 
    197   1.1      fvdl /*
    198  1.14       erh  * Convert between Linux and BSD sigaction structures. Linux sometimes
    199  1.14       erh  * has one extra field (sa_restorer) which we don't support.
    200   1.1      fvdl  */
    201   1.1      fvdl void
    202  1.14       erh linux_old_to_native_sigaction(lsa, bsa)
    203  1.14       erh 	struct linux_old_sigaction *lsa;
    204  1.14       erh 	struct sigaction *bsa;
    205  1.14       erh {
    206  1.14       erh 
    207  1.14       erh 	bsa->sa_handler = lsa->sa_handler;
    208  1.14       erh 	linux_old_to_native_sigset(&lsa->sa_mask, &bsa->sa_mask);
    209  1.14       erh 	bsa->sa_flags = 0;
    210  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_NOCLDSTOP) != 0)
    211  1.14       erh 		bsa->sa_flags |= SA_NOCLDSTOP;
    212  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_ONSTACK) != 0)
    213  1.14       erh 		bsa->sa_flags |= SA_ONSTACK;
    214  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_RESTART) != 0)
    215  1.14       erh 		bsa->sa_flags |= SA_RESTART;
    216  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_ONESHOT) != 0)
    217  1.14       erh 		bsa->sa_flags |= SA_RESETHAND;
    218  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_NOMASK) != 0)
    219  1.14       erh 		bsa->sa_flags |= SA_NODEFER;
    220  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_SIGINFO) != 0)
    221  1.14       erh 		bsa->sa_flags |= SA_SIGINFO;
    222  1.22  jdolecek #ifdef DEBUG_LINUX
    223  1.14       erh 	if ((lsa->sa_flags & ~LINUX_SA_ALLBITS) != 0)
    224  1.14       erh /*XXX*/		printf("linux_old_to_native_sigaction: extra bits ignored\n");
    225  1.14       erh 	if (lsa->sa_restorer != 0)
    226  1.14       erh /*XXX*/		printf("linux_old_to_native_sigaction: sa_restorer ignored\n");
    227  1.14       erh #endif
    228  1.14       erh }
    229  1.14       erh 
    230  1.14       erh void
    231  1.14       erh native_to_linux_old_sigaction(bsa, lsa)
    232  1.14       erh 	struct sigaction *bsa;
    233  1.14       erh 	struct linux_old_sigaction *lsa;
    234  1.14       erh {
    235  1.14       erh 
    236  1.14       erh 	/* Clear sa_flags and sa_restorer (if it exists) */
    237  1.14       erh 	bzero(lsa, sizeof(struct linux_old_sigaction));
    238  1.14       erh 
    239  1.14       erh 	/* ...and fill in the mask and flags */
    240  1.14       erh 	native_to_linux_old_sigset(&bsa->sa_mask, &lsa->sa_mask);
    241  1.14       erh 	if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
    242  1.14       erh 		lsa->sa_flags |= LINUX_SA_NOCLDSTOP;
    243  1.14       erh 	if ((bsa->sa_flags & SA_ONSTACK) != 0)
    244  1.14       erh 		lsa->sa_flags |= LINUX_SA_ONSTACK;
    245  1.14       erh 	if ((bsa->sa_flags & SA_RESTART) != 0)
    246  1.14       erh 		lsa->sa_flags |= LINUX_SA_RESTART;
    247  1.14       erh 	if ((bsa->sa_flags & SA_NODEFER) != 0)
    248  1.14       erh 		lsa->sa_flags |= LINUX_SA_NOMASK;
    249  1.14       erh 	if ((bsa->sa_flags & SA_RESETHAND) != 0)
    250  1.14       erh 		lsa->sa_flags |= LINUX_SA_ONESHOT;
    251  1.14       erh 	if ((bsa->sa_flags & SA_SIGINFO) != 0)
    252  1.14       erh 		lsa->sa_flags |= LINUX_SA_SIGINFO;
    253  1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    254  1.14       erh }
    255  1.14       erh 
    256  1.14       erh /* ...and the new sigaction conversion funcs. */
    257  1.14       erh void
    258  1.12   mycroft linux_to_native_sigaction(lsa, bsa)
    259   1.1      fvdl 	struct linux_sigaction *lsa;
    260   1.1      fvdl 	struct sigaction *bsa;
    261   1.1      fvdl {
    262   1.6   mycroft 
    263   1.1      fvdl 	bsa->sa_handler = lsa->sa_handler;
    264  1.12   mycroft 	linux_to_native_sigset(&lsa->sa_mask, &bsa->sa_mask);
    265   1.1      fvdl 	bsa->sa_flags = 0;
    266  1.12   mycroft 	if ((lsa->sa_flags & LINUX_SA_NOCLDSTOP) != 0)
    267  1.12   mycroft 		bsa->sa_flags |= SA_NOCLDSTOP;
    268   1.6   mycroft 	if ((lsa->sa_flags & LINUX_SA_ONSTACK) != 0)
    269   1.6   mycroft 		bsa->sa_flags |= SA_ONSTACK;
    270   1.6   mycroft 	if ((lsa->sa_flags & LINUX_SA_RESTART) != 0)
    271   1.6   mycroft 		bsa->sa_flags |= SA_RESTART;
    272   1.6   mycroft 	if ((lsa->sa_flags & LINUX_SA_ONESHOT) != 0)
    273   1.6   mycroft 		bsa->sa_flags |= SA_RESETHAND;
    274   1.6   mycroft 	if ((lsa->sa_flags & LINUX_SA_NOMASK) != 0)
    275   1.6   mycroft 		bsa->sa_flags |= SA_NODEFER;
    276  1.14       erh 	if ((lsa->sa_flags & LINUX_SA_SIGINFO) != 0)
    277  1.14       erh 		bsa->sa_flags |= SA_SIGINFO;
    278  1.22  jdolecek #ifdef DEBUG_LINUX
    279  1.12   mycroft 	if ((lsa->sa_flags & ~LINUX_SA_ALLBITS) != 0)
    280  1.12   mycroft /*XXX*/		printf("linux_to_native_sigaction: extra bits ignored\n");
    281  1.12   mycroft 	if (lsa->sa_restorer != 0)
    282  1.12   mycroft /*XXX*/		printf("linux_to_native_sigaction: sa_restorer ignored\n");
    283  1.13        tv #endif
    284   1.1      fvdl }
    285   1.1      fvdl 
    286   1.1      fvdl void
    287  1.12   mycroft native_to_linux_sigaction(bsa, lsa)
    288   1.1      fvdl 	struct sigaction *bsa;
    289   1.1      fvdl 	struct linux_sigaction *lsa;
    290   1.1      fvdl {
    291   1.6   mycroft 
    292  1.14       erh 	/* Clear sa_flags and sa_restorer (if it exists) */
    293  1.14       erh 	bzero(lsa, sizeof(struct linux_sigaction));
    294  1.14       erh 
    295  1.14       erh 	/* ...and fill in the mask and flags */
    296  1.12   mycroft 	native_to_linux_sigset(&bsa->sa_mask, &lsa->sa_mask);
    297   1.6   mycroft 	if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
    298   1.6   mycroft 		lsa->sa_flags |= LINUX_SA_NOCLDSTOP;
    299   1.6   mycroft 	if ((bsa->sa_flags & SA_ONSTACK) != 0)
    300   1.6   mycroft 		lsa->sa_flags |= LINUX_SA_ONSTACK;
    301   1.6   mycroft 	if ((bsa->sa_flags & SA_RESTART) != 0)
    302   1.6   mycroft 		lsa->sa_flags |= LINUX_SA_RESTART;
    303   1.6   mycroft 	if ((bsa->sa_flags & SA_NODEFER) != 0)
    304   1.6   mycroft 		lsa->sa_flags |= LINUX_SA_NOMASK;
    305   1.6   mycroft 	if ((bsa->sa_flags & SA_RESETHAND) != 0)
    306   1.6   mycroft 		lsa->sa_flags |= LINUX_SA_ONESHOT;
    307  1.14       erh 	if ((bsa->sa_flags & SA_SIGINFO) != 0)
    308  1.14       erh 		lsa->sa_flags |= LINUX_SA_SIGINFO;
    309  1.14       erh 	lsa->sa_handler = bsa->sa_handler;
    310   1.1      fvdl }
    311   1.1      fvdl 
    312  1.14       erh /* ----------------------------------------------------------------------- */
    313   1.1      fvdl 
    314   1.1      fvdl /*
    315   1.1      fvdl  * The Linux sigaction() system call. Do the usual conversions,
    316   1.1      fvdl  * and just call sigaction(). Some flags and values are silently
    317   1.1      fvdl  * ignored (see above).
    318   1.1      fvdl  */
    319   1.1      fvdl int
    320  1.14       erh linux_sys_rt_sigaction(p, v, retval)
    321  1.26  augustss 	struct proc *p;
    322   1.8   thorpej 	void *v;
    323   1.8   thorpej 	register_t *retval;
    324   1.8   thorpej {
    325  1.14       erh 	struct linux_sys_rt_sigaction_args /* {
    326   1.1      fvdl 		syscallarg(int) signum;
    327  1.12   mycroft 		syscallarg(const struct linux_sigaction *) nsa;
    328   1.1      fvdl 		syscallarg(struct linux_sigaction *) osa;
    329  1.14       erh 		syscallarg(size_t) sigsetsize;
    330   1.8   thorpej 	} */ *uap = v;
    331  1.12   mycroft 	struct linux_sigaction nlsa, olsa;
    332  1.12   mycroft 	struct sigaction nbsa, obsa;
    333  1.25      tron 	int error, sig;
    334   1.1      fvdl 
    335  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    336  1.14       erh 		return (EINVAL);
    337  1.14       erh 
    338  1.12   mycroft 	if (SCARG(uap, nsa)) {
    339  1.12   mycroft 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    340  1.12   mycroft 		if (error)
    341  1.12   mycroft 			return (error);
    342  1.12   mycroft 		linux_to_native_sigaction(&nlsa, &nbsa);
    343  1.12   mycroft 	}
    344  1.25      tron 	sig = SCARG(uap, signum);
    345  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    346  1.25      tron 		return (EINVAL);
    347  1.29        tv 	if (sig > 0 && !linux_to_native_sig[sig]) {
    348  1.29        tv 		/* Pretend that we did something useful for unknown signals. */
    349  1.29        tv 		obsa.sa_handler = SIG_IGN;
    350  1.29        tv 		sigemptyset(&obsa.sa_mask);
    351  1.29        tv 		obsa.sa_flags = 0;
    352  1.29        tv 	} else {
    353  1.29        tv 		error = sigaction1(p, linux_to_native_sig[sig],
    354  1.29        tv 		    SCARG(uap, nsa) ? &nbsa : NULL, SCARG(uap, osa) ? &obsa : NULL);
    355  1.29        tv 		if (error)
    356  1.29        tv 			return (error);
    357  1.29        tv 	}
    358  1.12   mycroft 	if (SCARG(uap, osa)) {
    359  1.12   mycroft 		native_to_linux_sigaction(&obsa, &olsa);
    360  1.12   mycroft 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    361  1.12   mycroft 		if (error)
    362  1.12   mycroft 			return (error);
    363   1.1      fvdl 	}
    364  1.12   mycroft 	return (0);
    365   1.1      fvdl }
    366   1.1      fvdl 
    367   1.1      fvdl int
    368  1.17       erh linux_sigprocmask1(p, how, set, oset)
    369  1.26  augustss 	struct proc *p;
    370  1.17       erh 	int how;
    371  1.17       erh 	const linux_old_sigset_t *set;
    372  1.17       erh 	linux_old_sigset_t *oset;
    373   1.8   thorpej {
    374  1.14       erh 	linux_old_sigset_t nlss, olss;
    375  1.12   mycroft 	sigset_t nbss, obss;
    376  1.12   mycroft 	int error;
    377   1.1      fvdl 
    378  1.17       erh 	switch (how) {
    379   1.1      fvdl 	case LINUX_SIG_BLOCK:
    380  1.12   mycroft 		how = SIG_BLOCK;
    381   1.1      fvdl 		break;
    382   1.1      fvdl 	case LINUX_SIG_UNBLOCK:
    383  1.12   mycroft 		how = SIG_UNBLOCK;
    384   1.1      fvdl 		break;
    385   1.1      fvdl 	case LINUX_SIG_SETMASK:
    386  1.12   mycroft 		how = SIG_SETMASK;
    387   1.1      fvdl 		break;
    388   1.1      fvdl 	default:
    389  1.12   mycroft 		return (EINVAL);
    390   1.1      fvdl 	}
    391   1.1      fvdl 
    392  1.17       erh 	if (set) {
    393  1.17       erh 		error = copyin(set, &nlss, sizeof(nlss));
    394  1.12   mycroft 		if (error)
    395  1.12   mycroft 			return (error);
    396  1.14       erh 		linux_old_to_native_sigset(&nlss, &nbss);
    397  1.12   mycroft 	}
    398  1.12   mycroft 	error = sigprocmask1(p, how,
    399  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    400  1.12   mycroft 	if (error)
    401  1.12   mycroft 		return (error);
    402  1.17       erh 	if (oset) {
    403  1.14       erh 		native_to_linux_old_sigset(&obss, &olss);
    404  1.17       erh 		error = copyout(&olss, oset, sizeof(olss));
    405  1.12   mycroft 		if (error)
    406  1.12   mycroft 			return (error);
    407  1.12   mycroft 	}
    408  1.12   mycroft 	return (error);
    409  1.17       erh }
    410  1.17       erh 
    411  1.17       erh int
    412  1.17       erh linux_sys_rt_sigprocmask(p, v, retval)
    413  1.26  augustss 	struct proc *p;
    414  1.17       erh 	void *v;
    415  1.17       erh 	register_t *retval;
    416  1.17       erh {
    417  1.17       erh 	struct linux_sys_rt_sigprocmask_args /* {
    418  1.17       erh 		syscallarg(int) how;
    419  1.17       erh 		syscallarg(const linux_sigset_t *) set;
    420  1.17       erh 		syscallarg(linux_sigset_t *) oset;
    421  1.17       erh 		syscallarg(size_t) sigsetsize;
    422  1.17       erh 	} */ *uap = v;
    423  1.17       erh 
    424  1.24      fvdl 	linux_sigset_t nlss, olss, *oset;
    425  1.24      fvdl 	const linux_sigset_t *set;
    426  1.24      fvdl 	sigset_t nbss, obss;
    427  1.24      fvdl 	int error, how;
    428  1.24      fvdl 
    429  1.24      fvdl 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    430  1.24      fvdl 		return (EINVAL);
    431  1.24      fvdl 
    432  1.24      fvdl 	switch (SCARG(uap, how)) {
    433  1.24      fvdl 	case LINUX_SIG_BLOCK:
    434  1.24      fvdl 		how = SIG_BLOCK;
    435  1.24      fvdl 		break;
    436  1.24      fvdl 	case LINUX_SIG_UNBLOCK:
    437  1.24      fvdl 		how = SIG_UNBLOCK;
    438  1.24      fvdl 		break;
    439  1.24      fvdl 	case LINUX_SIG_SETMASK:
    440  1.24      fvdl 		how = SIG_SETMASK;
    441  1.24      fvdl 		break;
    442  1.24      fvdl 	default:
    443  1.24      fvdl 		return (EINVAL);
    444  1.17       erh 	}
    445  1.17       erh 
    446  1.24      fvdl 	set = SCARG(uap, set);
    447  1.24      fvdl 	oset = SCARG(uap, oset);
    448  1.24      fvdl 
    449  1.24      fvdl 	if (set) {
    450  1.24      fvdl 		error = copyin(set, &nlss, sizeof(nlss));
    451  1.24      fvdl 		if (error)
    452  1.24      fvdl 			return (error);
    453  1.24      fvdl 		linux_to_native_sigset(&nlss, &nbss);
    454  1.24      fvdl 	}
    455  1.24      fvdl 	error = sigprocmask1(p, how,
    456  1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    457  1.28      tron 	if (!error && oset) {
    458  1.24      fvdl 		native_to_linux_sigset(&obss, &olss);
    459  1.24      fvdl 		error = copyout(&olss, oset, sizeof(olss));
    460  1.24      fvdl 	}
    461  1.24      fvdl 	return (error);
    462   1.1      fvdl }
    463   1.1      fvdl 
    464   1.1      fvdl int
    465  1.14       erh linux_sys_rt_sigpending(p, v, retval)
    466  1.26  augustss 	struct proc *p;
    467   1.9   mycroft 	void *v;
    468   1.1      fvdl 	register_t *retval;
    469   1.1      fvdl {
    470  1.14       erh 	struct linux_sys_rt_sigpending_args /* {
    471  1.14       erh 		syscallarg(linux_sigset_t *) set;
    472  1.14       erh 		syscallarg(size_t) sigsetsize;
    473  1.14       erh 	} */ *uap = v;
    474  1.12   mycroft 	sigset_t bss;
    475  1.12   mycroft 	linux_sigset_t lss;
    476   1.6   mycroft 
    477  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    478  1.14       erh 		return (EINVAL);
    479  1.14       erh 
    480  1.14       erh 	sigpending1(p, &bss);
    481  1.12   mycroft 	native_to_linux_sigset(&bss, &lss);
    482  1.14       erh 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    483   1.1      fvdl }
    484  1.24      fvdl 
    485   1.1      fvdl int
    486   1.9   mycroft linux_sys_sigpending(p, v, retval)
    487  1.26  augustss 	struct proc *p;
    488   1.8   thorpej 	void *v;
    489   1.8   thorpej 	register_t *retval;
    490   1.8   thorpej {
    491   1.9   mycroft 	struct linux_sys_sigpending_args /* {
    492  1.14       erh 		syscallarg(linux_old_sigset_t *) mask;
    493   1.8   thorpej 	} */ *uap = v;
    494  1.12   mycroft 	sigset_t bss;
    495  1.14       erh 	linux_old_sigset_t lss;
    496   1.1      fvdl 
    497  1.12   mycroft 	sigpending1(p, &bss);
    498  1.14       erh 	native_to_linux_old_sigset(&bss, &lss);
    499  1.12   mycroft 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    500   1.1      fvdl }
    501   1.1      fvdl 
    502   1.1      fvdl int
    503   1.9   mycroft linux_sys_sigsuspend(p, v, retval)
    504  1.26  augustss 	struct proc *p;
    505   1.8   thorpej 	void *v;
    506   1.8   thorpej 	register_t *retval;
    507   1.8   thorpej {
    508   1.9   mycroft 	struct linux_sys_sigsuspend_args /* {
    509   1.3      fvdl 		syscallarg(caddr_t) restart;
    510   1.3      fvdl 		syscallarg(int) oldmask;
    511   1.1      fvdl 		syscallarg(int) mask;
    512   1.8   thorpej 	} */ *uap = v;
    513  1.14       erh 	linux_old_sigset_t lss;
    514  1.14       erh 	sigset_t bss;
    515  1.14       erh 
    516  1.14       erh 	lss = SCARG(uap, mask);
    517  1.14       erh 	linux_old_to_native_sigset(&lss, &bss);
    518  1.14       erh 	return (sigsuspend1(p, &bss));
    519  1.14       erh }
    520  1.14       erh int
    521  1.14       erh linux_sys_rt_sigsuspend(p, v, retval)
    522  1.26  augustss 	struct proc *p;
    523  1.14       erh 	void *v;
    524  1.14       erh 	register_t *retval;
    525  1.14       erh {
    526  1.14       erh 	struct linux_sys_rt_sigsuspend_args /* {
    527  1.14       erh 		syscallarg(linux_sigset_t *) unewset;
    528  1.14       erh 		syscallarg(size_t) sigsetsize;
    529  1.14       erh 	} */ *uap = v;
    530  1.12   mycroft 	linux_sigset_t lss;
    531  1.12   mycroft 	sigset_t bss;
    532  1.14       erh 	int error;
    533  1.14       erh 
    534  1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    535  1.14       erh 		return (EINVAL);
    536  1.14       erh 
    537  1.14       erh 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    538  1.14       erh 	if (error)
    539  1.14       erh 		return (error);
    540  1.14       erh 
    541  1.12   mycroft 	linux_to_native_sigset(&lss, &bss);
    542  1.14       erh 
    543  1.12   mycroft 	return (sigsuspend1(p, &bss));
    544   1.3      fvdl }
    545   1.3      fvdl 
    546   1.3      fvdl /*
    547  1.14       erh  * Once more: only a signal conversion is needed.
    548  1.14       erh  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    549   1.3      fvdl  */
    550   1.3      fvdl int
    551  1.14       erh linux_sys_rt_queueinfo(p, v, retval)
    552  1.26  augustss 	struct proc *p;
    553  1.14       erh 	void *v;
    554   1.3      fvdl 	register_t *retval;
    555  1.14       erh {
    556  1.14       erh 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    557  1.14       erh #if 0
    558  1.14       erh 	struct linux_sys_rt_queueinfo_args /* {
    559  1.14       erh 		syscallarg(int) pid;
    560  1.14       erh 		syscallarg(int) signum;
    561  1.14       erh 		syscallarg(siginfo_t *) uinfo;
    562  1.14       erh 	} */ *uap = v;
    563  1.14       erh #endif
    564   1.3      fvdl 
    565  1.14       erh 	/* XXX To really implement this we need to	*/
    566  1.14       erh 	/* XXX keep a list of queued signals somewhere.	*/
    567  1.14       erh 	return (linux_sys_kill(p, v, retval));
    568   1.1      fvdl }
    569   1.1      fvdl 
    570   1.1      fvdl int
    571   1.9   mycroft linux_sys_kill(p, v, retval)
    572  1.26  augustss 	struct proc *p;
    573   1.8   thorpej 	void *v;
    574   1.8   thorpej 	register_t *retval;
    575   1.8   thorpej {
    576   1.9   mycroft 	struct linux_sys_kill_args /* {
    577   1.1      fvdl 		syscallarg(int) pid;
    578   1.1      fvdl 		syscallarg(int) signum;
    579   1.8   thorpej 	} */ *uap = v;
    580   1.9   mycroft 	struct sys_kill_args ka;
    581  1.25      tron 	int sig;
    582   1.6   mycroft 
    583   1.6   mycroft 	SCARG(&ka, pid) = SCARG(uap, pid);
    584  1.25      tron 	sig = SCARG(uap, signum);
    585  1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    586  1.25      tron 		return (EINVAL);
    587  1.25      tron 	SCARG(&ka, signum) = linux_to_native_sig[sig];
    588   1.9   mycroft 	return sys_kill(p, &ka, retval);
    589   1.1      fvdl }
    590