Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.72.2.1
      1  1.72.2.1      yamt /*	$NetBSD: linux_signal.c,v 1.72.2.1 2012/04/17 00:07:17 yamt Exp $	*/
      2      1.53        ad 
      3      1.16      fvdl /*-
      4      1.16      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5       1.1      fvdl  * All rights reserved.
      6       1.1      fvdl  *
      7      1.16      fvdl  * This code is derived from software contributed to The NetBSD Foundation
      8      1.16      fvdl  * by Frank van der Linden and Eric Haszlakiewicz.
      9      1.16      fvdl  *
     10       1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     11       1.1      fvdl  * modification, are permitted provided that the following conditions
     12       1.1      fvdl  * are met:
     13       1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     14       1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     15       1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     18       1.1      fvdl  *
     19      1.16      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.16      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.16      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.16      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.16      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.16      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.16      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.16      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.16      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.16      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.16      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     30      1.16      fvdl  */
     31      1.16      fvdl /*
     32       1.1      fvdl  * heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
     33       1.1      fvdl  */
     34       1.1      fvdl 
     35      1.14       erh /*
     36      1.14       erh  *   Functions in multiarch:
     37      1.14       erh  *	linux_sys_signal	: linux_sig_notalpha.c
     38      1.14       erh  *	linux_sys_siggetmask	: linux_sig_notalpha.c
     39      1.14       erh  *	linux_sys_sigsetmask	: linux_sig_notalpha.c
     40      1.14       erh  *	linux_sys_pause		: linux_sig_notalpha.c
     41      1.14       erh  *	linux_sys_sigaction	: linux_sigaction.c
     42      1.14       erh  *
     43      1.14       erh  */
     44      1.14       erh 
     45      1.14       erh /*
     46      1.14       erh  *   Unimplemented:
     47      1.14       erh  *	linux_sys_rt_sigtimedwait	: sigsuspend w/timeout.
     48      1.14       erh  */
     49      1.32     lukem 
     50      1.32     lukem #include <sys/cdefs.h>
     51  1.72.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.72.2.1 2012/04/17 00:07:17 yamt Exp $");
     52      1.21  drochner 
     53      1.21  drochner #define COMPAT_LINUX 1
     54      1.14       erh 
     55       1.1      fvdl #include <sys/param.h>
     56       1.1      fvdl #include <sys/systm.h>
     57       1.1      fvdl #include <sys/namei.h>
     58       1.1      fvdl #include <sys/proc.h>
     59       1.1      fvdl #include <sys/filedesc.h>
     60       1.1      fvdl #include <sys/ioctl.h>
     61       1.1      fvdl #include <sys/mount.h>
     62       1.1      fvdl #include <sys/kernel.h>
     63       1.1      fvdl #include <sys/signal.h>
     64       1.1      fvdl #include <sys/signalvar.h>
     65       1.1      fvdl #include <sys/malloc.h>
     66      1.68     njoly #include <sys/wait.h>
     67       1.1      fvdl 
     68       1.1      fvdl #include <sys/syscallargs.h>
     69       1.1      fvdl 
     70      1.15  christos #include <compat/linux/common/linux_types.h>
     71      1.15  christos #include <compat/linux/common/linux_signal.h>
     72      1.71       chs #include <compat/linux/common/linux_emuldata.h>
     73      1.17       erh #include <compat/linux/common/linux_siginfo.h>
     74      1.45      fvdl #include <compat/linux/common/linux_sigevent.h>
     75      1.15  christos #include <compat/linux/common/linux_util.h>
     76      1.55     njoly #include <compat/linux/common/linux_ipc.h>
     77      1.55     njoly #include <compat/linux/common/linux_sem.h>
     78  1.72.2.1      yamt #include <compat/linux/common/linux_errno.h>
     79  1.72.2.1      yamt #include <compat/linux/common/linux_sched.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.63     njoly 					& (1L << ((n) - 1) % LINUX__NSIG_BPW))
     87      1.20     itohy #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     88      1.63     njoly 					|= (1L << ((n) - 1) % LINUX__NSIG_BPW))
     89       1.6   mycroft 
     90      1.36  christos #ifdef DEBUG_LINUX
     91      1.36  christos #define DPRINTF(a)	uprintf a
     92      1.36  christos #else
     93      1.36  christos #define DPRINTF(a)
     94      1.36  christos #endif
     95      1.36  christos 
     96      1.37  christos extern const int native_to_linux_signo[];
     97      1.37  christos extern const int linux_to_native_signo[];
     98       1.6   mycroft 
     99      1.14       erh /*
    100      1.20     itohy  * Convert between Linux and BSD signal sets.
    101      1.14       erh  */
    102      1.20     itohy #if LINUX__NSIG_WORDS > 1
    103       1.6   mycroft void
    104      1.57       dsl linux_old_extra_to_native_sigset(sigset_t *bss, const linux_old_sigset_t *lss, const unsigned long *extra)
    105      1.20     itohy {
    106      1.20     itohy 	linux_sigset_t lsnew;
    107      1.20     itohy 
    108      1.20     itohy 	/* convert old sigset to new sigset */
    109      1.20     itohy 	linux_sigemptyset(&lsnew);
    110      1.20     itohy 	lsnew.sig[0] = *lss;
    111      1.20     itohy 	if (extra)
    112      1.33  christos 		memcpy(&lsnew.sig[1], extra,
    113      1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    114      1.20     itohy 
    115      1.33  christos 	linux_to_native_sigset(bss, &lsnew);
    116      1.20     itohy }
    117      1.20     itohy 
    118      1.20     itohy void
    119      1.57       dsl native_to_linux_old_extra_sigset(linux_old_sigset_t *lss, unsigned long *extra, const sigset_t *bss)
    120      1.20     itohy {
    121      1.20     itohy 	linux_sigset_t lsnew;
    122      1.20     itohy 
    123      1.33  christos 	native_to_linux_sigset(&lsnew, bss);
    124      1.20     itohy 
    125      1.20     itohy 	/* convert new sigset to old sigset */
    126      1.20     itohy 	*lss = lsnew.sig[0];
    127      1.20     itohy 	if (extra)
    128      1.33  christos 		memcpy(extra, &lsnew.sig[1],
    129      1.33  christos 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    130      1.20     itohy }
    131      1.43      manu #endif /* LINUX__NSIG_WORDS > 1 */
    132      1.20     itohy 
    133      1.20     itohy void
    134      1.57       dsl linux_to_native_sigset(sigset_t *bss, const linux_sigset_t *lss)
    135       1.1      fvdl {
    136       1.1      fvdl 	int i, newsig;
    137       1.1      fvdl 
    138       1.6   mycroft 	sigemptyset(bss);
    139      1.20     itohy 	for (i = 1; i < LINUX__NSIG; i++) {
    140       1.6   mycroft 		if (linux_sigismember(lss, i)) {
    141      1.37  christos 			newsig = linux_to_native_signo[i];
    142       1.1      fvdl 			if (newsig)
    143       1.6   mycroft 				sigaddset(bss, newsig);
    144       1.1      fvdl 		}
    145       1.1      fvdl 	}
    146       1.1      fvdl }
    147       1.1      fvdl 
    148       1.1      fvdl void
    149      1.57       dsl native_to_linux_sigset(linux_sigset_t *lss, const sigset_t *bss)
    150       1.1      fvdl {
    151       1.1      fvdl 	int i, newsig;
    152      1.20     itohy 
    153       1.6   mycroft 	linux_sigemptyset(lss);
    154       1.6   mycroft 	for (i = 1; i < NSIG; i++) {
    155       1.6   mycroft 		if (sigismember(bss, i)) {
    156      1.37  christos 			newsig = native_to_linux_signo[i];
    157       1.1      fvdl 			if (newsig)
    158       1.6   mycroft 				linux_sigaddset(lss, newsig);
    159       1.1      fvdl 		}
    160       1.1      fvdl 	}
    161       1.1      fvdl }
    162       1.1      fvdl 
    163  1.72.2.1      yamt void
    164  1.72.2.1      yamt native_to_linux_siginfo(linux_siginfo_t *lsi, const struct _ksiginfo *ksi)
    165  1.72.2.1      yamt {
    166  1.72.2.1      yamt 	memset(lsi, 0, sizeof(*lsi));
    167  1.72.2.1      yamt 
    168  1.72.2.1      yamt 	lsi->lsi_signo = native_to_linux_signo[ksi->_signo];
    169  1.72.2.1      yamt 	lsi->lsi_errno = native_to_linux_errno[ksi->_errno];
    170  1.72.2.1      yamt 	lsi->lsi_code = native_to_linux_si_code(ksi->_code);
    171  1.72.2.1      yamt 
    172  1.72.2.1      yamt 	switch (ksi->_code) {
    173  1.72.2.1      yamt 	case SI_NOINFO:
    174  1.72.2.1      yamt 		break;
    175  1.72.2.1      yamt 
    176  1.72.2.1      yamt 	case SI_USER:
    177  1.72.2.1      yamt 		lsi->lsi_pid = ksi->_reason._rt._pid;
    178  1.72.2.1      yamt 		lsi->lsi_uid = ksi->_reason._rt._uid;
    179  1.72.2.1      yamt 		if (lsi->lsi_signo == LINUX_SIGALRM ||
    180  1.72.2.1      yamt 		    lsi->lsi_signo >= LINUX_SIGRTMIN)
    181  1.72.2.1      yamt 			lsi->lsi_value.sival_ptr =
    182  1.72.2.1      yamt 			    ksi->_reason._rt._value.sival_ptr;
    183  1.72.2.1      yamt 		break;
    184  1.72.2.1      yamt 
    185  1.72.2.1      yamt 	case SI_TIMER:
    186  1.72.2.1      yamt 	case SI_QUEUE:
    187  1.72.2.1      yamt 		lsi->lsi_uid = ksi->_reason._rt._uid;
    188  1.72.2.1      yamt 		lsi->lsi_uid = ksi->_reason._rt._uid;
    189  1.72.2.1      yamt 		lsi->lsi_value.sival_ptr = ksi->_reason._rt._value.sival_ptr;
    190  1.72.2.1      yamt 		break;
    191  1.72.2.1      yamt 
    192  1.72.2.1      yamt 	case SI_ASYNCIO:
    193  1.72.2.1      yamt 	case SI_MESGQ:
    194  1.72.2.1      yamt 		lsi->lsi_value.sival_ptr = ksi->_reason._rt._value.sival_ptr;
    195  1.72.2.1      yamt 		break;
    196  1.72.2.1      yamt 
    197  1.72.2.1      yamt 	default:
    198  1.72.2.1      yamt 		switch (ksi->_signo) {
    199  1.72.2.1      yamt 		case SIGCHLD:
    200  1.72.2.1      yamt 			lsi->lsi_uid = ksi->_reason._child._uid;
    201  1.72.2.1      yamt 			lsi->lsi_pid = ksi->_reason._child._pid;
    202  1.72.2.1      yamt 			lsi->lsi_status = native_to_linux_si_status(
    203  1.72.2.1      yamt 			    ksi->_code, ksi->_reason._child._status);
    204  1.72.2.1      yamt 			lsi->lsi_utime = ksi->_reason._child._utime;
    205  1.72.2.1      yamt 			lsi->lsi_stime = ksi->_reason._child._stime;
    206  1.72.2.1      yamt 			break;
    207  1.72.2.1      yamt 
    208  1.72.2.1      yamt 		case SIGILL:
    209  1.72.2.1      yamt 		case SIGFPE:
    210  1.72.2.1      yamt 		case SIGSEGV:
    211  1.72.2.1      yamt 		case SIGBUS:
    212  1.72.2.1      yamt 		case SIGTRAP:
    213  1.72.2.1      yamt 			lsi->lsi_addr = ksi->_reason._fault._addr;
    214  1.72.2.1      yamt 			break;
    215  1.72.2.1      yamt 
    216  1.72.2.1      yamt 		case SIGIO:
    217  1.72.2.1      yamt 			lsi->lsi_fd = ksi->_reason._poll._fd;
    218  1.72.2.1      yamt 			lsi->lsi_band = ksi->_reason._poll._band;
    219  1.72.2.1      yamt 			break;
    220  1.72.2.1      yamt 		default:
    221  1.72.2.1      yamt 			break;
    222  1.72.2.1      yamt 		}
    223  1.72.2.1      yamt 	}
    224  1.72.2.1      yamt }
    225  1.72.2.1      yamt 
    226      1.34  christos unsigned int
    227      1.57       dsl native_to_linux_sigflags(const int bsf)
    228      1.33  christos {
    229      1.34  christos 	unsigned int lsf = 0;
    230      1.34  christos 	if ((bsf & SA_NOCLDSTOP) != 0)
    231      1.34  christos 		lsf |= LINUX_SA_NOCLDSTOP;
    232      1.34  christos 	if ((bsf & SA_NOCLDWAIT) != 0)
    233      1.34  christos 		lsf |= LINUX_SA_NOCLDWAIT;
    234      1.34  christos 	if ((bsf & SA_ONSTACK) != 0)
    235      1.34  christos 		lsf |= LINUX_SA_ONSTACK;
    236      1.34  christos 	if ((bsf & SA_RESTART) != 0)
    237      1.34  christos 		lsf |= LINUX_SA_RESTART;
    238      1.34  christos 	if ((bsf & SA_NODEFER) != 0)
    239      1.34  christos 		lsf |= LINUX_SA_NOMASK;
    240      1.34  christos 	if ((bsf & SA_RESETHAND) != 0)
    241      1.34  christos 		lsf |= LINUX_SA_ONESHOT;
    242      1.34  christos 	if ((bsf & SA_SIGINFO) != 0)
    243      1.34  christos 		lsf |= LINUX_SA_SIGINFO;
    244      1.34  christos 	return lsf;
    245      1.33  christos }
    246      1.33  christos 
    247      1.34  christos int
    248      1.57       dsl linux_to_native_sigflags(const unsigned long lsf)
    249      1.33  christos {
    250      1.34  christos 	int bsf = 0;
    251      1.34  christos 	if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
    252      1.34  christos 		bsf |= SA_NOCLDSTOP;
    253      1.34  christos 	if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
    254      1.34  christos 		bsf |= SA_NOCLDWAIT;
    255      1.34  christos 	if ((lsf & LINUX_SA_ONSTACK) != 0)
    256      1.34  christos 		bsf |= SA_ONSTACK;
    257      1.34  christos 	if ((lsf & LINUX_SA_RESTART) != 0)
    258      1.34  christos 		bsf |= SA_RESTART;
    259      1.34  christos 	if ((lsf & LINUX_SA_ONESHOT) != 0)
    260      1.34  christos 		bsf |= SA_RESETHAND;
    261      1.34  christos 	if ((lsf & LINUX_SA_NOMASK) != 0)
    262      1.34  christos 		bsf |= SA_NODEFER;
    263      1.34  christos 	if ((lsf & LINUX_SA_SIGINFO) != 0)
    264      1.34  christos 		bsf |= SA_SIGINFO;
    265      1.50  christos 	if ((lsf & ~LINUX_SA_ALLBITS) != 0) {
    266      1.36  christos 		DPRINTF(("linux_old_to_native_sigflags: "
    267      1.36  christos 		    "%lx extra bits ignored\n", lsf));
    268      1.50  christos 	}
    269      1.34  christos 	return bsf;
    270      1.33  christos }
    271      1.33  christos 
    272       1.1      fvdl /*
    273      1.46      manu  * Convert between Linux and BSD sigaction structures.
    274       1.1      fvdl  */
    275       1.1      fvdl void
    276      1.57       dsl linux_old_to_native_sigaction(struct sigaction *bsa, const struct linux_old_sigaction *lsa)
    277      1.14       erh {
    278      1.39  christos 	bsa->sa_handler = lsa->linux_sa_handler;
    279      1.39  christos 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    280      1.39  christos 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    281      1.14       erh }
    282      1.14       erh 
    283      1.14       erh void
    284      1.57       dsl native_to_linux_old_sigaction(struct linux_old_sigaction *lsa, const struct sigaction *bsa)
    285      1.14       erh {
    286      1.39  christos 	lsa->linux_sa_handler = bsa->sa_handler;
    287      1.39  christos 	native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    288      1.39  christos 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    289      1.34  christos #ifndef __alpha__
    290      1.39  christos 	lsa->linux_sa_restorer = NULL;
    291      1.34  christos #endif
    292      1.14       erh }
    293      1.14       erh 
    294      1.14       erh /* ...and the new sigaction conversion funcs. */
    295      1.14       erh void
    296      1.57       dsl linux_to_native_sigaction(struct sigaction *bsa, const struct linux_sigaction *lsa)
    297       1.1      fvdl {
    298      1.39  christos 	bsa->sa_handler = lsa->linux_sa_handler;
    299      1.39  christos 	linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    300      1.39  christos 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    301       1.1      fvdl }
    302       1.1      fvdl 
    303       1.1      fvdl void
    304      1.57       dsl native_to_linux_sigaction(struct linux_sigaction *lsa, const struct sigaction *bsa)
    305       1.1      fvdl {
    306      1.39  christos 	lsa->linux_sa_handler = bsa->sa_handler;
    307      1.39  christos 	native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    308      1.39  christos 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    309      1.34  christos #ifndef __alpha__
    310      1.39  christos 	lsa->linux_sa_restorer = NULL;
    311      1.34  christos #endif
    312       1.1      fvdl }
    313       1.1      fvdl 
    314      1.14       erh /* ----------------------------------------------------------------------- */
    315       1.1      fvdl 
    316       1.1      fvdl /*
    317       1.1      fvdl  * The Linux sigaction() system call. Do the usual conversions,
    318       1.1      fvdl  * and just call sigaction(). Some flags and values are silently
    319       1.1      fvdl  * ignored (see above).
    320       1.1      fvdl  */
    321       1.1      fvdl int
    322      1.58       dsl linux_sys_rt_sigaction(struct lwp *l, const struct linux_sys_rt_sigaction_args *uap, register_t *retval)
    323       1.8   thorpej {
    324      1.58       dsl 	/* {
    325       1.1      fvdl 		syscallarg(int) signum;
    326      1.12   mycroft 		syscallarg(const struct linux_sigaction *) nsa;
    327       1.1      fvdl 		syscallarg(struct linux_sigaction *) osa;
    328      1.14       erh 		syscallarg(size_t) sigsetsize;
    329      1.58       dsl 	} */
    330      1.12   mycroft 	struct linux_sigaction nlsa, olsa;
    331      1.12   mycroft 	struct sigaction nbsa, obsa;
    332      1.25      tron 	int error, sig;
    333      1.46      manu 	void *tramp = NULL;
    334      1.46      manu 	int vers = 0;
    335      1.47       mrg #if defined __amd64__
    336      1.53        ad 	struct sigacts *ps = l->l_proc->p_sigacts;
    337      1.46      manu #endif
    338       1.1      fvdl 
    339      1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    340      1.14       erh 		return (EINVAL);
    341      1.14       erh 
    342      1.12   mycroft 	if (SCARG(uap, nsa)) {
    343      1.12   mycroft 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    344      1.12   mycroft 		if (error)
    345      1.12   mycroft 			return (error);
    346      1.33  christos 		linux_to_native_sigaction(&nbsa, &nlsa);
    347      1.12   mycroft 	}
    348      1.46      manu 
    349      1.25      tron 	sig = SCARG(uap, signum);
    350      1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    351      1.25      tron 		return (EINVAL);
    352      1.37  christos 	if (sig > 0 && !linux_to_native_signo[sig]) {
    353      1.29        tv 		/* Pretend that we did something useful for unknown signals. */
    354      1.29        tv 		obsa.sa_handler = SIG_IGN;
    355      1.29        tv 		sigemptyset(&obsa.sa_mask);
    356      1.29        tv 		obsa.sa_flags = 0;
    357      1.29        tv 	} else {
    358      1.46      manu #if defined __amd64__
    359      1.46      manu 		if (nlsa.linux_sa_flags & LINUX_SA_RESTORER) {
    360      1.46      manu 			if ((tramp = nlsa.linux_sa_restorer) != NULL)
    361      1.72       wiz 				vers = 2; /* XXX arch dependent */
    362      1.46      manu 		}
    363      1.46      manu #endif
    364      1.46      manu 
    365      1.53        ad 		error = sigaction1(l, linux_to_native_signo[sig],
    366      1.38   thorpej 		    SCARG(uap, nsa) ? &nbsa : NULL,
    367      1.38   thorpej 		    SCARG(uap, osa) ? &obsa : NULL,
    368      1.46      manu 		    tramp, vers);
    369      1.29        tv 		if (error)
    370      1.29        tv 			return (error);
    371      1.29        tv 	}
    372      1.12   mycroft 	if (SCARG(uap, osa)) {
    373      1.33  christos 		native_to_linux_sigaction(&olsa, &obsa);
    374      1.46      manu 
    375      1.46      manu #if defined __amd64__
    376      1.46      manu 		if (ps->sa_sigdesc[sig].sd_vers != 0) {
    377      1.46      manu 			olsa.linux_sa_restorer = ps->sa_sigdesc[sig].sd_tramp;
    378      1.46      manu 			olsa.linux_sa_flags |= LINUX_SA_RESTORER;
    379      1.46      manu 		}
    380      1.46      manu #endif
    381      1.46      manu 
    382      1.12   mycroft 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    383      1.12   mycroft 		if (error)
    384      1.12   mycroft 			return (error);
    385       1.1      fvdl 	}
    386      1.12   mycroft 	return (0);
    387       1.1      fvdl }
    388       1.1      fvdl 
    389       1.1      fvdl int
    390      1.57       dsl linux_sigprocmask1(struct lwp *l, int how, const linux_old_sigset_t *set, linux_old_sigset_t *oset)
    391       1.8   thorpej {
    392      1.53        ad 	struct proc *p = l->l_proc;
    393      1.14       erh 	linux_old_sigset_t nlss, olss;
    394      1.12   mycroft 	sigset_t nbss, obss;
    395      1.12   mycroft 	int error;
    396       1.1      fvdl 
    397      1.17       erh 	switch (how) {
    398       1.1      fvdl 	case LINUX_SIG_BLOCK:
    399      1.12   mycroft 		how = SIG_BLOCK;
    400       1.1      fvdl 		break;
    401       1.1      fvdl 	case LINUX_SIG_UNBLOCK:
    402      1.12   mycroft 		how = SIG_UNBLOCK;
    403       1.1      fvdl 		break;
    404       1.1      fvdl 	case LINUX_SIG_SETMASK:
    405      1.12   mycroft 		how = SIG_SETMASK;
    406       1.1      fvdl 		break;
    407       1.1      fvdl 	default:
    408      1.12   mycroft 		return (EINVAL);
    409       1.1      fvdl 	}
    410       1.1      fvdl 
    411      1.17       erh 	if (set) {
    412      1.17       erh 		error = copyin(set, &nlss, sizeof(nlss));
    413      1.12   mycroft 		if (error)
    414      1.12   mycroft 			return (error);
    415      1.33  christos 		linux_old_to_native_sigset(&nbss, &nlss);
    416      1.12   mycroft 	}
    417      1.61        ad 	mutex_enter(p->p_lock);
    418      1.53        ad 	error = sigprocmask1(l, how,
    419      1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    420      1.61        ad 	mutex_exit(p->p_lock);
    421      1.12   mycroft 	if (error)
    422      1.42     perry 		return (error);
    423      1.17       erh 	if (oset) {
    424      1.33  christos 		native_to_linux_old_sigset(&olss, &obss);
    425      1.17       erh 		error = copyout(&olss, oset, sizeof(olss));
    426      1.12   mycroft 		if (error)
    427      1.12   mycroft 			return (error);
    428      1.42     perry 	}
    429      1.12   mycroft 	return (error);
    430      1.17       erh }
    431      1.17       erh 
    432      1.17       erh int
    433      1.58       dsl linux_sys_rt_sigprocmask(struct lwp *l, const struct linux_sys_rt_sigprocmask_args *uap, register_t *retval)
    434      1.17       erh {
    435      1.58       dsl 	/* {
    436      1.17       erh 		syscallarg(int) how;
    437      1.17       erh 		syscallarg(const linux_sigset_t *) set;
    438      1.17       erh 		syscallarg(linux_sigset_t *) oset;
    439      1.17       erh 		syscallarg(size_t) sigsetsize;
    440      1.58       dsl 	} */
    441      1.24      fvdl 	linux_sigset_t nlss, olss, *oset;
    442      1.24      fvdl 	const linux_sigset_t *set;
    443      1.53        ad 	struct proc *p = l->l_proc;
    444      1.24      fvdl 	sigset_t nbss, obss;
    445      1.24      fvdl 	int error, how;
    446      1.24      fvdl 
    447      1.24      fvdl 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    448      1.24      fvdl 		return (EINVAL);
    449      1.24      fvdl 
    450      1.24      fvdl 	switch (SCARG(uap, how)) {
    451      1.24      fvdl 	case LINUX_SIG_BLOCK:
    452      1.24      fvdl 		how = SIG_BLOCK;
    453      1.24      fvdl 		break;
    454      1.24      fvdl 	case LINUX_SIG_UNBLOCK:
    455      1.24      fvdl 		how = SIG_UNBLOCK;
    456      1.24      fvdl 		break;
    457      1.24      fvdl 	case LINUX_SIG_SETMASK:
    458      1.24      fvdl 		how = SIG_SETMASK;
    459      1.24      fvdl 		break;
    460      1.24      fvdl 	default:
    461      1.24      fvdl 		return (EINVAL);
    462      1.17       erh 	}
    463      1.17       erh 
    464      1.24      fvdl 	set = SCARG(uap, set);
    465      1.24      fvdl 	oset = SCARG(uap, oset);
    466      1.24      fvdl 
    467      1.24      fvdl 	if (set) {
    468      1.24      fvdl 		error = copyin(set, &nlss, sizeof(nlss));
    469      1.24      fvdl 		if (error)
    470      1.24      fvdl 			return (error);
    471      1.33  christos 		linux_to_native_sigset(&nbss, &nlss);
    472      1.24      fvdl 	}
    473      1.61        ad 	mutex_enter(p->p_lock);
    474      1.53        ad 	error = sigprocmask1(l, how,
    475      1.27      tron 	    set ? &nbss : NULL, oset ? &obss : NULL);
    476      1.61        ad 	mutex_exit(p->p_lock);
    477      1.28      tron 	if (!error && oset) {
    478      1.33  christos 		native_to_linux_sigset(&olss, &obss);
    479      1.24      fvdl 		error = copyout(&olss, oset, sizeof(olss));
    480      1.42     perry 	}
    481      1.24      fvdl 	return (error);
    482       1.1      fvdl }
    483       1.1      fvdl 
    484       1.1      fvdl int
    485      1.58       dsl linux_sys_rt_sigpending(struct lwp *l, const struct linux_sys_rt_sigpending_args *uap, register_t *retval)
    486       1.1      fvdl {
    487      1.58       dsl 	/* {
    488      1.14       erh 		syscallarg(linux_sigset_t *) set;
    489      1.14       erh 		syscallarg(size_t) sigsetsize;
    490      1.58       dsl 	} */
    491      1.12   mycroft 	sigset_t bss;
    492      1.12   mycroft 	linux_sigset_t lss;
    493       1.6   mycroft 
    494      1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    495      1.14       erh 		return (EINVAL);
    496      1.14       erh 
    497      1.53        ad 	sigpending1(l, &bss);
    498      1.33  christos 	native_to_linux_sigset(&lss, &bss);
    499      1.14       erh 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    500       1.1      fvdl }
    501      1.24      fvdl 
    502      1.43      manu #ifndef __amd64__
    503       1.1      fvdl int
    504      1.58       dsl linux_sys_sigpending(struct lwp *l, const struct linux_sys_sigpending_args *uap, register_t *retval)
    505       1.8   thorpej {
    506      1.58       dsl 	/* {
    507      1.14       erh 		syscallarg(linux_old_sigset_t *) mask;
    508      1.58       dsl 	} */
    509      1.12   mycroft 	sigset_t bss;
    510      1.14       erh 	linux_old_sigset_t lss;
    511       1.1      fvdl 
    512      1.53        ad 	sigpending1(l, &bss);
    513      1.33  christos 	native_to_linux_old_sigset(&lss, &bss);
    514      1.12   mycroft 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    515       1.1      fvdl }
    516       1.1      fvdl 
    517       1.1      fvdl int
    518      1.58       dsl linux_sys_sigsuspend(struct lwp *l, const struct linux_sys_sigsuspend_args *uap, register_t *retval)
    519       1.8   thorpej {
    520      1.58       dsl 	/* {
    521      1.54  christos 		syscallarg(void *) restart;
    522       1.3      fvdl 		syscallarg(int) oldmask;
    523       1.1      fvdl 		syscallarg(int) mask;
    524      1.58       dsl 	} */
    525      1.14       erh 	linux_old_sigset_t lss;
    526      1.14       erh 	sigset_t bss;
    527      1.14       erh 
    528      1.14       erh 	lss = SCARG(uap, mask);
    529      1.33  christos 	linux_old_to_native_sigset(&bss, &lss);
    530      1.53        ad 	return (sigsuspend1(l, &bss));
    531      1.14       erh }
    532      1.43      manu #endif /* __amd64__ */
    533      1.43      manu 
    534      1.14       erh int
    535      1.58       dsl linux_sys_rt_sigsuspend(struct lwp *l, const struct linux_sys_rt_sigsuspend_args *uap, register_t *retval)
    536      1.14       erh {
    537      1.58       dsl 	/* {
    538      1.14       erh 		syscallarg(linux_sigset_t *) unewset;
    539      1.14       erh 		syscallarg(size_t) sigsetsize;
    540      1.58       dsl 	} */
    541      1.12   mycroft 	linux_sigset_t lss;
    542      1.12   mycroft 	sigset_t bss;
    543      1.14       erh 	int error;
    544      1.14       erh 
    545      1.14       erh 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    546      1.14       erh 		return (EINVAL);
    547      1.14       erh 
    548      1.14       erh 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    549      1.14       erh 	if (error)
    550      1.14       erh 		return (error);
    551      1.14       erh 
    552      1.33  christos 	linux_to_native_sigset(&bss, &lss);
    553      1.14       erh 
    554      1.53        ad 	return (sigsuspend1(l, &bss));
    555       1.3      fvdl }
    556       1.3      fvdl 
    557  1.72.2.1      yamt static int
    558  1.72.2.1      yamt fetchss(const void *u, void *s, size_t len)
    559  1.72.2.1      yamt {
    560  1.72.2.1      yamt 	int error;
    561  1.72.2.1      yamt 	linux_sigset_t lss;
    562  1.72.2.1      yamt 
    563  1.72.2.1      yamt 	if ((error = copyin(u, &lss, sizeof(lss))) != 0)
    564  1.72.2.1      yamt 		return error;
    565  1.72.2.1      yamt 
    566  1.72.2.1      yamt 	linux_to_native_sigset(s, &lss);
    567  1.72.2.1      yamt 	return 0;
    568  1.72.2.1      yamt }
    569  1.72.2.1      yamt 
    570  1.72.2.1      yamt static int
    571  1.72.2.1      yamt fetchts(const void *u, void *s, size_t len)
    572  1.72.2.1      yamt {
    573  1.72.2.1      yamt 	int error;
    574  1.72.2.1      yamt 	struct linux_timespec lts;
    575  1.72.2.1      yamt 
    576  1.72.2.1      yamt 	if ((error = copyin(u, &lts, sizeof(lts))) != 0)
    577  1.72.2.1      yamt 		return error;
    578  1.72.2.1      yamt 
    579  1.72.2.1      yamt 	linux_to_native_timespec(s, &lts);
    580  1.72.2.1      yamt 	return 0;
    581  1.72.2.1      yamt }
    582  1.72.2.1      yamt 
    583  1.72.2.1      yamt static int
    584  1.72.2.1      yamt fakestorets(const void *u, void *s, size_t len)
    585  1.72.2.1      yamt {
    586  1.72.2.1      yamt 	/* Do nothing, sigtimedwait does not alter timeout like ours */
    587  1.72.2.1      yamt 	return 0;
    588  1.72.2.1      yamt }
    589  1.72.2.1      yamt 
    590  1.72.2.1      yamt static int
    591  1.72.2.1      yamt storeinfo(const void *s, void *u, size_t len)
    592  1.72.2.1      yamt {
    593  1.72.2.1      yamt 	struct linux_siginfo lsi;
    594  1.72.2.1      yamt 
    595  1.72.2.1      yamt 	native_to_linux_siginfo(&lsi, &((const siginfo_t *)s)->_info);
    596  1.72.2.1      yamt 	return copyout(&lsi, u, sizeof(lsi));
    597  1.72.2.1      yamt }
    598  1.72.2.1      yamt 
    599  1.72.2.1      yamt int
    600  1.72.2.1      yamt linux_sys_rt_sigtimedwait(struct lwp *l,
    601  1.72.2.1      yamt     const struct linux_sys_rt_sigtimedwait_args *uap, register_t *retval)
    602  1.72.2.1      yamt {
    603  1.72.2.1      yamt 	/* {
    604  1.72.2.1      yamt 		syscallarg(const linux_sigset_t *) set;
    605  1.72.2.1      yamt 		syscallarg(linux_siginfo_t *) info);
    606  1.72.2.1      yamt 		syscallarg(const struct linux_timespec *) timeout;
    607  1.72.2.1      yamt 	} */
    608  1.72.2.1      yamt 
    609  1.72.2.1      yamt 	return sigtimedwait1(l, (const struct sys_____sigtimedwait50_args *)uap,
    610  1.72.2.1      yamt 	    retval, fetchss, storeinfo, fetchts, fakestorets);
    611  1.72.2.1      yamt }
    612  1.72.2.1      yamt 
    613       1.3      fvdl /*
    614      1.14       erh  * Once more: only a signal conversion is needed.
    615      1.14       erh  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    616       1.3      fvdl  */
    617       1.3      fvdl int
    618      1.58       dsl linux_sys_rt_queueinfo(struct lwp *l, const struct linux_sys_rt_queueinfo_args *uap, register_t *retval)
    619      1.14       erh {
    620      1.69     njoly 	/*
    621      1.14       erh 		syscallarg(int) pid;
    622      1.14       erh 		syscallarg(int) signum;
    623      1.69     njoly 		syscallarg(linix_siginfo_t *) uinfo;
    624      1.69     njoly 	*/
    625      1.69     njoly 	int error;
    626      1.69     njoly 	linux_siginfo_t info;
    627      1.69     njoly 
    628      1.69     njoly 	error = copyin(SCARG(uap, uinfo), &info, sizeof(info));
    629      1.69     njoly 	if (error)
    630      1.69     njoly 		return error;
    631      1.69     njoly 	if (info.lsi_code >= 0)
    632      1.69     njoly 		return EPERM;
    633       1.3      fvdl 
    634      1.14       erh 	/* XXX To really implement this we need to	*/
    635      1.14       erh 	/* XXX keep a list of queued signals somewhere.	*/
    636      1.58       dsl 	return (linux_sys_kill(l, (const void *)uap, retval));
    637       1.1      fvdl }
    638       1.1      fvdl 
    639       1.1      fvdl int
    640      1.58       dsl linux_sys_kill(struct lwp *l, const struct linux_sys_kill_args *uap, register_t *retval)
    641       1.8   thorpej {
    642      1.58       dsl 	/* {
    643       1.1      fvdl 		syscallarg(int) pid;
    644       1.1      fvdl 		syscallarg(int) signum;
    645      1.58       dsl 	} */
    646      1.40   thorpej 
    647       1.9   mycroft 	struct sys_kill_args ka;
    648      1.25      tron 	int sig;
    649       1.6   mycroft 
    650       1.6   mycroft 	SCARG(&ka, pid) = SCARG(uap, pid);
    651      1.25      tron 	sig = SCARG(uap, signum);
    652      1.25      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    653      1.25      tron 		return (EINVAL);
    654      1.37  christos 	SCARG(&ka, signum) = linux_to_native_signo[sig];
    655      1.40   thorpej 	return sys_kill(l, &ka, retval);
    656       1.1      fvdl }
    657      1.30  christos 
    658      1.30  christos #ifdef LINUX_SS_ONSTACK
    659      1.56       dsl static void linux_to_native_sigaltstack(struct sigaltstack *,
    660      1.56       dsl     const struct linux_sigaltstack *);
    661      1.30  christos 
    662      1.30  christos static void
    663      1.57       dsl linux_to_native_sigaltstack(struct sigaltstack *bss, const struct linux_sigaltstack *lss)
    664      1.30  christos {
    665      1.30  christos 	bss->ss_sp = lss->ss_sp;
    666      1.30  christos 	bss->ss_size = lss->ss_size;
    667      1.30  christos 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    668      1.30  christos 	    bss->ss_flags = SS_ONSTACK;
    669      1.30  christos 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    670      1.30  christos 	    bss->ss_flags = SS_DISABLE;
    671      1.30  christos 	else
    672      1.30  christos 	    bss->ss_flags = 0;
    673      1.30  christos }
    674      1.30  christos 
    675      1.41  christos void
    676      1.57       dsl native_to_linux_sigaltstack(struct linux_sigaltstack *lss, const struct sigaltstack *bss)
    677      1.30  christos {
    678      1.30  christos 	lss->ss_sp = bss->ss_sp;
    679      1.30  christos 	lss->ss_size = bss->ss_size;
    680      1.30  christos 	if (bss->ss_flags & SS_ONSTACK)
    681      1.30  christos 	    lss->ss_flags = LINUX_SS_ONSTACK;
    682      1.30  christos 	else if (bss->ss_flags & SS_DISABLE)
    683      1.30  christos 	    lss->ss_flags = LINUX_SS_DISABLE;
    684      1.30  christos 	else
    685      1.30  christos 	    lss->ss_flags = 0;
    686      1.30  christos }
    687      1.30  christos 
    688      1.30  christos int
    689      1.58       dsl linux_sys_sigaltstack(struct lwp *l, const struct linux_sys_sigaltstack_args *uap, register_t *retval)
    690      1.30  christos {
    691      1.58       dsl 	/* {
    692      1.30  christos 		syscallarg(const struct linux_sigaltstack *) ss;
    693      1.30  christos 		syscallarg(struct linux_sigaltstack *) oss;
    694      1.58       dsl 	} */
    695      1.30  christos 	struct linux_sigaltstack ss;
    696      1.48  christos 	struct sigaltstack nss;
    697      1.53        ad 	struct proc *p = l->l_proc;
    698      1.53        ad 	int error = 0;
    699      1.30  christos 
    700      1.48  christos 	if (SCARG(uap, oss)) {
    701      1.53        ad 		native_to_linux_sigaltstack(&ss, &l->l_sigstk);
    702      1.48  christos 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    703      1.48  christos 			return error;
    704      1.48  christos 	}
    705      1.48  christos 
    706      1.30  christos 	if (SCARG(uap, ss) != NULL) {
    707      1.30  christos 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    708      1.30  christos 			return error;
    709      1.30  christos 		linux_to_native_sigaltstack(&nss, &ss);
    710      1.30  christos 
    711      1.61        ad 		mutex_enter(p->p_lock);
    712      1.53        ad 
    713      1.48  christos 		if (nss.ss_flags & ~SS_ALLBITS)
    714      1.53        ad 			error = EINVAL;
    715      1.53        ad 		else if (nss.ss_flags & SS_DISABLE) {
    716      1.53        ad 			if (l->l_sigstk.ss_flags & SS_ONSTACK)
    717      1.53        ad 				error = EINVAL;
    718      1.53        ad 		} else if (nss.ss_size < LINUX_MINSIGSTKSZ)
    719      1.53        ad 			error = ENOMEM;
    720      1.30  christos 
    721      1.53        ad 		if (error == 0)
    722      1.53        ad 			l->l_sigstk = nss;
    723      1.53        ad 
    724      1.61        ad 		mutex_exit(p->p_lock);
    725      1.30  christos 	}
    726      1.48  christos 
    727      1.53        ad 	return error;
    728      1.30  christos }
    729      1.44       jmc #endif /* LINUX_SS_ONSTACK */
    730      1.49      manu 
    731      1.65     njoly static int
    732      1.65     njoly linux_do_tkill(struct lwp *l, int tgid, int tid, int signum)
    733      1.65     njoly {
    734      1.65     njoly 	struct proc *p;
    735      1.71       chs 	struct lwp *t;
    736      1.71       chs 	ksiginfo_t ksi;
    737      1.65     njoly 	int error;
    738      1.65     njoly 
    739      1.65     njoly 	if (signum < 0 || signum >= LINUX__NSIG)
    740      1.65     njoly 		return EINVAL;
    741      1.65     njoly 	signum = linux_to_native_signo[signum];
    742      1.65     njoly 
    743      1.71       chs 	if (tgid == -1) {
    744      1.71       chs 		tgid = tid;
    745      1.71       chs 	}
    746      1.71       chs 
    747      1.65     njoly 	KSI_INIT(&ksi);
    748      1.65     njoly 	ksi.ksi_signo = signum;
    749      1.65     njoly 	ksi.ksi_code = SI_LWP;
    750      1.65     njoly 	ksi.ksi_pid = l->l_proc->p_pid;
    751      1.65     njoly 	ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
    752      1.71       chs 	ksi.ksi_lid = tid;
    753      1.65     njoly 
    754      1.65     njoly 	mutex_enter(proc_lock);
    755      1.71       chs 	p = proc_find(tgid);
    756      1.71       chs 	if (p == NULL) {
    757      1.65     njoly 		mutex_exit(proc_lock);
    758      1.65     njoly 		return ESRCH;
    759      1.65     njoly 	}
    760      1.65     njoly 	mutex_enter(p->p_lock);
    761      1.65     njoly 	error = kauth_authorize_process(l->l_cred,
    762      1.65     njoly 	    KAUTH_PROCESS_SIGNAL, p, KAUTH_ARG(signum), NULL, NULL);
    763      1.71       chs 	if ((t = lwp_find(p, ksi.ksi_lid)) == NULL)
    764      1.71       chs 		error = ESRCH;
    765      1.71       chs 	else if (signum != 0)
    766      1.65     njoly 		kpsignal2(p, &ksi);
    767      1.65     njoly 	mutex_exit(p->p_lock);
    768      1.65     njoly 	mutex_exit(proc_lock);
    769      1.65     njoly 
    770      1.65     njoly 	return error;
    771      1.65     njoly }
    772      1.65     njoly 
    773      1.49      manu int
    774      1.58       dsl linux_sys_tkill(struct lwp *l, const struct linux_sys_tkill_args *uap, register_t *retval)
    775      1.49      manu {
    776      1.58       dsl 	/* {
    777      1.49      manu 		syscallarg(int) tid;
    778      1.49      manu 		syscallarg(int) sig;
    779      1.58       dsl 	} */
    780      1.49      manu 
    781      1.65     njoly 	if (SCARG(uap, tid) <= 0)
    782      1.65     njoly 		return EINVAL;
    783      1.49      manu 
    784      1.71       chs 	return linux_do_tkill(l, -1, SCARG(uap, tid), SCARG(uap, sig));
    785      1.49      manu }
    786      1.49      manu 
    787      1.49      manu int
    788      1.58       dsl linux_sys_tgkill(struct lwp *l, const struct linux_sys_tgkill_args *uap, register_t *retval)
    789      1.49      manu {
    790      1.58       dsl 	/* {
    791      1.49      manu 		syscallarg(int) tgid;
    792      1.49      manu 		syscallarg(int) tid;
    793      1.49      manu 		syscallarg(int) sig;
    794      1.58       dsl 	} */
    795      1.49      manu 
    796      1.71       chs 	if (SCARG(uap, tid) <= 0 || SCARG(uap, tgid) < -1)
    797      1.65     njoly 		return EINVAL;
    798      1.49      manu 
    799      1.65     njoly 	return linux_do_tkill(l, SCARG(uap, tgid), SCARG(uap, tid), SCARG(uap, sig));
    800      1.49      manu }
    801      1.64     njoly 
    802      1.64     njoly int
    803      1.64     njoly native_to_linux_si_code(int code)
    804      1.64     njoly {
    805      1.64     njoly 	int si_codes[] = {
    806      1.64     njoly 	    LINUX_SI_USER, LINUX_SI_QUEUE, LINUX_SI_TIMER, LINUX_SI_ASYNCIO,
    807      1.64     njoly 	    LINUX_SI_MESGQ, LINUX_SI_TKILL /* SI_LWP */
    808      1.64     njoly 	};
    809      1.64     njoly 
    810      1.64     njoly 	if (code <= 0 && -code < __arraycount(si_codes))
    811      1.64     njoly 		return si_codes[-code];
    812      1.64     njoly 
    813      1.64     njoly 	return code;
    814      1.64     njoly }
    815      1.68     njoly 
    816      1.68     njoly int
    817      1.68     njoly native_to_linux_si_status(int code, int status)
    818      1.68     njoly {
    819      1.68     njoly 	int sts;
    820      1.68     njoly 
    821      1.68     njoly 	switch (code) {
    822      1.68     njoly 	case CLD_CONTINUED:
    823      1.68     njoly 		sts = LINUX_SIGCONT;
    824      1.68     njoly 		break;
    825      1.68     njoly 	case CLD_EXITED:
    826      1.68     njoly 		sts = WEXITSTATUS(status);
    827      1.68     njoly 		break;
    828      1.68     njoly 	case CLD_STOPPED:
    829      1.68     njoly 	case CLD_TRAPPED:
    830      1.68     njoly 	case CLD_DUMPED:
    831      1.68     njoly 	case CLD_KILLED:
    832      1.68     njoly 	default:
    833      1.68     njoly 		sts = native_to_linux_signo[WTERMSIG(status)];
    834      1.68     njoly 		break;
    835      1.68     njoly 	}
    836      1.68     njoly 
    837      1.68     njoly 	return sts;
    838      1.68     njoly }
    839