1 /* $NetBSD: netbsd32_signal.c,v 1.2 2001/11/13 02:09:07 lukem 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/cdefs.h> 32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.2 2001/11/13 02:09:07 lukem Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/malloc.h> 37 #include <sys/mount.h> 38 #include <sys/stat.h> 39 #include <sys/time.h> 40 #include <sys/signalvar.h> 41 #include <sys/proc.h> 42 43 #include <compat/netbsd32/netbsd32.h> 44 #include <compat/netbsd32/netbsd32_syscallargs.h> 45 46 int 47 netbsd32_sigaction(p, v, retval) 48 struct proc *p; 49 void *v; 50 register_t *retval; 51 { 52 struct netbsd32_sigaction_args /* { 53 syscallarg(int) signum; 54 syscallarg(const netbsd32_sigactionp_t) nsa; 55 syscallarg(netbsd32_sigactionp_t) osa; 56 } */ *uap = v; 57 struct sigaction nsa, osa; 58 struct netbsd32_sigaction *sa32p, sa32; 59 int error; 60 61 if (SCARG(uap, nsa)) { 62 sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, nsa); 63 if (copyin(sa32p, &sa32, sizeof(sa32))) 64 return EFAULT; 65 nsa.sa_handler = (void *)(u_long)sa32.sa_handler; 66 nsa.sa_mask = sa32.sa_mask; 67 nsa.sa_flags = sa32.sa_flags; 68 } 69 error = sigaction1(p, SCARG(uap, signum), 70 SCARG(uap, nsa) ? &nsa : 0, 71 SCARG(uap, osa) ? &osa : 0); 72 73 if (error) 74 return (error); 75 76 if (SCARG(uap, osa)) { 77 sa32.sa_handler = (netbsd32_sigactionp_t)(u_long)osa.sa_handler; 78 sa32.sa_mask = osa.sa_mask; 79 sa32.sa_flags = osa.sa_flags; 80 sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, osa); 81 if (copyout(&sa32, sa32p, sizeof(sa32))) 82 return EFAULT; 83 } 84 85 return (0); 86 } 87 88 int 89 netbsd32___sigaltstack14(p, v, retval) 90 struct proc *p; 91 void *v; 92 register_t *retval; 93 { 94 struct netbsd32___sigaltstack14_args /* { 95 syscallarg(const netbsd32_sigaltstackp_t) nss; 96 syscallarg(netbsd32_sigaltstackp_t) oss; 97 } */ *uap = v; 98 struct netbsd32_sigaltstack s32; 99 struct sigaltstack nss, oss; 100 int error; 101 102 if (SCARG(uap, nss)) { 103 error = copyin((caddr_t)(u_long)SCARG(uap, nss), &s32, sizeof(s32)); 104 if (error) 105 return (error); 106 nss.ss_sp = (void *)(u_long)s32.ss_sp; 107 nss.ss_size = (size_t)s32.ss_size; 108 nss.ss_flags = s32.ss_flags; 109 } 110 error = sigaltstack1(p, 111 SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0); 112 if (error) 113 return (error); 114 if (SCARG(uap, oss)) { 115 s32.ss_sp = (netbsd32_voidp)(u_long)oss.ss_sp; 116 s32.ss_size = (netbsd32_size_t)oss.ss_size; 117 s32.ss_flags = oss.ss_flags; 118 error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, oss), sizeof(s32)); 119 if (error) 120 return (error); 121 } 122 return (0); 123 } 124 125 /* ARGSUSED */ 126 int 127 netbsd32___sigaction14(p, v, retval) 128 struct proc *p; 129 void *v; 130 register_t *retval; 131 { 132 struct netbsd32___sigaction14_args /* { 133 syscallarg(int) signum; 134 syscallarg(const struct sigaction *) nsa; 135 syscallarg(struct sigaction *) osa; 136 } */ *uap = v; 137 struct netbsd32_sigaction sa32; 138 struct sigaction nsa, osa; 139 int error; 140 141 if (SCARG(uap, nsa)) { 142 error = copyin((caddr_t)(u_long)SCARG(uap, nsa), 143 &sa32, sizeof(sa32)); 144 if (error) 145 return (error); 146 nsa.sa_handler = (void *)(u_long)sa32.sa_handler; 147 nsa.sa_mask = sa32.sa_mask; 148 nsa.sa_flags = sa32.sa_flags; 149 } 150 error = sigaction1(p, SCARG(uap, signum), 151 SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0); 152 if (error) 153 return (error); 154 if (SCARG(uap, osa)) { 155 sa32.sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler; 156 sa32.sa_mask = osa.sa_mask; 157 sa32.sa_flags = osa.sa_flags; 158 error = copyout(&sa32, (caddr_t)(u_long)SCARG(uap, osa), sizeof(sa32)); 159 if (error) 160 return (error); 161 } 162 return (0); 163 } 164