1 /* $NetBSD: kern_sig_13.c,v 1.5 2000/03/30 11:27:14 augustss Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 #include <sys/proc.h> 41 #include <sys/signal.h> 42 #include <sys/signalvar.h> 43 #include <sys/systm.h> 44 45 #include <sys/mount.h> 46 #include <sys/syscallargs.h> 47 48 #include <machine/limits.h> 49 50 #include <compat/common/compat_util.h> 51 52 void 53 native_sigset13_to_sigset(oss, ss) 54 const sigset13_t *oss; 55 sigset_t *ss; 56 { 57 58 ss->__bits[0] = *oss; 59 ss->__bits[1] = 0; 60 ss->__bits[2] = 0; 61 ss->__bits[3] = 0; 62 } 63 64 void 65 native_sigset_to_sigset13(ss, oss) 66 const sigset_t *ss; 67 sigset13_t *oss; 68 { 69 70 *oss = ss->__bits[0]; 71 } 72 73 void 74 native_sigaction13_to_sigaction(osa, sa) 75 const struct sigaction13 *osa; 76 struct sigaction *sa; 77 { 78 79 sa->sa_handler = osa->sa_handler; 80 native_sigset13_to_sigset(&osa->sa_mask, &sa->sa_mask); 81 sa->sa_flags = osa->sa_flags; 82 } 83 84 void 85 native_sigaction_to_sigaction13(sa, osa) 86 const struct sigaction *sa; 87 struct sigaction13 *osa; 88 { 89 90 osa->sa_handler = sa->sa_handler; 91 native_sigset_to_sigset13(&sa->sa_mask, &osa->sa_mask); 92 osa->sa_flags = sa->sa_flags; 93 } 94 95 void 96 native_sigaltstack13_to_sigaltstack(osa, sa) 97 const struct sigaltstack13 *osa; 98 struct sigaltstack *sa; 99 { 100 101 sa->ss_sp = osa->ss_sp; 102 sa->ss_size = osa->ss_size; 103 sa->ss_flags = osa->ss_flags; 104 } 105 106 void 107 native_sigaltstack_to_sigaltstack13(sa, osa) 108 const struct sigaltstack *sa; 109 struct sigaltstack13 *osa; 110 { 111 112 osa->ss_sp = sa->ss_sp; 113 osa->ss_size = sa->ss_size; 114 osa->ss_flags = sa->ss_flags; 115 } 116 117 int 118 compat_13_sys_sigaltstack(p, v, retval) 119 struct proc *p; 120 void *v; 121 register_t *retval; 122 { 123 struct compat_13_sys_sigaltstack_args /* { 124 syscallarg(const struct sigaltstack13 *) nss; 125 syscallarg(struct sigaltstack13 *) oss; 126 } */ *uap = v; 127 struct sigaltstack13 ness, oess; 128 struct sigaltstack nbss, obss; 129 int error; 130 131 if (SCARG(uap, nss)) { 132 error = copyin(SCARG(uap, nss), &ness, sizeof(ness)); 133 if (error) 134 return (error); 135 native_sigaltstack13_to_sigaltstack(&ness, &nbss); 136 } 137 error = sigaltstack1(p, 138 SCARG(uap, nss) ? &nbss : 0, SCARG(uap, oss) ? &obss : 0); 139 if (error) 140 return (error); 141 if (SCARG(uap, oss)) { 142 native_sigaltstack_to_sigaltstack13(&obss, &oess); 143 error = copyout(&oess, SCARG(uap, oss), sizeof(oess)); 144 if (error) 145 return (error); 146 } 147 return (0); 148 } 149 150 int 151 compat_13_sys_sigaction(p, v, retval) 152 struct proc *p; 153 void *v; 154 register_t *retval; 155 { 156 struct compat_13_sys_sigaction_args /* { 157 syscallarg(int) signum; 158 syscallarg(const struct sigaction13 *) nsa; 159 syscallarg(struct sigaction13 *) osa; 160 } */ *uap = v; 161 struct sigaction13 nesa, oesa; 162 struct sigaction nbsa, obsa; 163 int error; 164 165 if (SCARG(uap, nsa)) { 166 error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa)); 167 if (error) 168 return (error); 169 native_sigaction13_to_sigaction(&nesa, &nbsa); 170 } 171 error = sigaction1(p, SCARG(uap, signum), 172 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0); 173 if (error) 174 return (error); 175 if (SCARG(uap, osa)) { 176 native_sigaction_to_sigaction13(&obsa, &oesa); 177 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa)); 178 if (error) 179 return (error); 180 } 181 return (0); 182 } 183 184 int 185 compat_13_sys_sigprocmask(p, v, retval) 186 struct proc *p; 187 void *v; 188 register_t *retval; 189 { 190 struct compat_13_sys_sigprocmask_args /* { 191 syscallarg(int) how; 192 syscallarg(int) mask; 193 } */ *uap = v; 194 sigset13_t ness, oess; 195 sigset_t nbss, obss; 196 int error; 197 198 ness = SCARG(uap, mask); 199 native_sigset13_to_sigset(&ness, &nbss); 200 error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss); 201 if (error) 202 return (error); 203 native_sigset_to_sigset13(&obss, &oess); 204 *retval = oess; 205 return (0); 206 } 207 208 int 209 compat_13_sys_sigpending(p, v, retval) 210 struct proc *p; 211 void *v; 212 register_t *retval; 213 { 214 sigset13_t ess; 215 sigset_t bss; 216 217 sigpending1(p, &bss); 218 native_sigset_to_sigset13(&bss, &ess); 219 *retval = ess; 220 return (0); 221 } 222 223 int 224 compat_13_sys_sigsuspend(p, v, retval) 225 struct proc *p; 226 void *v; 227 register_t *retval; 228 { 229 struct compat_13_sys_sigsuspend_args /* { 230 syscallarg(sigset13_t) mask; 231 } */ *uap = v; 232 sigset13_t ess; 233 sigset_t bss; 234 235 ess = SCARG(uap, mask); 236 native_sigset13_to_sigset(&ess, &bss); 237 return (sigsuspend1(p, &bss)); 238 } 239