Home | History | Annotate | Line # | Download | only in common
linux32_signal.c revision 1.19
      1  1.19  christos /*	$NetBSD: linux32_signal.c,v 1.19 2018/01/07 21:16:00 christos Exp $ */
      2   1.1      manu 
      3   1.1      manu /*-
      4   1.1      manu  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
      5   1.1      manu  *
      6   1.1      manu  * Redistribution and use in source and binary forms, with or without
      7   1.1      manu  * modification, are permitted provided that the following conditions
      8   1.1      manu  * are met:
      9   1.1      manu  * 1. Redistributions of source code must retain the above copyright
     10   1.1      manu  *    notice, this list of conditions and the following disclaimer.
     11   1.1      manu  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1      manu  *    notice, this list of conditions and the following disclaimer in the
     13   1.1      manu  *    documentation and/or other materials provided with the distribution.
     14   1.1      manu  * 3. All advertising materials mentioning features or use of this software
     15   1.1      manu  *    must display the following acknowledgement:
     16   1.1      manu  *	This product includes software developed by Emmanuel Dreyfus
     17   1.1      manu  * 4. The name of the author may not be used to endorse or promote
     18   1.1      manu  *    products derived from this software without specific prior written
     19   1.1      manu  *    permission.
     20   1.1      manu  *
     21   1.1      manu  * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
     22   1.1      manu  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     23   1.1      manu  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24   1.1      manu  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
     25   1.1      manu  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26   1.1      manu  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27   1.1      manu  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28   1.1      manu  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29   1.1      manu  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30   1.1      manu  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31   1.1      manu  * POSSIBILITY OF SUCH DAMAGE.
     32   1.1      manu  */
     33   1.6     lukem 
     34   1.6     lukem #include <sys/cdefs.h>
     35  1.19  christos __KERNEL_RCSID(0, "$NetBSD: linux32_signal.c,v 1.19 2018/01/07 21:16:00 christos Exp $");
     36   1.6     lukem 
     37   1.1      manu #include <sys/param.h>
     38   1.1      manu #include <sys/ucred.h>
     39   1.1      manu #include <sys/signalvar.h>
     40   1.1      manu #include <sys/lwp.h>
     41   1.1      manu #include <sys/time.h>
     42   1.2        ad #include <sys/proc.h>
     43  1.14  christos #include <sys/wait.h>
     44   1.1      manu 
     45   1.1      manu #include <compat/netbsd32/netbsd32.h>
     46   1.1      manu 
     47  1.17       chs #include <compat/linux/common/linux_types.h>
     48  1.14  christos #include <compat/linux/common/linux_signal.h>
     49  1.17       chs 
     50   1.1      manu #include <compat/linux32/common/linux32_types.h>
     51   1.1      manu #include <compat/linux32/common/linux32_signal.h>
     52  1.14  christos #include <compat/linux32/common/linux32_siginfo.h>
     53   1.1      manu #include <compat/linux32/linux32_syscallargs.h>
     54  1.14  christos #include <compat/linux32/common/linux32_errno.h>
     55  1.14  christos #include <compat/linux32/common/linux32_sched.h>
     56   1.1      manu 
     57   1.1      manu #define linux32_sigemptyset(s)    memset((s), 0, sizeof(*(s)))
     58   1.1      manu #define linux32_sigismember(s, n) ((s)->sig[((n) - 1) / LINUX32__NSIG_BPW]  \
     59   1.1      manu 				    & (1 << ((n) - 1) % LINUX32__NSIG_BPW))
     60   1.1      manu #define linux32_sigaddset(s, n)   ((s)->sig[((n) - 1) / LINUX32__NSIG_BPW]  \
     61   1.1      manu 				    |= (1 << ((n) - 1) % LINUX32__NSIG_BPW))
     62   1.1      manu 
     63   1.1      manu extern const int native_to_linux32_signo[];
     64   1.1      manu extern const int linux32_to_native_signo[];
     65   1.1      manu 
     66  1.10  christos #ifdef DEBUG_LINUX
     67  1.10  christos #define DPRINTF(a)      uprintf a
     68  1.10  christos #else
     69  1.10  christos #define DPRINTF(a)
     70  1.10  christos #endif
     71  1.10  christos 
     72   1.1      manu void
     73   1.5       dsl linux32_to_native_sigset(sigset_t *bss, const linux32_sigset_t *lss)
     74   1.1      manu {
     75   1.1      manu 	int i, newsig;
     76   1.1      manu 
     77   1.1      manu 	sigemptyset(bss);
     78   1.1      manu 	for (i = 1; i < LINUX32__NSIG; i++) {
     79   1.1      manu 		if (linux32_sigismember(lss, i)) {
     80   1.1      manu 			newsig = linux32_to_native_signo[i];
     81   1.1      manu 			if (newsig)
     82   1.1      manu 				sigaddset(bss, newsig);
     83   1.1      manu 		}
     84   1.1      manu 	}
     85   1.1      manu }
     86   1.1      manu 
     87   1.1      manu void
     88   1.5       dsl native_to_linux32_sigset(linux32_sigset_t *lss, const sigset_t *bss)
     89   1.1      manu {
     90   1.1      manu 	int i, newsig;
     91   1.1      manu 
     92   1.1      manu 	linux32_sigemptyset(lss);
     93   1.1      manu 	for (i = 1; i < NSIG; i++) {
     94   1.1      manu 		if (sigismember(bss, i)) {
     95   1.1      manu 			newsig = native_to_linux32_signo[i];
     96   1.1      manu 			if (newsig)
     97   1.1      manu 				linux32_sigaddset(lss, newsig);
     98   1.1      manu 		}
     99   1.1      manu 	}
    100   1.1      manu }
    101   1.1      manu 
    102  1.14  christos void
    103  1.14  christos native_to_linux32_siginfo(linux32_siginfo_t *lsi, const struct _ksiginfo *ksi)
    104  1.14  christos {
    105  1.14  christos 	memset(lsi, 0, sizeof(*lsi));
    106  1.14  christos 
    107  1.14  christos 	lsi->lsi_signo = native_to_linux32_signo[ksi->_signo];
    108  1.14  christos 	lsi->lsi_errno = native_to_linux32_errno[ksi->_errno];
    109  1.14  christos 	lsi->lsi_code = native_to_linux32_si_code(ksi->_code);
    110  1.14  christos 
    111  1.14  christos 	switch (ksi->_code) {
    112  1.14  christos 	case SI_NOINFO:
    113  1.14  christos 		break;
    114  1.14  christos 
    115  1.14  christos 	case SI_USER:
    116  1.14  christos 		lsi->lsi_pid = ksi->_reason._rt._pid;
    117  1.14  christos 		lsi->lsi_uid = ksi->_reason._rt._uid;
    118  1.14  christos 		if (lsi->lsi_signo == LINUX_SIGALRM ||
    119  1.14  christos 		    lsi->lsi_signo >= LINUX_SIGRTMIN)
    120  1.14  christos 			NETBSD32PTR32(lsi->lsi_value.sival_ptr,
    121  1.14  christos 			    ksi->_reason._rt._value.sival_ptr);
    122  1.14  christos 		break;
    123  1.14  christos 
    124  1.14  christos 	case SI_TIMER:
    125  1.14  christos 	case SI_QUEUE:
    126  1.14  christos 		lsi->lsi_uid = ksi->_reason._rt._uid;
    127  1.14  christos 		lsi->lsi_uid = ksi->_reason._rt._uid;
    128  1.14  christos 		NETBSD32PTR32(lsi->lsi_value.sival_ptr,
    129  1.14  christos 		    ksi->_reason._rt._value.sival_ptr);
    130  1.14  christos 		break;
    131  1.14  christos 
    132  1.14  christos 	case SI_ASYNCIO:
    133  1.14  christos 	case SI_MESGQ:
    134  1.14  christos 		NETBSD32PTR32(lsi->lsi_value.sival_ptr,
    135  1.14  christos 		    ksi->_reason._rt._value.sival_ptr);
    136  1.14  christos 		break;
    137  1.14  christos 
    138  1.14  christos 	default:
    139  1.14  christos 		switch (ksi->_signo) {
    140  1.14  christos 		case SIGCHLD:
    141  1.14  christos 			lsi->lsi_uid = ksi->_reason._child._uid;
    142  1.14  christos 			lsi->lsi_pid = ksi->_reason._child._pid;
    143  1.14  christos 			lsi->lsi_status = native_to_linux32_si_status(
    144  1.14  christos 			    ksi->_code, ksi->_reason._child._status);
    145  1.14  christos 			lsi->lsi_utime = ksi->_reason._child._utime;
    146  1.14  christos 			lsi->lsi_stime = ksi->_reason._child._stime;
    147  1.14  christos 			break;
    148  1.14  christos 
    149  1.14  christos 		case SIGILL:
    150  1.14  christos 		case SIGFPE:
    151  1.14  christos 		case SIGSEGV:
    152  1.14  christos 		case SIGBUS:
    153  1.14  christos 		case SIGTRAP:
    154  1.14  christos 			NETBSD32PTR32(lsi->lsi_addr, ksi->_reason._fault._addr);
    155  1.14  christos 			break;
    156  1.14  christos 
    157  1.14  christos 		case SIGIO:
    158  1.14  christos 			lsi->lsi_fd = ksi->_reason._poll._fd;
    159  1.14  christos 			lsi->lsi_band = ksi->_reason._poll._band;
    160  1.14  christos 			break;
    161  1.14  christos 		default:
    162  1.14  christos 			break;
    163  1.14  christos 		}
    164  1.14  christos 	}
    165  1.14  christos }
    166  1.14  christos 
    167   1.1      manu unsigned int
    168   1.5       dsl native_to_linux32_sigflags(const int bsf)
    169   1.1      manu {
    170   1.1      manu 	unsigned int lsf = 0;
    171   1.1      manu 	if ((bsf & SA_NOCLDSTOP) != 0)
    172   1.1      manu 		lsf |= LINUX32_SA_NOCLDSTOP;
    173   1.1      manu 	if ((bsf & SA_NOCLDWAIT) != 0)
    174   1.1      manu 		lsf |= LINUX32_SA_NOCLDWAIT;
    175   1.1      manu 	if ((bsf & SA_ONSTACK) != 0)
    176   1.1      manu 		lsf |= LINUX32_SA_ONSTACK;
    177   1.1      manu 	if ((bsf & SA_RESTART) != 0)
    178   1.1      manu 		lsf |= LINUX32_SA_RESTART;
    179   1.1      manu 	if ((bsf & SA_NODEFER) != 0)
    180   1.1      manu 		lsf |= LINUX32_SA_NOMASK;
    181   1.1      manu 	if ((bsf & SA_RESETHAND) != 0)
    182   1.1      manu 		lsf |= LINUX32_SA_ONESHOT;
    183   1.1      manu 	if ((bsf & SA_SIGINFO) != 0)
    184   1.1      manu 		lsf |= LINUX32_SA_SIGINFO;
    185   1.1      manu 	return lsf;
    186   1.1      manu }
    187   1.1      manu 
    188   1.1      manu int
    189   1.5       dsl linux32_to_native_sigflags(const unsigned long lsf)
    190   1.1      manu {
    191   1.1      manu 	int bsf = 0;
    192   1.1      manu 	if ((lsf & LINUX32_SA_NOCLDSTOP) != 0)
    193   1.1      manu 		bsf |= SA_NOCLDSTOP;
    194   1.1      manu 	if ((lsf & LINUX32_SA_NOCLDWAIT) != 0)
    195   1.1      manu 		bsf |= SA_NOCLDWAIT;
    196   1.1      manu 	if ((lsf & LINUX32_SA_ONSTACK) != 0)
    197   1.1      manu 		bsf |= SA_ONSTACK;
    198   1.1      manu 	if ((lsf & LINUX32_SA_RESTART) != 0)
    199   1.1      manu 		bsf |= SA_RESTART;
    200   1.1      manu 	if ((lsf & LINUX32_SA_ONESHOT) != 0)
    201   1.1      manu 		bsf |= SA_RESETHAND;
    202   1.1      manu 	if ((lsf & LINUX32_SA_NOMASK) != 0)
    203   1.1      manu 		bsf |= SA_NODEFER;
    204   1.1      manu 	if ((lsf & LINUX32_SA_SIGINFO) != 0)
    205   1.1      manu 		bsf |= SA_SIGINFO;
    206   1.1      manu 	if ((lsf & ~LINUX32_SA_ALLBITS) != 0) {
    207   1.1      manu #ifdef DEBUG_LINUX
    208   1.1      manu 		printf("linux32_old_to_native_sigflags: "
    209   1.1      manu 		    "%lx extra bits ignored\n", lsf);
    210   1.1      manu #endif
    211   1.1      manu 	}
    212   1.1      manu 	return bsf;
    213   1.1      manu }
    214   1.1      manu 
    215   1.1      manu void
    216   1.5       dsl linux32_to_native_sigaction(struct sigaction *bsa, const struct linux32_sigaction *lsa)
    217   1.1      manu {
    218   1.1      manu 	bsa->sa_handler = NETBSD32PTR64(lsa->linux_sa_handler);
    219   1.1      manu 	linux32_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    220   1.1      manu 	bsa->sa_flags = linux32_to_native_sigflags(lsa->linux_sa_flags);
    221   1.1      manu }
    222   1.1      manu 
    223   1.1      manu void
    224   1.5       dsl native_to_linux32_sigaction(struct linux32_sigaction *lsa, const struct sigaction *bsa)
    225   1.1      manu {
    226   1.3       dsl 	NETBSD32PTR32(lsa->linux_sa_handler, bsa->sa_handler);
    227   1.1      manu 	native_to_linux32_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    228   1.1      manu 	lsa->linux_sa_flags = native_to_linux32_sigflags(bsa->sa_flags);
    229   1.3       dsl 	NETBSD32PTR32(lsa->linux_sa_restorer, NULL);
    230   1.1      manu }
    231   1.1      manu 
    232   1.1      manu void
    233   1.5       dsl native_to_linux32_sigaltstack(struct linux32_sigaltstack *lss, const struct sigaltstack *bss)
    234   1.1      manu {
    235   1.3       dsl 	NETBSD32PTR32(lss->ss_sp, bss->ss_sp);
    236   1.1      manu 	lss->ss_size = bss->ss_size;
    237   1.1      manu 	if (bss->ss_flags & SS_ONSTACK)
    238   1.1      manu 	    lss->ss_flags = LINUX32_SS_ONSTACK;
    239   1.1      manu 	else if (bss->ss_flags & SS_DISABLE)
    240   1.1      manu 	    lss->ss_flags = LINUX32_SS_DISABLE;
    241   1.1      manu 	else
    242   1.1      manu 	    lss->ss_flags = 0;
    243   1.1      manu }
    244   1.1      manu 
    245   1.1      manu 
    246   1.1      manu void
    247   1.5       dsl native_to_linux32_old_sigset(linux32_old_sigset_t *lss, const sigset_t *bss)
    248   1.1      manu {
    249   1.1      manu 	linux32_sigset_t lsnew;
    250   1.1      manu 
    251   1.1      manu 	native_to_linux32_sigset(&lsnew, bss);
    252   1.1      manu 
    253   1.1      manu 	/* convert new sigset to old sigset */
    254   1.1      manu 	*lss = lsnew.sig[0];
    255   1.1      manu }
    256   1.1      manu 
    257   1.1      manu void
    258   1.5       dsl linux32_old_to_native_sigset(sigset_t *bss, const linux32_old_sigset_t *lss)
    259   1.1      manu {
    260   1.1      manu 	linux32_sigset_t ls;
    261   1.1      manu 
    262  1.11    cegger 	memset(&ls, 0, sizeof(ls));
    263   1.1      manu 	ls.sig[0] = *lss;
    264   1.1      manu 
    265   1.1      manu 	linux32_to_native_sigset(bss, &ls);
    266   1.1      manu }
    267   1.1      manu 
    268   1.1      manu int
    269   1.7       dsl linux32_sys_rt_sigaction(struct lwp *l, const struct linux32_sys_rt_sigaction_args *uap, register_t *retval)
    270   1.1      manu {
    271   1.7       dsl 	/* {
    272   1.1      manu 		syscallarg(int) signum;
    273   1.1      manu 		syscallarg(const linux32_sigactionp_t) nsa;
    274   1.1      manu 		syscallarg(linux32_sigactionp_t) osa;
    275   1.1      manu 		syscallarg(netbsd32_size_t) sigsetsize;
    276   1.7       dsl 	} */
    277   1.1      manu 	struct linux32_sigaction nls32;
    278   1.1      manu 	struct linux32_sigaction ols32;
    279   1.1      manu 	struct sigaction ns;
    280   1.1      manu 	struct sigaction os;
    281   1.1      manu 	int error;
    282   1.1      manu 	int sig;
    283   1.1      manu 	int vers = 0;
    284   1.1      manu 	void *tramp = NULL;
    285   1.1      manu 
    286  1.10  christos 	if (SCARG(uap, sigsetsize) != sizeof(linux32_sigset_t)) {
    287  1.10  christos 		DPRINTF(("rt_sigaction: Inconsistent sigsetsize %u %zu\n",
    288  1.10  christos 		    SCARG(uap, sigsetsize), sizeof(linux32_sigset_t)));
    289   1.1      manu 		return EINVAL;
    290  1.10  christos 	}
    291   1.1      manu 
    292   1.4       dsl 	if (SCARG_P32(uap, nsa) != NULL) {
    293   1.4       dsl 		if ((error = copyin(SCARG_P32(uap, nsa),
    294  1.10  christos 		    &nls32, sizeof(nls32))) != 0) {
    295  1.10  christos 			DPRINTF(("rt_sigaction: Copyin %d\n", error));
    296   1.1      manu 			return error;
    297  1.10  christos 		}
    298   1.1      manu 		linux32_to_native_sigaction(&ns, &nls32);
    299   1.1      manu 	}
    300   1.1      manu 
    301   1.1      manu 	sig = SCARG(uap, signum);
    302  1.19  christos 	/*
    303  1.19  christos 	 * XXX: Linux has 33 realtime signals, the go binary wants to
    304  1.19  christos 	 * reset all of them; nothing else uses the last RT signal, so for
    305  1.19  christos 	 * now ignore it.
    306  1.19  christos 	 */
    307  1.19  christos 	if (sig == LINUX__NSIG) {
    308  1.19  christos 		uprintf("%s: setting signal %d ignored\n", __func__, sig);
    309  1.19  christos 		sig--;	/* back to 63 which is ignored */
    310  1.19  christos 	}
    311  1.10  christos 	if (sig < 0 || sig >= LINUX32__NSIG) {
    312  1.10  christos 		DPRINTF(("rt_sigaction: Bad signal number %d %d\n",
    313  1.10  christos 		    sig, LINUX32__NSIG));
    314   1.1      manu 		return EINVAL;
    315  1.10  christos 	}
    316   1.1      manu 	if (sig > 0 && !linux32_to_native_signo[sig]) {
    317   1.1      manu 		/* unknown signal... */
    318   1.1      manu 		os.sa_handler = SIG_IGN;
    319   1.1      manu 		sigemptyset(&os.sa_mask);
    320   1.1      manu 		os.sa_flags = 0;
    321   1.1      manu 	} else {
    322   1.2        ad 		if ((error = sigaction1(l,
    323   1.1      manu 		    linux32_to_native_signo[sig],
    324   1.4       dsl 		    SCARG_P32(uap, nsa) ? &ns : NULL,
    325   1.4       dsl 		    SCARG_P32(uap, osa) ? &os : NULL,
    326  1.10  christos 		    tramp, vers)) != 0) {
    327  1.10  christos 			DPRINTF(("rt_sigaction: sigaction %d\n", error));
    328   1.1      manu 			return error;
    329  1.10  christos 		}
    330   1.1      manu 	}
    331   1.1      manu 
    332   1.4       dsl 	if (SCARG_P32(uap, osa) != NULL) {
    333   1.1      manu 		native_to_linux32_sigaction(&ols32, &os);
    334   1.1      manu 
    335   1.4       dsl 		if ((error = copyout(&ols32, SCARG_P32(uap, osa),
    336  1.10  christos 		    sizeof(ols32))) != 0) {
    337  1.10  christos 			DPRINTF(("rt_sigaction: Copyout %d\n", error));
    338   1.1      manu 			return error;
    339  1.10  christos 		}
    340   1.1      manu 	}
    341   1.1      manu 
    342   1.1      manu 	return 0;
    343   1.1      manu }
    344   1.1      manu 
    345   1.1      manu int
    346   1.7       dsl linux32_sys_rt_sigprocmask(struct lwp *l, const struct linux32_sys_rt_sigprocmask_args *uap, register_t *retval)
    347   1.1      manu {
    348   1.7       dsl 	/* {
    349   1.1      manu 		syscallarg(int) how;
    350   1.1      manu 		syscallarg(const linux32_sigsetp_t) set;
    351   1.1      manu 		syscallarg(linux32_sigsetp_t) oset;
    352   1.1      manu 		syscallarg(netbsd32_size_t) sigsetsize;
    353   1.7       dsl 	} */
    354   1.1      manu 	struct proc *p = l->l_proc;
    355   1.1      manu 	linux32_sigset_t nls32, ols32;
    356   1.1      manu 	sigset_t ns, os;
    357   1.1      manu 	int error;
    358   1.1      manu 	int how;
    359   1.1      manu 
    360   1.1      manu 	if (SCARG(uap, sigsetsize) != sizeof(linux32_sigset_t))
    361   1.1      manu 		return EINVAL;
    362   1.1      manu 
    363   1.1      manu 	switch (SCARG(uap, how)) {
    364   1.1      manu 	case LINUX32_SIG_BLOCK:
    365   1.1      manu 		how = SIG_BLOCK;
    366   1.1      manu 		break;
    367   1.1      manu 	case LINUX32_SIG_UNBLOCK:
    368   1.1      manu 		how = SIG_UNBLOCK;
    369   1.1      manu 		break;
    370   1.1      manu 	case LINUX32_SIG_SETMASK:
    371   1.1      manu 		how = SIG_SETMASK;
    372   1.1      manu 		break;
    373   1.1      manu 	default:
    374   1.1      manu 		return EINVAL;
    375   1.1      manu 		break;
    376   1.1      manu 	}
    377   1.1      manu 
    378   1.4       dsl 	if (SCARG_P32(uap, set) != NULL) {
    379   1.4       dsl 		if ((error = copyin(SCARG_P32(uap, set),
    380   1.1      manu 		    &nls32, sizeof(nls32))) != 0)
    381   1.1      manu 			return error;
    382   1.1      manu 		linux32_to_native_sigset(&ns, &nls32);
    383   1.1      manu 	}
    384   1.1      manu 
    385   1.8        ad 	mutex_enter(p->p_lock);
    386   1.2        ad 	error = sigprocmask1(l, how,
    387   1.4       dsl 	    SCARG_P32(uap, set) ? &ns : NULL,
    388   1.4       dsl 	    SCARG_P32(uap, oset) ? &os : NULL);
    389   1.8        ad 	mutex_exit(p->p_lock);
    390   1.2        ad 
    391   1.2        ad         if (error != 0)
    392   1.1      manu 		return error;
    393   1.1      manu 
    394   1.4       dsl 	if (SCARG_P32(uap, oset) != NULL) {
    395   1.1      manu 		native_to_linux32_sigset(&ols32, &os);
    396   1.1      manu 		if ((error = copyout(&ols32,
    397   1.4       dsl 		    SCARG_P32(uap, oset), sizeof(ols32))) != 0)
    398   1.1      manu 			return error;
    399   1.1      manu 	}
    400   1.1      manu 
    401   1.1      manu 	return 0;
    402   1.1      manu }
    403   1.1      manu 
    404   1.1      manu int
    405   1.7       dsl linux32_sys_kill(struct lwp *l, const struct linux32_sys_kill_args *uap, register_t *retval)
    406   1.7       dsl {
    407   1.7       dsl 	/* {
    408   1.1      manu 		syscallarg(int) pid;
    409   1.1      manu 		syscallarg(int) signum;
    410   1.7       dsl 	} */
    411   1.1      manu 
    412   1.1      manu 	struct sys_kill_args ka;
    413   1.1      manu 	int sig;
    414   1.1      manu 
    415   1.1      manu 	SCARG(&ka, pid) = SCARG(uap, pid);
    416   1.1      manu 	sig = SCARG(uap, signum);
    417   1.1      manu 	if (sig < 0 || sig >= LINUX32__NSIG)
    418   1.1      manu 		return (EINVAL);
    419   1.1      manu 	SCARG(&ka, signum) = linux32_to_native_signo[sig];
    420   1.1      manu 	return sys_kill(l, &ka, retval);
    421   1.1      manu }
    422   1.1      manu 
    423   1.1      manu int
    424   1.7       dsl linux32_sys_rt_sigsuspend(struct lwp *l, const struct linux32_sys_rt_sigsuspend_args *uap, register_t *retval)
    425   1.7       dsl {
    426   1.7       dsl 	/* {
    427   1.1      manu 		syscallarg(linux32_sigsetp_t) unewset;
    428   1.1      manu                 syscallarg(netbsd32_size_t) sigsetsize;
    429   1.7       dsl 	} */
    430   1.1      manu 	linux32_sigset_t lss;
    431   1.1      manu 	sigset_t bss;
    432   1.1      manu 	int error;
    433   1.1      manu 
    434   1.1      manu 	if (SCARG(uap, sigsetsize) != sizeof(linux32_sigset_t))
    435   1.1      manu 		return EINVAL;
    436   1.1      manu 
    437   1.4       dsl 	if ((error = copyin(SCARG_P32(uap, unewset),
    438   1.1      manu 	    &lss, sizeof(linux32_sigset_t))) != 0)
    439   1.1      manu 		return error;
    440   1.1      manu 
    441   1.1      manu 	linux32_to_native_sigset(&bss, &lss);
    442   1.1      manu 
    443   1.2        ad 	return sigsuspend1(l, &bss);
    444   1.1      manu }
    445   1.1      manu 
    446  1.14  christos static int
    447  1.14  christos fetchss(const void *u, void *s, size_t len)
    448  1.14  christos {
    449  1.14  christos 	int error;
    450  1.14  christos 	linux32_sigset_t lss;
    451  1.14  christos 
    452  1.14  christos 	if ((error = copyin(u, &lss, sizeof(lss))) != 0)
    453  1.14  christos 		return error;
    454  1.14  christos 
    455  1.14  christos 	linux32_to_native_sigset(s, &lss);
    456  1.14  christos 	return 0;
    457  1.14  christos }
    458  1.14  christos 
    459  1.14  christos static int
    460  1.14  christos fetchts(const void *u, void *s, size_t len)
    461  1.14  christos {
    462  1.14  christos 	int error;
    463  1.14  christos 	struct linux32_timespec lts;
    464  1.14  christos 
    465  1.14  christos 	if ((error = copyin(u, &lts, sizeof(lts))) != 0)
    466  1.14  christos 		return error;
    467  1.14  christos 
    468  1.14  christos 	linux32_to_native_timespec(s, &lts);
    469  1.14  christos 	return 0;
    470  1.14  christos }
    471  1.14  christos 
    472  1.14  christos static int
    473  1.14  christos fakestorets(const void *u, void *s, size_t len)
    474  1.14  christos {
    475  1.14  christos 	/* Do nothing, sigtimedwait does not alter timeout like ours */
    476  1.14  christos 	return 0;
    477  1.14  christos }
    478  1.14  christos 
    479  1.14  christos static int
    480  1.14  christos storeinfo(const void *s, void *u, size_t len)
    481  1.14  christos {
    482  1.14  christos 	linux32_siginfo_t lsi;
    483  1.14  christos 
    484  1.14  christos 
    485  1.14  christos 	native_to_linux32_siginfo(&lsi, &((const siginfo_t *)s)->_info);
    486  1.14  christos 	return copyout(&lsi, u, sizeof(lsi));
    487  1.14  christos }
    488  1.14  christos 
    489  1.14  christos int
    490  1.14  christos linux32_sys_rt_sigtimedwait(struct lwp *l,
    491  1.14  christos     const struct linux32_sys_rt_sigtimedwait_args *uap, register_t *retval)
    492  1.14  christos {
    493  1.14  christos 	/* {
    494  1.14  christos 		syscallarg(const linux32_sigset_t *) set;
    495  1.14  christos 		syscallarg(linux32_siginfo_t *) info);
    496  1.14  christos 		syscallarg(const struct linux32_timespec *) timeout;
    497  1.14  christos 	} */
    498  1.16  christos 	struct sys_____sigtimedwait50_args ap;
    499  1.14  christos 
    500  1.16  christos 	SCARG(&ap, set) = SCARG_P32(uap, set);
    501  1.16  christos 	SCARG(&ap, info) = SCARG_P32(uap, info);
    502  1.16  christos 	SCARG(&ap, timeout) = SCARG_P32(uap, timeout);
    503  1.16  christos 
    504  1.16  christos 	return sigtimedwait1(l, &ap,
    505  1.14  christos 	    retval, fetchss, storeinfo, fetchts, fakestorets);
    506  1.14  christos }
    507  1.14  christos 
    508   1.1      manu int
    509   1.7       dsl linux32_sys_signal(struct lwp *l, const struct linux32_sys_signal_args *uap, register_t *retval)
    510   1.1      manu {
    511   1.7       dsl 	/* {
    512   1.1      manu 		syscallarg(int) signum;
    513  1.18  christos 		syscallarg(linux32_handlerp_t) handler;
    514   1.7       dsl 	} */
    515   1.1      manu         struct sigaction nbsa, obsa;
    516   1.1      manu         int error, sig;
    517   1.1      manu 
    518   1.1      manu         *retval = -1;
    519   1.1      manu 
    520   1.1      manu         sig = SCARG(uap, signum);
    521   1.1      manu         if (sig < 0 || sig >= LINUX32__NSIG)
    522   1.1      manu                 return EINVAL;
    523   1.1      manu 
    524   1.4       dsl         nbsa.sa_handler = SCARG_P32(uap, handler);
    525   1.1      manu         sigemptyset(&nbsa.sa_mask);
    526   1.1      manu         nbsa.sa_flags = SA_RESETHAND | SA_NODEFER;
    527   1.1      manu 
    528   1.2        ad         if ((error = sigaction1(l, linux32_to_native_signo[sig],
    529   1.1      manu             &nbsa, &obsa, NULL, 0)) != 0)
    530   1.1      manu 		return error;
    531   1.1      manu 
    532   1.1      manu         *retval = (int)(long)obsa.sa_handler;
    533   1.1      manu         return 0;
    534   1.1      manu }
    535   1.9     njoly 
    536   1.9     njoly int
    537   1.9     njoly linux32_sys_rt_sigpending(struct lwp *l, const struct linux32_sys_rt_sigpending_args *uap, register_t *retval)
    538   1.9     njoly {
    539   1.9     njoly 	/* {
    540   1.9     njoly 		syscallarg(linux32_sigsetp_t) set;
    541   1.9     njoly 		syscallarg(netbsd32_size_t) sigsetsize;
    542   1.9     njoly 	} */
    543   1.9     njoly 	sigset_t bss;
    544   1.9     njoly 	linux32_sigset_t lss;
    545   1.9     njoly 
    546   1.9     njoly 	if (SCARG(uap, sigsetsize) != sizeof(linux32_sigset_t))
    547   1.9     njoly 		return EINVAL;
    548   1.9     njoly 
    549   1.9     njoly 	sigpending1(l, &bss);
    550   1.9     njoly 	native_to_linux32_sigset(&lss, &bss);
    551   1.9     njoly 	return copyout(&lss, SCARG_P32(uap, set), sizeof(lss));
    552   1.9     njoly }
    553  1.12     njoly 
    554  1.12     njoly int
    555  1.12     njoly linux32_sys_siggetmask(struct lwp *l, const void *v, register_t *retval)
    556  1.12     njoly {
    557  1.12     njoly 	struct proc *p = l->l_proc;
    558  1.12     njoly 	sigset_t bss;
    559  1.12     njoly 	linux32_old_sigset_t lss;
    560  1.12     njoly 	int error;
    561  1.12     njoly 
    562  1.12     njoly 	mutex_enter(p->p_lock);
    563  1.12     njoly 	error = sigprocmask1(l, SIG_SETMASK, 0, &bss);
    564  1.12     njoly 	mutex_exit(p->p_lock);
    565  1.12     njoly 	if (error)
    566  1.12     njoly 		return error;
    567  1.12     njoly 	native_to_linux32_old_sigset(&lss, &bss);
    568  1.12     njoly 	*retval = lss;
    569  1.12     njoly 	return 0;
    570  1.12     njoly }
    571  1.12     njoly 
    572  1.12     njoly int
    573  1.12     njoly linux32_sys_sigsetmask(struct lwp *l, const struct linux32_sys_sigsetmask_args *uap, register_t *retval)
    574  1.12     njoly {
    575  1.12     njoly 	/* {
    576  1.12     njoly 		syscallarg(linux32_old_sigset_t) mask;
    577  1.12     njoly 	} */
    578  1.12     njoly 	sigset_t nbss, obss;
    579  1.12     njoly 	linux32_old_sigset_t nlss, olss;
    580  1.12     njoly 	struct proc *p = l->l_proc;
    581  1.12     njoly 	int error;
    582  1.12     njoly 
    583  1.12     njoly 	nlss = SCARG(uap, mask);
    584  1.12     njoly 	linux32_old_to_native_sigset(&nbss, &nlss);
    585  1.12     njoly 	mutex_enter(p->p_lock);
    586  1.12     njoly 	error = sigprocmask1(l, SIG_SETMASK, &nbss, &obss);
    587  1.12     njoly 	mutex_exit(p->p_lock);
    588  1.12     njoly 	if (error)
    589  1.12     njoly 		return error;
    590  1.12     njoly 	native_to_linux32_old_sigset(&olss, &obss);
    591  1.12     njoly 	*retval = olss;
    592  1.12     njoly 	return 0;
    593  1.12     njoly }
    594  1.13     njoly 
    595  1.13     njoly int
    596  1.13     njoly linux32_sys_rt_queueinfo(struct lwp *l, const struct linux32_sys_rt_queueinfo_args *uap, register_t *retval)
    597  1.13     njoly {
    598  1.13     njoly 	/*
    599  1.13     njoly 		syscallarg(int) pid;
    600  1.13     njoly 		syscallarg(int) sig;
    601  1.13     njoly 		syscallarg(linux32_siginfop_t) uinfo;
    602  1.13     njoly 	*/
    603  1.13     njoly 	int error;
    604  1.13     njoly 	linux32_siginfo_t info;
    605  1.13     njoly 
    606  1.13     njoly 	error = copyin(SCARG_P32(uap, uinfo), &info, sizeof(info));
    607  1.13     njoly 	if (error)
    608  1.13     njoly 		return error;
    609  1.13     njoly 	if (info.lsi_code >= 0)
    610  1.13     njoly 		return EPERM;
    611  1.13     njoly 
    612  1.13     njoly 	/* XXX To really implement this we need to      */
    613  1.13     njoly 	/* XXX keep a list of queued signals somewhere. */
    614  1.13     njoly 	return linux32_sys_kill(l, (const void *)uap, retval);
    615  1.13     njoly }
    616  1.14  christos 
    617  1.14  christos int
    618  1.14  christos native_to_linux32_si_code(int code)
    619  1.14  christos {
    620  1.14  christos 	int si_codes[] = {
    621  1.14  christos 	    LINUX32_SI_USER, LINUX32_SI_QUEUE, LINUX32_SI_TIMER,
    622  1.14  christos 	    LINUX32_SI_ASYNCIO, LINUX32_SI_MESGQ, LINUX32_SI_TKILL /* SI_LWP */
    623  1.14  christos 	};
    624  1.14  christos 
    625  1.14  christos 	if (code <= 0 && -code < __arraycount(si_codes))
    626  1.14  christos 		return si_codes[-code];
    627  1.14  christos 
    628  1.14  christos 	return code;
    629  1.14  christos }
    630  1.14  christos 
    631  1.14  christos int
    632  1.14  christos native_to_linux32_si_status(int code, int status)
    633  1.14  christos {
    634  1.14  christos 	int sts;
    635  1.14  christos 
    636  1.14  christos 	switch (code) {
    637  1.14  christos 	case CLD_CONTINUED:
    638  1.14  christos 		sts = LINUX_SIGCONT;
    639  1.14  christos 		break;
    640  1.14  christos 	case CLD_EXITED:
    641  1.14  christos 		sts = WEXITSTATUS(status);
    642  1.14  christos 		break;
    643  1.14  christos 	case CLD_STOPPED:
    644  1.14  christos 	case CLD_TRAPPED:
    645  1.14  christos 	case CLD_DUMPED:
    646  1.14  christos 	case CLD_KILLED:
    647  1.14  christos 	default:
    648  1.14  christos 		sts = native_to_linux32_signo[WTERMSIG(status)];
    649  1.14  christos 		break;
    650  1.14  christos 	}
    651  1.14  christos 
    652  1.14  christos 	return sts;
    653  1.14  christos }
    654