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