Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_signal.c revision 1.40
      1  1.40    martin /*	$NetBSD: netbsd32_signal.c,v 1.40 2016/09/13 07:39:45 martin Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4   1.1       mrg  * Copyright (c) 1998, 2001 Matthew R. Green
      5   1.1       mrg  * All rights reserved.
      6   1.1       mrg  *
      7   1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8   1.1       mrg  * modification, are permitted provided that the following conditions
      9   1.1       mrg  * are met:
     10   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15   1.1       mrg  *
     16   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21   1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22   1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23   1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24   1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1       mrg  * SUCH DAMAGE.
     27   1.1       mrg  */
     28   1.2     lukem 
     29   1.2     lukem #include <sys/cdefs.h>
     30  1.40    martin __KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.40 2016/09/13 07:39:45 martin Exp $");
     31   1.1       mrg 
     32   1.1       mrg #include <sys/param.h>
     33   1.1       mrg #include <sys/systm.h>
     34   1.1       mrg #include <sys/mount.h>
     35   1.1       mrg #include <sys/stat.h>
     36   1.1       mrg #include <sys/time.h>
     37   1.1       mrg #include <sys/signalvar.h>
     38  1.40    martin #include <sys/ktrace.h>
     39   1.1       mrg #include <sys/proc.h>
     40   1.7      fvdl #include <sys/wait.h>
     41  1.11  christos #include <sys/dirent.h>
     42   1.7      fvdl 
     43   1.7      fvdl #include <uvm/uvm_extern.h>
     44   1.1       mrg 
     45   1.1       mrg #include <compat/netbsd32/netbsd32.h>
     46  1.10      cube #include <compat/netbsd32/netbsd32_conv.h>
     47   1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     48   1.1       mrg 
     49  1.12  christos #include <compat/sys/signal.h>
     50  1.12  christos #include <compat/sys/signalvar.h>
     51  1.13  christos #include <compat/sys/siginfo.h>
     52  1.12  christos #include <compat/sys/ucontext.h>
     53  1.25       dsl #include <compat/common/compat_sigaltstack.h>
     54  1.12  christos 
     55  1.40    martin void netbsd32_ktrpsig(int, sig_t, const sigset_t *, const ksiginfo_t *);
     56  1.14  christos 
     57   1.1       mrg int
     58  1.28       dsl netbsd32_sigaction(struct lwp *l, const struct netbsd32_sigaction_args *uap, register_t *retval)
     59   1.1       mrg {
     60  1.28       dsl 	/* {
     61   1.1       mrg 		syscallarg(int) signum;
     62   1.1       mrg 		syscallarg(const netbsd32_sigactionp_t) nsa;
     63   1.1       mrg 		syscallarg(netbsd32_sigactionp_t) osa;
     64  1.28       dsl 	} */
     65   1.1       mrg 	struct sigaction nsa, osa;
     66  1.38  christos 	struct netbsd32_sigaction13 *sa32p, sa32;
     67   1.1       mrg 	int error;
     68   1.1       mrg 
     69  1.23       dsl 	if (SCARG_P32(uap, nsa)) {
     70  1.23       dsl 		sa32p = SCARG_P32(uap, nsa);
     71   1.1       mrg 		if (copyin(sa32p, &sa32, sizeof(sa32)))
     72   1.1       mrg 			return EFAULT;
     73   1.5    atatat 		nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler);
     74  1.38  christos 		memset(&nsa.sa_mask, 0, sizeof(nsa.sa_mask));
     75  1.38  christos 		nsa.sa_mask.__bits[0] = sa32.netbsd32_sa_mask;
     76   1.5    atatat 		nsa.sa_flags = sa32.netbsd32_sa_flags;
     77   1.1       mrg 	}
     78  1.19        ad 	error = sigaction1(l, SCARG(uap, signum),
     79  1.23       dsl 			   SCARG_P32(uap, nsa) ? &nsa : 0,
     80  1.23       dsl 			   SCARG_P32(uap, osa) ? &osa : 0,
     81   1.3   thorpej 			   NULL, 0);
     82   1.8     perry 
     83   1.1       mrg 	if (error)
     84   1.1       mrg 		return (error);
     85   1.1       mrg 
     86  1.23       dsl 	if (SCARG_P32(uap, osa)) {
     87  1.22       dsl 		NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
     88  1.38  christos 		sa32.netbsd32_sa_mask = osa.sa_mask.__bits[0];
     89   1.5    atatat 		sa32.netbsd32_sa_flags = osa.sa_flags;
     90  1.23       dsl 		sa32p = SCARG_P32(uap, osa);
     91   1.1       mrg 		if (copyout(&sa32, sa32p, sizeof(sa32)))
     92   1.1       mrg 			return EFAULT;
     93   1.1       mrg 	}
     94   1.1       mrg 
     95   1.1       mrg 	return (0);
     96   1.1       mrg }
     97   1.1       mrg 
     98   1.1       mrg int
     99  1.28       dsl netbsd32___sigaltstack14(struct lwp *l, const struct netbsd32___sigaltstack14_args *uap, register_t *retval)
    100   1.1       mrg {
    101  1.28       dsl 	/* {
    102   1.1       mrg 		syscallarg(const netbsd32_sigaltstackp_t) nss;
    103   1.1       mrg 		syscallarg(netbsd32_sigaltstackp_t) oss;
    104  1.28       dsl 	} */
    105  1.25       dsl 	compat_sigaltstack(uap, netbsd32_sigaltstack, SS_ONSTACK, SS_DISABLE);
    106   1.1       mrg }
    107   1.1       mrg 
    108   1.1       mrg /* ARGSUSED */
    109   1.1       mrg int
    110  1.28       dsl netbsd32___sigaction14(struct lwp *l, const struct netbsd32___sigaction14_args *uap, register_t *retval)
    111   1.1       mrg {
    112  1.28       dsl 	/* {
    113   1.1       mrg 		syscallarg(int) signum;
    114   1.1       mrg 		syscallarg(const struct sigaction *) nsa;
    115   1.1       mrg 		syscallarg(struct sigaction *) osa;
    116  1.28       dsl 	} */
    117   1.1       mrg 	struct netbsd32_sigaction sa32;
    118   1.1       mrg 	struct sigaction nsa, osa;
    119   1.1       mrg 	int error;
    120   1.1       mrg 
    121  1.23       dsl 	if (SCARG_P32(uap, nsa)) {
    122  1.23       dsl 		error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32));
    123   1.1       mrg 		if (error)
    124   1.1       mrg 			return (error);
    125  1.22       dsl 		nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler);
    126   1.5    atatat 		nsa.sa_mask = sa32.netbsd32_sa_mask;
    127   1.5    atatat 		nsa.sa_flags = sa32.netbsd32_sa_flags;
    128   1.1       mrg 	}
    129  1.19        ad 	error = sigaction1(l, SCARG(uap, signum),
    130  1.23       dsl 		    SCARG_P32(uap, nsa) ? &nsa : 0,
    131  1.23       dsl 		    SCARG_P32(uap, osa) ? &osa : 0,
    132  1.22       dsl 		    NULL, 0);
    133   1.1       mrg 	if (error)
    134   1.1       mrg 		return (error);
    135  1.23       dsl 	if (SCARG_P32(uap, osa)) {
    136  1.22       dsl 		NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
    137   1.5    atatat 		sa32.netbsd32_sa_mask = osa.sa_mask;
    138   1.5    atatat 		sa32.netbsd32_sa_flags = osa.sa_flags;
    139  1.23       dsl 		error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32));
    140   1.4       scw 		if (error)
    141   1.4       scw 			return (error);
    142   1.4       scw 	}
    143   1.4       scw 	return (0);
    144   1.4       scw }
    145   1.4       scw 
    146   1.4       scw /* ARGSUSED */
    147   1.4       scw int
    148  1.28       dsl netbsd32___sigaction_sigtramp(struct lwp *l, const struct netbsd32___sigaction_sigtramp_args *uap, register_t *retval)
    149   1.4       scw {
    150  1.28       dsl 	/* {
    151   1.4       scw 		syscallarg(int) signum;
    152   1.4       scw 		syscallarg(const netbsd32_sigactionp_t) nsa;
    153   1.4       scw 		syscallarg(netbsd32_sigactionp_t) osa;
    154   1.4       scw 		syscallarg(netbsd32_voidp) tramp;
    155   1.4       scw 		syscallarg(int) vers;
    156  1.28       dsl 	} */
    157   1.4       scw 	struct netbsd32_sigaction sa32;
    158   1.4       scw 	struct sigaction nsa, osa;
    159   1.4       scw 	int error;
    160   1.4       scw 
    161  1.23       dsl 	if (SCARG_P32(uap, nsa)) {
    162  1.23       dsl 		error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32));
    163   1.4       scw 		if (error)
    164   1.4       scw 			return (error);
    165  1.22       dsl 		nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler);
    166   1.5    atatat 		nsa.sa_mask = sa32.netbsd32_sa_mask;
    167   1.5    atatat 		nsa.sa_flags = sa32.netbsd32_sa_flags;
    168   1.4       scw 	}
    169  1.19        ad 	error = sigaction1(l, SCARG(uap, signum),
    170  1.23       dsl 	    SCARG_P32(uap, nsa) ? &nsa : 0,
    171  1.23       dsl 	    SCARG_P32(uap, osa) ? &osa : 0,
    172  1.23       dsl 	    SCARG_P32(uap, tramp), SCARG(uap, vers));
    173   1.4       scw 	if (error)
    174   1.4       scw 		return (error);
    175  1.23       dsl 	if (SCARG_P32(uap, osa)) {
    176  1.22       dsl 		NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
    177   1.5    atatat 		sa32.netbsd32_sa_mask = osa.sa_mask;
    178   1.5    atatat 		sa32.netbsd32_sa_flags = osa.sa_flags;
    179  1.23       dsl 		error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32));
    180   1.1       mrg 		if (error)
    181   1.1       mrg 			return (error);
    182   1.1       mrg 	}
    183   1.1       mrg 	return (0);
    184   1.7      fvdl }
    185   1.7      fvdl 
    186  1.39    martin void
    187  1.39    martin netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32)
    188   1.7      fvdl {
    189   1.7      fvdl 	memset(si, 0, sizeof (*si));
    190  1.39    martin 	si->_signo = si32->_signo;
    191  1.39    martin 	si->_code = si32->_code;
    192  1.39    martin 	si->_errno = si32->_errno;
    193   1.7      fvdl 
    194  1.39    martin 	switch (si32->_signo) {
    195   1.7      fvdl 	case SIGILL:
    196   1.7      fvdl 	case SIGBUS:
    197   1.7      fvdl 	case SIGSEGV:
    198   1.7      fvdl 	case SIGFPE:
    199   1.7      fvdl 	case SIGTRAP:
    200  1.39    martin 		si->_reason._fault._addr = NETBSD32IPTR64(si32->_reason._fault._addr);
    201  1.39    martin 		si->_reason._fault._trap = si32->_reason._fault._trap;
    202   1.7      fvdl 		break;
    203   1.7      fvdl 	case SIGALRM:
    204   1.7      fvdl 	case SIGVTALRM:
    205   1.7      fvdl 	case SIGPROF:
    206  1.39    martin 	default:	/* see sigqueue() and kill1() */
    207  1.39    martin 		si->_reason._rt._pid = si32->_reason._rt._pid;
    208  1.39    martin 		si->_reason._rt._uid = si32->_reason._rt._uid;
    209  1.39    martin 		si->_reason._rt._value.sival_int = si32->_reason._rt._value.sival_int;
    210   1.7      fvdl 		break;
    211   1.7      fvdl 	case SIGCHLD:
    212  1.39    martin 		si->_reason._child._pid = si32->_reason._child._pid;
    213  1.39    martin 		si->_reason._child._uid = si32->_reason._child._uid;
    214  1.39    martin 		si->_reason._child._utime = si32->_reason._child._utime;
    215  1.39    martin 		si->_reason._child._stime = si32->_reason._child._stime;
    216   1.7      fvdl 		break;
    217   1.7      fvdl 	case SIGURG:
    218   1.7      fvdl 	case SIGIO:
    219  1.39    martin 		si->_reason._poll._band = si32->_reason._poll._band;
    220  1.39    martin 		si->_reason._poll._fd = si32->_reason._poll._fd;
    221   1.7      fvdl 		break;
    222   1.7      fvdl 	}
    223   1.7      fvdl }
    224   1.7      fvdl 
    225  1.40    martin static void
    226  1.40    martin netbsd32_ksi_to_ksi32(struct __ksiginfo32 *si32, const struct _ksiginfo *si)
    227  1.40    martin {
    228  1.40    martin 	memset(si32, 0, sizeof (*si32));
    229  1.40    martin 	si32->_signo = si->_signo;
    230  1.40    martin 	si32->_code = si->_code;
    231  1.40    martin 	si32->_errno = si->_errno;
    232  1.40    martin 
    233  1.40    martin 	switch (si->_signo) {
    234  1.40    martin 	case SIGILL:
    235  1.40    martin 	case SIGBUS:
    236  1.40    martin 	case SIGSEGV:
    237  1.40    martin 	case SIGFPE:
    238  1.40    martin 	case SIGTRAP:
    239  1.40    martin 		si32->_reason._fault._addr =
    240  1.40    martin 		    NETBSD32PTR32I(si->_reason._fault._addr);
    241  1.40    martin 		si32->_reason._fault._trap = si->_reason._fault._trap;
    242  1.40    martin 		break;
    243  1.40    martin 	case SIGALRM:
    244  1.40    martin 	case SIGVTALRM:
    245  1.40    martin 	case SIGPROF:
    246  1.40    martin 	default:	/* see sigqueue() and kill1() */
    247  1.40    martin 		si32->_reason._rt._pid = si->_reason._rt._pid;
    248  1.40    martin 		si32->_reason._rt._uid = si->_reason._rt._uid;
    249  1.40    martin 		si32->_reason._rt._value.sival_int = si->_reason._rt._value.sival_int;
    250  1.40    martin 		break;
    251  1.40    martin 	case SIGCHLD:
    252  1.40    martin 		si32->_reason._child._pid = si->_reason._child._pid;
    253  1.40    martin 		si32->_reason._child._uid = si->_reason._child._uid;
    254  1.40    martin 		si32->_reason._child._utime = si->_reason._child._utime;
    255  1.40    martin 		si32->_reason._child._stime = si->_reason._child._stime;
    256  1.40    martin 		break;
    257  1.40    martin 	case SIGURG:
    258  1.40    martin 	case SIGIO:
    259  1.40    martin 		si32->_reason._poll._band = si->_reason._poll._band;
    260  1.40    martin 		si32->_reason._poll._fd = si->_reason._poll._fd;
    261  1.40    martin 		break;
    262  1.40    martin 	}
    263  1.40    martin }
    264  1.40    martin 
    265  1.15       chs void
    266   1.9  drochner netbsd32_si_to_si32(siginfo32_t *si32, const siginfo_t *si)
    267   1.7      fvdl {
    268   1.7      fvdl 	memset(si32, 0, sizeof (*si32));
    269   1.7      fvdl 	si32->si_signo = si->si_signo;
    270   1.7      fvdl 	si32->si_code = si->si_code;
    271   1.7      fvdl 	si32->si_errno = si->si_errno;
    272   1.7      fvdl 
    273   1.7      fvdl 	switch (si32->si_signo) {
    274  1.17      cube 	case 0:	/* SA */
    275  1.24  christos 		si32->si_value.sival_int = si->si_value.sival_int;
    276  1.17      cube 		break;
    277   1.7      fvdl 	case SIGILL:
    278   1.7      fvdl 	case SIGBUS:
    279   1.7      fvdl 	case SIGSEGV:
    280   1.7      fvdl 	case SIGFPE:
    281   1.7      fvdl 	case SIGTRAP:
    282   1.7      fvdl 		si32->si_addr = (uint32_t)(uintptr_t)si->si_addr;
    283   1.7      fvdl 		si32->si_trap = si->si_trap;
    284   1.7      fvdl 		break;
    285   1.7      fvdl 	case SIGALRM:
    286   1.7      fvdl 	case SIGVTALRM:
    287   1.7      fvdl 	case SIGPROF:
    288  1.39    martin 	default:
    289   1.7      fvdl 		si32->si_pid = si->si_pid;
    290   1.7      fvdl 		si32->si_uid = si->si_uid;
    291  1.24  christos 		si32->si_value.sival_int = si->si_value.sival_int;
    292   1.7      fvdl 		break;
    293   1.7      fvdl 	case SIGCHLD:
    294   1.7      fvdl 		si32->si_pid = si->si_pid;
    295   1.7      fvdl 		si32->si_uid = si->si_uid;
    296   1.7      fvdl 		si32->si_status = si->si_status;
    297   1.7      fvdl 		si32->si_utime = si->si_utime;
    298   1.7      fvdl 		si32->si_stime = si->si_stime;
    299   1.7      fvdl 		break;
    300   1.7      fvdl 	case SIGURG:
    301   1.7      fvdl 	case SIGIO:
    302   1.7      fvdl 		si32->si_band = si->si_band;
    303   1.7      fvdl 		si32->si_fd = si->si_fd;
    304   1.7      fvdl 		break;
    305   1.7      fvdl 	}
    306   1.7      fvdl }
    307   1.7      fvdl 
    308   1.7      fvdl void
    309   1.7      fvdl getucontext32(struct lwp *l, ucontext32_t *ucp)
    310   1.7      fvdl {
    311  1.20      cube 	struct proc *p = l->l_proc;
    312   1.7      fvdl 
    313  1.29        ad 	KASSERT(mutex_owned(p->p_lock));
    314   1.7      fvdl 
    315   1.7      fvdl 	ucp->uc_flags = 0;
    316   1.7      fvdl 	ucp->uc_link = (uint32_t)(intptr_t)l->l_ctxlink;
    317  1.37     rmind 	ucp->uc_sigmask = l->l_sigmask;
    318   1.7      fvdl 	ucp->uc_flags |= _UC_SIGMASK;
    319   1.7      fvdl 
    320   1.7      fvdl 	/*
    321   1.7      fvdl 	 * The (unsupplied) definition of the `current execution stack'
    322   1.7      fvdl 	 * in the System V Interface Definition appears to allow returning
    323   1.7      fvdl 	 * the main context stack.
    324   1.7      fvdl 	 */
    325  1.19        ad 	if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) {
    326   1.7      fvdl 		ucp->uc_stack.ss_sp = USRSTACK32;
    327   1.7      fvdl 		ucp->uc_stack.ss_size = ctob(p->p_vmspace->vm_ssize);
    328   1.7      fvdl 		ucp->uc_stack.ss_flags = 0;	/* XXX, def. is Very Fishy */
    329   1.7      fvdl 	} else {
    330   1.7      fvdl 		/* Simply copy alternate signal execution stack. */
    331   1.7      fvdl 		ucp->uc_stack.ss_sp =
    332  1.19        ad 		    (uint32_t)(intptr_t)l->l_sigstk.ss_sp;
    333  1.19        ad 		ucp->uc_stack.ss_size = l->l_sigstk.ss_size;
    334  1.19        ad 		ucp->uc_stack.ss_flags = l->l_sigstk.ss_flags;
    335   1.7      fvdl 	}
    336   1.7      fvdl 	ucp->uc_flags |= _UC_STACK;
    337  1.29        ad 	mutex_exit(p->p_lock);
    338   1.7      fvdl 	cpu_getmcontext32(l, &ucp->uc_mcontext, &ucp->uc_flags);
    339  1.29        ad 	mutex_enter(p->p_lock);
    340   1.7      fvdl }
    341   1.7      fvdl 
    342   1.7      fvdl int
    343  1.28       dsl netbsd32_getcontext(struct lwp *l, const struct netbsd32_getcontext_args *uap, register_t *retval)
    344   1.7      fvdl {
    345  1.28       dsl 	/* {
    346   1.7      fvdl 		syscallarg(netbsd32_ucontextp) ucp;
    347  1.28       dsl 	} */
    348  1.20      cube 	struct proc *p = l->l_proc;
    349   1.7      fvdl 	ucontext32_t uc;
    350   1.7      fvdl 
    351  1.35     joerg 	memset(&uc, 0, sizeof(uc));
    352  1.35     joerg 
    353  1.29        ad 	mutex_enter(p->p_lock);
    354   1.7      fvdl 	getucontext32(l, &uc);
    355  1.29        ad 	mutex_exit(p->p_lock);
    356   1.7      fvdl 
    357  1.23       dsl 	return copyout(&uc, SCARG_P32(uap, ucp), sizeof (ucontext32_t));
    358   1.7      fvdl }
    359   1.7      fvdl 
    360   1.7      fvdl int
    361   1.7      fvdl setucontext32(struct lwp *l, const ucontext32_t *ucp)
    362   1.7      fvdl {
    363  1.20      cube 	struct proc *p = l->l_proc;
    364  1.20      cube 	int error;
    365  1.20      cube 
    366  1.29        ad 	KASSERT(mutex_owned(p->p_lock));
    367  1.20      cube 
    368  1.20      cube 	if ((ucp->uc_flags & _UC_SIGMASK) != 0) {
    369  1.20      cube 		error = sigprocmask1(l, SIG_SETMASK, &ucp->uc_sigmask, NULL);
    370  1.20      cube 		if (error != 0)
    371  1.20      cube 			return error;
    372  1.20      cube 	}
    373   1.7      fvdl 
    374  1.29        ad 	mutex_exit(p->p_lock);
    375  1.20      cube 	error = cpu_setmcontext32(l, &ucp->uc_mcontext, ucp->uc_flags);
    376  1.29        ad 	mutex_enter(p->p_lock);
    377  1.20      cube 	if (error != 0)
    378   1.7      fvdl 		return (error);
    379  1.20      cube 
    380   1.7      fvdl 	l->l_ctxlink = (void *)(intptr_t)ucp->uc_link;
    381  1.20      cube 
    382   1.7      fvdl 	/*
    383  1.20      cube 	 * If there was stack information, update whether or not we are
    384  1.20      cube 	 * still running on an alternate signal stack.
    385   1.7      fvdl 	 */
    386  1.20      cube 	if ((ucp->uc_flags & _UC_STACK) != 0) {
    387  1.20      cube 		if (ucp->uc_stack.ss_flags & SS_ONSTACK)
    388  1.20      cube 			l->l_sigstk.ss_flags |= SS_ONSTACK;
    389  1.20      cube 		else
    390  1.20      cube 			l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    391  1.20      cube 	}
    392   1.7      fvdl 
    393   1.7      fvdl 	return 0;
    394   1.7      fvdl }
    395   1.7      fvdl 
    396   1.7      fvdl /* ARGSUSED */
    397   1.7      fvdl int
    398  1.28       dsl netbsd32_setcontext(struct lwp *l, const struct netbsd32_setcontext_args *uap, register_t *retval)
    399   1.7      fvdl {
    400  1.28       dsl 	/* {
    401   1.7      fvdl 		syscallarg(netbsd32_ucontextp) ucp;
    402  1.28       dsl 	} */
    403   1.7      fvdl 	ucontext32_t uc;
    404   1.7      fvdl 	int error;
    405  1.20      cube 	struct proc *p = l->l_proc;
    406   1.7      fvdl 
    407  1.23       dsl 	error = copyin(SCARG_P32(uap, ucp), &uc, sizeof (uc));
    408  1.18  drochner 	if (error)
    409  1.18  drochner 		return (error);
    410  1.18  drochner 	if (!(uc.uc_flags & _UC_CPU))
    411  1.18  drochner 		return (EINVAL);
    412  1.29        ad 	mutex_enter(p->p_lock);
    413  1.18  drochner 	error = setucontext32(l, &uc);
    414  1.29        ad 	mutex_exit(p->p_lock);
    415  1.18  drochner 	if (error)
    416   1.7      fvdl 		return (error);
    417   1.7      fvdl 
    418   1.7      fvdl 	return (EJUSTRETURN);
    419   1.1       mrg }
    420  1.10      cube 
    421  1.10      cube static int
    422  1.10      cube netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
    423  1.10      cube {
    424  1.10      cube 	const siginfo_t *info = src;
    425  1.10      cube 	siginfo32_t info32;
    426  1.10      cube 
    427  1.10      cube 	netbsd32_si_to_si32(&info32, info);
    428  1.10      cube 
    429  1.10      cube 	return copyout(&info32, dst, sizeof(info32));
    430  1.10      cube }
    431  1.10      cube 
    432  1.10      cube static int
    433  1.10      cube netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
    434  1.10      cube {
    435  1.10      cube 	struct timespec *ts = dst;
    436  1.10      cube 	struct netbsd32_timespec ts32;
    437  1.10      cube 	int error;
    438  1.10      cube 
    439  1.10      cube 	error = copyin(src, &ts32, sizeof(ts32));
    440  1.10      cube 	if (error)
    441  1.10      cube 		return error;
    442  1.10      cube 
    443  1.10      cube 	netbsd32_to_timespec(&ts32, ts);
    444  1.10      cube 	return 0;
    445  1.10      cube }
    446  1.10      cube 
    447  1.10      cube static int
    448  1.10      cube netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
    449  1.10      cube {
    450  1.10      cube 	const struct timespec *ts = src;
    451  1.10      cube 	struct netbsd32_timespec ts32;
    452  1.10      cube 
    453  1.10      cube 	netbsd32_from_timespec(ts, &ts32);
    454  1.10      cube 
    455  1.10      cube 	return copyout(&ts32, dst, sizeof(ts32));
    456  1.10      cube }
    457  1.10      cube 
    458  1.10      cube int
    459  1.32  christos netbsd32_____sigtimedwait50(struct lwp *l, const struct netbsd32_____sigtimedwait50_args *uap, register_t *retval)
    460  1.10      cube {
    461  1.28       dsl 	/* {
    462  1.10      cube 		syscallarg(netbsd32_sigsetp_t) set;
    463  1.10      cube 		syscallarg(netbsd32_siginfop_t) info;
    464  1.32  christos 		syscallarg(netbsd32_timespec50p_t) timeout;
    465  1.28       dsl 	} */
    466  1.32  christos 	struct sys_____sigtimedwait50_args ua;
    467  1.10      cube 
    468  1.10      cube 	NETBSD32TOP_UAP(set, const sigset_t);
    469  1.10      cube 	NETBSD32TOP_UAP(info, siginfo_t);
    470  1.10      cube 	NETBSD32TOP_UAP(timeout, struct timespec);
    471  1.10      cube 
    472  1.33     pooka 	return sigtimedwait1(l, &ua, retval,
    473  1.36  christos 	    copyin,
    474  1.32  christos 	    netbsd32_sigtimedwait_put_info,
    475  1.10      cube 	    netbsd32_sigtimedwait_fetch_timeout,
    476  1.10      cube 	    netbsd32_sigtimedwait_put_timeout);
    477  1.10      cube }
    478  1.39    martin 
    479  1.39    martin int
    480  1.39    martin netbsd32_sigqueueinfo(struct lwp *l,
    481  1.39    martin     const struct netbsd32_sigqueueinfo_args *uap, register_t *retval)
    482  1.39    martin {
    483  1.39    martin 	/* {
    484  1.39    martin 		syscallarg(pid_t) pid;
    485  1.39    martin 		syscallarg(const netbsd32_siginfop_t) info;
    486  1.39    martin 	} */
    487  1.39    martin 	struct __ksiginfo32 ksi32;
    488  1.39    martin 	ksiginfo_t ksi;
    489  1.39    martin 	int error;
    490  1.39    martin 
    491  1.39    martin 	if ((error = copyin(SCARG_P32(uap, info), &ksi32,
    492  1.39    martin 	    sizeof(ksi32))) != 0)
    493  1.39    martin 		return error;
    494  1.39    martin 
    495  1.39    martin 	KSI_INIT(&ksi);
    496  1.39    martin 	netbsd32_ksi32_to_ksi(&ksi.ksi_info, &ksi32);
    497  1.39    martin 
    498  1.39    martin 	return kill1(l, SCARG(uap, pid), &ksi, retval);
    499  1.39    martin }
    500  1.40    martin 
    501  1.40    martin struct netbsd32_ktr_psig {
    502  1.40    martin 	int			signo;
    503  1.40    martin 	netbsd32_pointer_t	action;
    504  1.40    martin 	sigset_t		mask;
    505  1.40    martin 	int			code;
    506  1.40    martin 	/* and optional siginfo_t */
    507  1.40    martin };
    508  1.40    martin 
    509  1.40    martin void
    510  1.40    martin netbsd32_ktrpsig(int sig, sig_t action, const sigset_t *mask,
    511  1.40    martin 	 const ksiginfo_t *ksi)
    512  1.40    martin {
    513  1.40    martin 	struct ktrace_entry *kte;
    514  1.40    martin 	lwp_t *l = curlwp;
    515  1.40    martin 	struct {
    516  1.40    martin 		struct netbsd32_ktr_psig	kp;
    517  1.40    martin 		siginfo32_t			si;
    518  1.40    martin 	} *kbuf;
    519  1.40    martin 
    520  1.40    martin 	if (!KTRPOINT(l->l_proc, KTR_PSIG))
    521  1.40    martin 		return;
    522  1.40    martin 
    523  1.40    martin 	if (ktealloc(&kte, (void *)&kbuf, l, KTR_PSIG, sizeof(*kbuf)))
    524  1.40    martin 		return;
    525  1.40    martin 
    526  1.40    martin 	kbuf->kp.signo = (char)sig;
    527  1.40    martin 	NETBSD32PTR32(kbuf->kp.action, action);
    528  1.40    martin 	kbuf->kp.mask = *mask;
    529  1.40    martin 
    530  1.40    martin 	if (ksi) {
    531  1.40    martin 		kbuf->kp.code = KSI_TRAPCODE(ksi);
    532  1.40    martin 		(void)memset(&kbuf->si, 0, sizeof(kbuf->si));
    533  1.40    martin 		netbsd32_ksi_to_ksi32(&kbuf->si._info, &ksi->ksi_info);
    534  1.40    martin 		ktesethdrlen(kte, sizeof(*kbuf));
    535  1.40    martin 	} else {
    536  1.40    martin 		kbuf->kp.code = 0;
    537  1.40    martin 		ktesethdrlen(kte, sizeof(struct netbsd32_ktr_psig));
    538  1.40    martin 	}
    539  1.40    martin 
    540  1.40    martin 	ktraddentry(l, kte, KTA_WAITOK);
    541  1.40    martin }
    542  1.40    martin 
    543  1.40    martin 
    544