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