kern_sig_13.c revision 1.9
1/* $NetBSD: kern_sig_13.c,v 1.9 2003/01/18 07:28:34 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.9 2003/01/18 07:28:34 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/sa.h> 50#include <sys/syscallargs.h> 51 52#include <machine/limits.h> 53 54#include <compat/common/compat_util.h> 55 56void 57native_sigset13_to_sigset(oss, ss) 58 const sigset13_t *oss; 59 sigset_t *ss; 60{ 61 62 ss->__bits[0] = *oss; 63 ss->__bits[1] = 0; 64 ss->__bits[2] = 0; 65 ss->__bits[3] = 0; 66} 67 68void 69native_sigset_to_sigset13(ss, oss) 70 const sigset_t *ss; 71 sigset13_t *oss; 72{ 73 74 *oss = ss->__bits[0]; 75} 76 77void 78native_sigaction13_to_sigaction(osa, sa) 79 const struct sigaction13 *osa; 80 struct sigaction *sa; 81{ 82 83 sa->sa_handler = osa->osa_handler; 84 native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask); 85 sa->sa_flags = osa->osa_flags; 86} 87 88void 89native_sigaction_to_sigaction13(sa, osa) 90 const struct sigaction *sa; 91 struct sigaction13 *osa; 92{ 93 94 osa->osa_handler = sa->sa_handler; 95 native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask); 96 osa->osa_flags = sa->sa_flags; 97} 98 99void 100native_sigaltstack13_to_sigaltstack(osa, sa) 101 const struct sigaltstack13 *osa; 102 struct sigaltstack *sa; 103{ 104 105 sa->ss_sp = osa->ss_sp; 106 sa->ss_size = osa->ss_size; 107 sa->ss_flags = osa->ss_flags; 108} 109 110void 111native_sigaltstack_to_sigaltstack13(sa, osa) 112 const struct sigaltstack *sa; 113 struct sigaltstack13 *osa; 114{ 115 116 osa->ss_sp = sa->ss_sp; 117 osa->ss_size = sa->ss_size; 118 osa->ss_flags = sa->ss_flags; 119} 120 121int 122compat_13_sys_sigaltstack(struct lwp *l, void *v, register_t *retval) 123{ 124 struct compat_13_sys_sigaltstack_args /* { 125 syscallarg(const struct sigaltstack13 *) nss; 126 syscallarg(struct sigaltstack13 *) oss; 127 } */ *uap = v; 128 struct proc *p = l->l_proc; 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(p, 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 proc *p = l->l_proc; 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 NULL, 0); 174 if (error) 175 return (error); 176 if (SCARG(uap, osa)) { 177 native_sigaction_to_sigaction13(&obsa, &oesa); 178 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa)); 179 if (error) 180 return (error); 181 } 182 return (0); 183} 184 185int 186compat_13_sys_sigprocmask(struct lwp *l, void *v, register_t *retval) 187{ 188 struct compat_13_sys_sigprocmask_args /* { 189 syscallarg(int) how; 190 syscallarg(int) mask; 191 } */ *uap = v; 192 struct proc *p = l->l_proc; 193 sigset13_t ness, oess; 194 sigset_t nbss, obss; 195 int error; 196 197 ness = SCARG(uap, mask); 198 native_sigset13_to_sigset(&ness, &nbss); 199 error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss); 200 if (error) 201 return (error); 202 native_sigset_to_sigset13(&obss, &oess); 203 *retval = oess; 204 return (0); 205} 206 207int 208compat_13_sys_sigpending(struct lwp *l, void *v, register_t *retval) 209{ 210 struct proc *p = l->l_proc; 211 sigset13_t ess; 212 sigset_t bss; 213 214 sigpending1(p, &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 struct proc *p = l->l_proc; 227 sigset13_t ess; 228 sigset_t bss; 229 230 ess = SCARG(uap, mask); 231 native_sigset13_to_sigset(&ess, &bss); 232 return (sigsuspend1(p, &bss)); 233} 234