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