1 /* $NetBSD: netbsd32_signal.c,v 1.5 2002/11/27 16:44:03 atatat 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.5 2002/11/27 16:44:03 atatat 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 = 63 (struct netbsd32_sigaction *)NETBSD32PTR64(SCARG(uap, nsa)); 64 if (copyin(sa32p, &sa32, sizeof(sa32))) 65 return EFAULT; 66 nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler); 67 nsa.sa_mask = sa32.netbsd32_sa_mask; 68 nsa.sa_flags = sa32.netbsd32_sa_flags; 69 } 70 error = sigaction1(p, SCARG(uap, signum), 71 SCARG(uap, nsa) ? &nsa : 0, 72 SCARG(uap, osa) ? &osa : 0, 73 NULL, 0); 74 75 if (error) 76 return (error); 77 78 if (SCARG(uap, osa)) { 79 sa32.netbsd32_sa_handler = (netbsd32_sigactionp_t)(u_long)osa.sa_handler; 80 sa32.netbsd32_sa_mask = osa.sa_mask; 81 sa32.netbsd32_sa_flags = osa.sa_flags; 82 sa32p = 83 (struct netbsd32_sigaction *)NETBSD32PTR64(SCARG(uap, osa)); 84 if (copyout(&sa32, sa32p, sizeof(sa32))) 85 return EFAULT; 86 } 87 88 return (0); 89 } 90 91 int 92 netbsd32___sigaltstack14(p, v, retval) 93 struct proc *p; 94 void *v; 95 register_t *retval; 96 { 97 struct netbsd32___sigaltstack14_args /* { 98 syscallarg(const netbsd32_sigaltstackp_t) nss; 99 syscallarg(netbsd32_sigaltstackp_t) oss; 100 } */ *uap = v; 101 struct netbsd32_sigaltstack s32; 102 struct sigaltstack nss, oss; 103 int error; 104 105 if (SCARG(uap, nss)) { 106 error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, nss)), &s32, 107 sizeof(s32)); 108 if (error) 109 return (error); 110 nss.ss_sp = (void *)NETBSD32PTR64(s32.ss_sp); 111 nss.ss_size = (size_t)s32.ss_size; 112 nss.ss_flags = s32.ss_flags; 113 } 114 error = sigaltstack1(p, 115 SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0); 116 if (error) 117 return (error); 118 if (SCARG(uap, oss)) { 119 s32.ss_sp = (netbsd32_voidp)(u_long)oss.ss_sp; 120 s32.ss_size = (netbsd32_size_t)oss.ss_size; 121 s32.ss_flags = oss.ss_flags; 122 error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, oss)), 123 sizeof(s32)); 124 if (error) 125 return (error); 126 } 127 return (0); 128 } 129 130 /* ARGSUSED */ 131 int 132 netbsd32___sigaction14(p, v, retval) 133 struct proc *p; 134 void *v; 135 register_t *retval; 136 { 137 struct netbsd32___sigaction14_args /* { 138 syscallarg(int) signum; 139 syscallarg(const struct sigaction *) nsa; 140 syscallarg(struct sigaction *) osa; 141 } */ *uap = v; 142 struct netbsd32_sigaction sa32; 143 struct sigaction nsa, osa; 144 int error; 145 146 if (SCARG(uap, nsa)) { 147 error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, nsa)), &sa32, 148 sizeof(sa32)); 149 if (error) 150 return (error); 151 nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler); 152 nsa.sa_mask = sa32.netbsd32_sa_mask; 153 nsa.sa_flags = sa32.netbsd32_sa_flags; 154 } 155 error = sigaction1(p, SCARG(uap, signum), 156 SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0, 157 NULL, 0); 158 if (error) 159 return (error); 160 if (SCARG(uap, osa)) { 161 sa32.netbsd32_sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler; 162 sa32.netbsd32_sa_mask = osa.sa_mask; 163 sa32.netbsd32_sa_flags = osa.sa_flags; 164 error = copyout(&sa32, (caddr_t)NETBSD32PTR64(SCARG(uap, osa)), 165 sizeof(sa32)); 166 if (error) 167 return (error); 168 } 169 return (0); 170 } 171 172 /* ARGSUSED */ 173 int 174 netbsd32___sigaction_sigtramp(p, v, retval) 175 struct proc *p; 176 void *v; 177 register_t *retval; 178 { 179 struct netbsd32___sigaction_sigtramp_args /* { 180 syscallarg(int) signum; 181 syscallarg(const netbsd32_sigactionp_t) nsa; 182 syscallarg(netbsd32_sigactionp_t) osa; 183 syscallarg(netbsd32_voidp) tramp; 184 syscallarg(int) vers; 185 } */ *uap = v; 186 struct netbsd32_sigaction sa32; 187 struct sigaction nsa, osa; 188 int error; 189 190 if (SCARG(uap, nsa)) { 191 error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, nsa)), &sa32, 192 sizeof(sa32)); 193 if (error) 194 return (error); 195 nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler); 196 nsa.sa_mask = sa32.netbsd32_sa_mask; 197 nsa.sa_flags = sa32.netbsd32_sa_flags; 198 } 199 error = sigaction1(p, SCARG(uap, signum), 200 SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0, 201 NETBSD32PTR64(SCARG(uap, tramp)), SCARG(uap, vers)); 202 if (error) 203 return (error); 204 if (SCARG(uap, osa)) { 205 sa32.netbsd32_sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler; 206 sa32.netbsd32_sa_mask = osa.sa_mask; 207 sa32.netbsd32_sa_flags = osa.sa_flags; 208 error = copyout(&sa32, (caddr_t)NETBSD32PTR64(SCARG(uap, osa)), 209 sizeof(sa32)); 210 if (error) 211 return (error); 212 } 213 return (0); 214 } 215