kern_sig_13.c revision 1.3
1/* $NetBSD: kern_sig_13.c,v 1.3 1998/09/11 12:50:07 mycroft 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 52void native_sigset13_to_sigset __P((const sigset13_t *, sigset_t *)); 53void native_sigset_to_sigset13 __P((const sigset_t *, sigset13_t *)); 54void native_sigaction13_to_sigaction __P((const struct sigaction13 *, struct sigaction *)); 55void native_sigaction_to_sigaction13 __P((const struct sigaction *, struct sigaction13 *)); 56void native_sigaltstack13_to_sigaltstack __P((const struct sigaltstack13 *, struct sigaltstack *)); 57void native_sigaltstack_to_sigaltstack13 __P((const struct sigaltstack *, struct sigaltstack13 *)); 58 59void 60native_sigset13_to_sigset(oss, ss) 61 const sigset13_t *oss; 62 sigset_t *ss; 63{ 64 65 ss->__bits[0] = *oss; 66 ss->__bits[1] = 0; 67 ss->__bits[2] = 0; 68 ss->__bits[3] = 0; 69} 70 71void 72native_sigset_to_sigset13(ss, oss) 73 const sigset_t *ss; 74 sigset13_t *oss; 75{ 76 77 *oss = ss->__bits[0]; 78} 79 80void 81native_sigaction13_to_sigaction(osa, sa) 82 const struct sigaction13 *osa; 83 struct sigaction *sa; 84{ 85 86 sa->sa_handler = osa->sa_handler; 87 native_sigset13_to_sigset(&osa->sa_mask, &sa->sa_mask); 88 sa->sa_flags = osa->sa_flags; 89} 90 91void 92native_sigaction_to_sigaction13(sa, osa) 93 const struct sigaction *sa; 94 struct sigaction13 *osa; 95{ 96 97 osa->sa_handler = sa->sa_handler; 98 native_sigset_to_sigset13(&sa->sa_mask, &osa->sa_mask); 99 osa->sa_flags = sa->sa_flags; 100} 101 102void 103native_sigaltstack13_to_sigaltstack(osa, sa) 104 const struct sigaltstack13 *osa; 105 struct sigaltstack *sa; 106{ 107 108 sa->ss_sp = osa->ss_sp; 109 sa->ss_size = osa->ss_size; 110 sa->ss_flags = osa->ss_flags; 111} 112 113void 114native_sigaltstack_to_sigaltstack13(sa, osa) 115 const struct sigaltstack *sa; 116 struct sigaltstack13 *osa; 117{ 118 119 osa->ss_sp = sa->ss_sp; 120 osa->ss_size = sa->ss_size; 121 osa->ss_flags = sa->ss_flags; 122} 123 124int 125compat_13_sys_sigaltstack(p, v, retval) 126 struct proc *p; 127 void *v; 128 register_t *retval; 129{ 130 struct compat_13_sys_sigaltstack_args /* { 131 syscallarg(const struct sigaltstack13 *) nss; 132 syscallarg(struct sigaltstack13 *) oss; 133 } */ *uap = v; 134 struct sigaltstack13 ness, oess; 135 struct sigaltstack nbss, obss; 136 int error; 137 138 if (SCARG(uap, nss)) { 139 error = copyin(SCARG(uap, nss), &ness, sizeof(ness)); 140 if (error) 141 return (error); 142 native_sigaltstack13_to_sigaltstack(&ness, &nbss); 143 } 144 error = sigaltstack1(p, 145 SCARG(uap, nss) ? &nbss : 0, SCARG(uap, oss) ? &obss : 0); 146 if (error) 147 return (error); 148 if (SCARG(uap, oss)) { 149 native_sigaltstack_to_sigaltstack13(&obss, &oess); 150 error = copyout(&oess, SCARG(uap, oss), sizeof(oess)); 151 if (error) 152 return (error); 153 } 154 return (0); 155} 156 157int 158compat_13_sys_sigaction(p, v, retval) 159 struct proc *p; 160 void *v; 161 register_t *retval; 162{ 163 struct compat_13_sys_sigaction_args /* { 164 syscallarg(int) signum; 165 syscallarg(const struct sigaction13 *) nsa; 166 syscallarg(struct sigaction13 *) osa; 167 } */ *uap = v; 168 struct sigaction13 nesa, oesa; 169 struct sigaction nbsa, obsa; 170 int error; 171 172 if (SCARG(uap, nsa)) { 173 error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa)); 174 if (error) 175 return (error); 176 native_sigaction13_to_sigaction(&nesa, &nbsa); 177 } 178 error = sigaction1(p, SCARG(uap, signum), 179 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0); 180 if (error) 181 return (error); 182 if (SCARG(uap, osa)) { 183 native_sigaction_to_sigaction13(&obsa, &oesa); 184 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa)); 185 if (error) 186 return (error); 187 } 188 return (0); 189} 190 191int 192compat_13_sys_sigprocmask(p, v, retval) 193 register struct proc *p; 194 void *v; 195 register_t *retval; 196{ 197 struct compat_13_sys_sigprocmask_args /* { 198 syscallarg(int) how; 199 syscallarg(int) mask; 200 } */ *uap = v; 201 sigset13_t ness, oess; 202 sigset_t nbss, obss; 203 int error; 204 205 ness = SCARG(uap, mask); 206 native_sigset13_to_sigset(&ness, &nbss); 207 error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss); 208 if (error) 209 return (error); 210 native_sigset_to_sigset13(&obss, &oess); 211 *retval = oess; 212 return (0); 213} 214 215int 216compat_13_sys_sigpending(p, v, retval) 217 struct proc *p; 218 void *v; 219 register_t *retval; 220{ 221 sigset13_t ess; 222 sigset_t bss; 223 224 sigpending1(p, &bss); 225 native_sigset_to_sigset13(&bss, &ess); 226 *retval = ess; 227 return (0); 228} 229 230int 231compat_13_sys_sigsuspend(p, v, retval) 232 register struct proc *p; 233 void *v; 234 register_t *retval; 235{ 236 struct compat_13_sys_sigsuspend_args /* { 237 syscallarg(sigset13_t) mask; 238 } */ *uap = v; 239 sigset13_t ess; 240 sigset_t bss; 241 242 ess = SCARG(uap, mask); 243 native_sigset13_to_sigset(&ess, &bss); 244 return (sigsuspend1(p, &bss)); 245} 246