Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_signal.c revision 1.1.4.6
      1  1.1.4.6  thorpej /*	$NetBSD: netbsd32_signal.c,v 1.1.4.6 2002/12/11 06:37:38 thorpej 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  * 3. The name of the author may not be used to endorse or promote products
     16      1.1      mrg  *    derived from this software without specific prior written permission.
     17      1.1      mrg  *
     18      1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19      1.1      mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20      1.1      mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21      1.1      mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22      1.1      mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23      1.1      mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24      1.1      mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25      1.1      mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26      1.1      mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27      1.1      mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28      1.1      mrg  * SUCH DAMAGE.
     29      1.1      mrg  */
     30  1.1.4.1  nathanw 
     31  1.1.4.1  nathanw #include <sys/cdefs.h>
     32  1.1.4.6  thorpej __KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.1.4.6 2002/12/11 06:37:38 thorpej Exp $");
     33      1.1      mrg 
     34      1.1      mrg #include <sys/param.h>
     35      1.1      mrg #include <sys/systm.h>
     36      1.1      mrg #include <sys/malloc.h>
     37      1.1      mrg #include <sys/mount.h>
     38      1.1      mrg #include <sys/stat.h>
     39      1.1      mrg #include <sys/time.h>
     40      1.1      mrg #include <sys/signalvar.h>
     41      1.1      mrg #include <sys/proc.h>
     42      1.1      mrg 
     43      1.1      mrg #include <compat/netbsd32/netbsd32.h>
     44      1.1      mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     45      1.1      mrg 
     46      1.1      mrg int
     47  1.1.4.3   petrov netbsd32_sigaction(l, v, retval)
     48  1.1.4.3   petrov 	struct lwp *l;
     49      1.1      mrg 	void *v;
     50      1.1      mrg 	register_t *retval;
     51      1.1      mrg {
     52      1.1      mrg 	struct netbsd32_sigaction_args /* {
     53      1.1      mrg 		syscallarg(int) signum;
     54      1.1      mrg 		syscallarg(const netbsd32_sigactionp_t) nsa;
     55      1.1      mrg 		syscallarg(netbsd32_sigactionp_t) osa;
     56      1.1      mrg 	} */ *uap = v;
     57      1.1      mrg 	struct sigaction nsa, osa;
     58      1.1      mrg 	struct netbsd32_sigaction *sa32p, sa32;
     59      1.1      mrg 	int error;
     60      1.1      mrg 
     61      1.1      mrg 	if (SCARG(uap, nsa)) {
     62  1.1.4.4  nathanw 		sa32p =
     63  1.1.4.4  nathanw 		    (struct netbsd32_sigaction *)NETBSD32PTR64(SCARG(uap, nsa));
     64      1.1      mrg 		if (copyin(sa32p, &sa32, sizeof(sa32)))
     65      1.1      mrg 			return EFAULT;
     66  1.1.4.6  thorpej 		nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler);
     67  1.1.4.6  thorpej 		nsa.sa_mask = sa32.netbsd32_sa_mask;
     68  1.1.4.6  thorpej 		nsa.sa_flags = sa32.netbsd32_sa_flags;
     69      1.1      mrg 	}
     70  1.1.4.3   petrov 	error = sigaction1(l->l_proc, SCARG(uap, signum),
     71      1.1      mrg 			   SCARG(uap, nsa) ? &nsa : 0,
     72  1.1.4.2  nathanw 			   SCARG(uap, osa) ? &osa : 0,
     73  1.1.4.2  nathanw 			   NULL, 0);
     74      1.1      mrg 
     75      1.1      mrg 	if (error)
     76      1.1      mrg 		return (error);
     77      1.1      mrg 
     78      1.1      mrg 	if (SCARG(uap, osa)) {
     79  1.1.4.6  thorpej 		sa32.netbsd32_sa_handler = (netbsd32_sigactionp_t)(u_long)osa.sa_handler;
     80  1.1.4.6  thorpej 		sa32.netbsd32_sa_mask = osa.sa_mask;
     81  1.1.4.6  thorpej 		sa32.netbsd32_sa_flags = osa.sa_flags;
     82  1.1.4.4  nathanw 		sa32p =
     83  1.1.4.4  nathanw 		    (struct netbsd32_sigaction *)NETBSD32PTR64(SCARG(uap, osa));
     84      1.1      mrg 		if (copyout(&sa32, sa32p, sizeof(sa32)))
     85      1.1      mrg 			return EFAULT;
     86      1.1      mrg 	}
     87      1.1      mrg 
     88      1.1      mrg 	return (0);
     89      1.1      mrg }
     90      1.1      mrg 
     91      1.1      mrg int
     92  1.1.4.3   petrov netbsd32___sigaltstack14(l, v, retval)
     93  1.1.4.3   petrov 	struct lwp *l;
     94      1.1      mrg 	void *v;
     95      1.1      mrg 	register_t *retval;
     96      1.1      mrg {
     97      1.1      mrg 	struct netbsd32___sigaltstack14_args /* {
     98      1.1      mrg 		syscallarg(const netbsd32_sigaltstackp_t) nss;
     99      1.1      mrg 		syscallarg(netbsd32_sigaltstackp_t) oss;
    100      1.1      mrg 	} */ *uap = v;
    101      1.1      mrg 	struct netbsd32_sigaltstack s32;
    102      1.1      mrg 	struct sigaltstack nss, oss;
    103      1.1      mrg 	int error;
    104      1.1      mrg 
    105      1.1      mrg 	if (SCARG(uap, nss)) {
    106  1.1.4.4  nathanw 		error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, nss)), &s32,
    107  1.1.4.4  nathanw 		    sizeof(s32));
    108      1.1      mrg 		if (error)
    109      1.1      mrg 			return (error);
    110  1.1.4.4  nathanw 		nss.ss_sp = (void *)NETBSD32PTR64(s32.ss_sp);
    111      1.1      mrg 		nss.ss_size = (size_t)s32.ss_size;
    112      1.1      mrg 		nss.ss_flags = s32.ss_flags;
    113      1.1      mrg 	}
    114  1.1.4.3   petrov 	error = sigaltstack1(l->l_proc,
    115      1.1      mrg 	    SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
    116      1.1      mrg 	if (error)
    117      1.1      mrg 		return (error);
    118      1.1      mrg 	if (SCARG(uap, oss)) {
    119      1.1      mrg 		s32.ss_sp = (netbsd32_voidp)(u_long)oss.ss_sp;
    120      1.1      mrg 		s32.ss_size = (netbsd32_size_t)oss.ss_size;
    121      1.1      mrg 		s32.ss_flags = oss.ss_flags;
    122  1.1.4.4  nathanw 		error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, oss)),
    123  1.1.4.4  nathanw 		    sizeof(s32));
    124      1.1      mrg 		if (error)
    125      1.1      mrg 			return (error);
    126      1.1      mrg 	}
    127      1.1      mrg 	return (0);
    128      1.1      mrg }
    129      1.1      mrg 
    130      1.1      mrg /* ARGSUSED */
    131      1.1      mrg int
    132  1.1.4.3   petrov netbsd32___sigaction14(l, v, retval)
    133  1.1.4.3   petrov 	struct lwp *l;
    134      1.1      mrg 	void *v;
    135      1.1      mrg 	register_t *retval;
    136      1.1      mrg {
    137      1.1      mrg 	struct netbsd32___sigaction14_args /* {
    138      1.1      mrg 		syscallarg(int) signum;
    139      1.1      mrg 		syscallarg(const struct sigaction *) nsa;
    140      1.1      mrg 		syscallarg(struct sigaction *) osa;
    141      1.1      mrg 	} */ *uap = v;
    142      1.1      mrg 	struct netbsd32_sigaction sa32;
    143      1.1      mrg 	struct sigaction nsa, osa;
    144      1.1      mrg 	int error;
    145      1.1      mrg 
    146      1.1      mrg 	if (SCARG(uap, nsa)) {
    147  1.1.4.4  nathanw 		error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, nsa)), &sa32,
    148  1.1.4.4  nathanw 		    sizeof(sa32));
    149      1.1      mrg 		if (error)
    150      1.1      mrg 			return (error);
    151  1.1.4.6  thorpej 		nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler);
    152  1.1.4.6  thorpej 		nsa.sa_mask = sa32.netbsd32_sa_mask;
    153  1.1.4.6  thorpej 		nsa.sa_flags = sa32.netbsd32_sa_flags;
    154      1.1      mrg 	}
    155  1.1.4.3   petrov 	error = sigaction1(l->l_proc, SCARG(uap, signum),
    156  1.1.4.2  nathanw 	    SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0,
    157  1.1.4.2  nathanw 	    NULL, 0);
    158      1.1      mrg 	if (error)
    159      1.1      mrg 		return (error);
    160      1.1      mrg 	if (SCARG(uap, osa)) {
    161  1.1.4.6  thorpej 		sa32.netbsd32_sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler;
    162  1.1.4.6  thorpej 		sa32.netbsd32_sa_mask = osa.sa_mask;
    163  1.1.4.6  thorpej 		sa32.netbsd32_sa_flags = osa.sa_flags;
    164  1.1.4.4  nathanw 		error = copyout(&sa32, (caddr_t)NETBSD32PTR64(SCARG(uap, osa)),
    165  1.1.4.4  nathanw 		    sizeof(sa32));
    166  1.1.4.4  nathanw 		if (error)
    167  1.1.4.4  nathanw 			return (error);
    168  1.1.4.4  nathanw 	}
    169  1.1.4.4  nathanw 	return (0);
    170  1.1.4.4  nathanw }
    171  1.1.4.4  nathanw 
    172  1.1.4.4  nathanw /* ARGSUSED */
    173  1.1.4.4  nathanw int
    174  1.1.4.5   petrov netbsd32___sigaction_sigtramp(l, v, retval)
    175  1.1.4.5   petrov 	struct lwp *l;
    176  1.1.4.4  nathanw 	void *v;
    177  1.1.4.4  nathanw 	register_t *retval;
    178  1.1.4.4  nathanw {
    179  1.1.4.4  nathanw 	struct netbsd32___sigaction_sigtramp_args /* {
    180  1.1.4.4  nathanw 		syscallarg(int) signum;
    181  1.1.4.4  nathanw 		syscallarg(const netbsd32_sigactionp_t) nsa;
    182  1.1.4.4  nathanw 		syscallarg(netbsd32_sigactionp_t) osa;
    183  1.1.4.4  nathanw 		syscallarg(netbsd32_voidp) tramp;
    184  1.1.4.4  nathanw 		syscallarg(int) vers;
    185  1.1.4.4  nathanw 	} */ *uap = v;
    186  1.1.4.5   petrov 	struct proc *p = l->l_proc;
    187  1.1.4.4  nathanw 	struct netbsd32_sigaction sa32;
    188  1.1.4.4  nathanw 	struct sigaction nsa, osa;
    189  1.1.4.4  nathanw 	int error;
    190  1.1.4.4  nathanw 
    191  1.1.4.4  nathanw 	if (SCARG(uap, nsa)) {
    192  1.1.4.4  nathanw 		error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, nsa)), &sa32,
    193  1.1.4.4  nathanw 		    sizeof(sa32));
    194  1.1.4.4  nathanw 		if (error)
    195  1.1.4.4  nathanw 			return (error);
    196  1.1.4.6  thorpej 		nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler);
    197  1.1.4.6  thorpej 		nsa.sa_mask = sa32.netbsd32_sa_mask;
    198  1.1.4.6  thorpej 		nsa.sa_flags = sa32.netbsd32_sa_flags;
    199  1.1.4.4  nathanw 	}
    200  1.1.4.4  nathanw 	error = sigaction1(p, SCARG(uap, signum),
    201  1.1.4.4  nathanw 	    SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0,
    202  1.1.4.4  nathanw 	    NETBSD32PTR64(SCARG(uap, tramp)), SCARG(uap, vers));
    203  1.1.4.4  nathanw 	if (error)
    204  1.1.4.4  nathanw 		return (error);
    205  1.1.4.4  nathanw 	if (SCARG(uap, osa)) {
    206  1.1.4.6  thorpej 		sa32.netbsd32_sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler;
    207  1.1.4.6  thorpej 		sa32.netbsd32_sa_mask = osa.sa_mask;
    208  1.1.4.6  thorpej 		sa32.netbsd32_sa_flags = osa.sa_flags;
    209  1.1.4.4  nathanw 		error = copyout(&sa32, (caddr_t)NETBSD32PTR64(SCARG(uap, osa)),
    210  1.1.4.4  nathanw 		    sizeof(sa32));
    211      1.1      mrg 		if (error)
    212      1.1      mrg 			return (error);
    213      1.1      mrg 	}
    214      1.1      mrg 	return (0);
    215      1.1      mrg }
    216