Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_signal.c revision 1.1.2.2
      1 /*	$NetBSD: netbsd32_signal.c,v 1.1.2.2 2001/02/11 19:14:16 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2001 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/malloc.h>
     34 #include <sys/mount.h>
     35 #include <sys/stat.h>
     36 #include <sys/time.h>
     37 #include <sys/signalvar.h>
     38 #include <sys/proc.h>
     39 
     40 #include <compat/netbsd32/netbsd32.h>
     41 #include <compat/netbsd32/netbsd32_syscallargs.h>
     42 
     43 int
     44 netbsd32_sigaction(p, v, retval)
     45 	struct proc *p;
     46 	void *v;
     47 	register_t *retval;
     48 {
     49 	struct netbsd32_sigaction_args /* {
     50 		syscallarg(int) signum;
     51 		syscallarg(const netbsd32_sigactionp_t) nsa;
     52 		syscallarg(netbsd32_sigactionp_t) osa;
     53 	} */ *uap = v;
     54 	struct sigaction nsa, osa;
     55 	struct netbsd32_sigaction *sa32p, sa32;
     56 	int error;
     57 
     58 	if (SCARG(uap, nsa)) {
     59 		sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, nsa);
     60 		if (copyin(sa32p, &sa32, sizeof(sa32)))
     61 			return EFAULT;
     62 		nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
     63 		nsa.sa_mask = sa32.sa_mask;
     64 		nsa.sa_flags = sa32.sa_flags;
     65 	}
     66 	error = sigaction1(p, SCARG(uap, signum),
     67 			   SCARG(uap, nsa) ? &nsa : 0,
     68 			   SCARG(uap, osa) ? &osa : 0);
     69 
     70 	if (error)
     71 		return (error);
     72 
     73 	if (SCARG(uap, osa)) {
     74 		sa32.sa_handler = (netbsd32_sigactionp_t)(u_long)osa.sa_handler;
     75 		sa32.sa_mask = osa.sa_mask;
     76 		sa32.sa_flags = osa.sa_flags;
     77 		sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, osa);
     78 		if (copyout(&sa32, sa32p, sizeof(sa32)))
     79 			return EFAULT;
     80 	}
     81 
     82 	return (0);
     83 }
     84 
     85 int
     86 netbsd32___sigaltstack14(p, v, retval)
     87 	struct proc *p;
     88 	void *v;
     89 	register_t *retval;
     90 {
     91 	struct netbsd32___sigaltstack14_args /* {
     92 		syscallarg(const netbsd32_sigaltstackp_t) nss;
     93 		syscallarg(netbsd32_sigaltstackp_t) oss;
     94 	} */ *uap = v;
     95 	struct netbsd32_sigaltstack s32;
     96 	struct sigaltstack nss, oss;
     97 	int error;
     98 
     99 	if (SCARG(uap, nss)) {
    100 		error = copyin((caddr_t)(u_long)SCARG(uap, nss), &s32, sizeof(s32));
    101 		if (error)
    102 			return (error);
    103 		nss.ss_sp = (void *)(u_long)s32.ss_sp;
    104 		nss.ss_size = (size_t)s32.ss_size;
    105 		nss.ss_flags = s32.ss_flags;
    106 	}
    107 	error = sigaltstack1(p,
    108 	    SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
    109 	if (error)
    110 		return (error);
    111 	if (SCARG(uap, oss)) {
    112 		s32.ss_sp = (netbsd32_voidp)(u_long)oss.ss_sp;
    113 		s32.ss_size = (netbsd32_size_t)oss.ss_size;
    114 		s32.ss_flags = oss.ss_flags;
    115 		error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, oss), sizeof(s32));
    116 		if (error)
    117 			return (error);
    118 	}
    119 	return (0);
    120 }
    121 
    122 /* ARGSUSED */
    123 int
    124 netbsd32___sigaction14(p, v, retval)
    125 	struct proc *p;
    126 	void *v;
    127 	register_t *retval;
    128 {
    129 	struct netbsd32___sigaction14_args /* {
    130 		syscallarg(int) signum;
    131 		syscallarg(const struct sigaction *) nsa;
    132 		syscallarg(struct sigaction *) osa;
    133 	} */ *uap = v;
    134 	struct netbsd32_sigaction sa32;
    135 	struct sigaction nsa, osa;
    136 	int error;
    137 
    138 	if (SCARG(uap, nsa)) {
    139 		error = copyin((caddr_t)(u_long)SCARG(uap, nsa),
    140 			       &sa32, sizeof(sa32));
    141 		if (error)
    142 			return (error);
    143 		nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
    144 		nsa.sa_mask = sa32.sa_mask;
    145 		nsa.sa_flags = sa32.sa_flags;
    146 	}
    147 	error = sigaction1(p, SCARG(uap, signum),
    148 	    SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0);
    149 	if (error)
    150 		return (error);
    151 	if (SCARG(uap, osa)) {
    152 		sa32.sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler;
    153 		sa32.sa_mask = osa.sa_mask;
    154 		sa32.sa_flags = osa.sa_flags;
    155 		error = copyout(&sa32, (caddr_t)(u_long)SCARG(uap, osa), sizeof(sa32));
    156 		if (error)
    157 			return (error);
    158 	}
    159 	return (0);
    160 }
    161