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