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