kern_sig_13.c revision 1.15
1/* $NetBSD: kern_sig_13.c,v 1.15 2007/06/16 20:04:28 dsl 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.15 2007/06/16 20:04:28 dsl 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#include <compat/common/compat_sigaltstack.h> 57 58void 59native_sigset13_to_sigset(oss, ss) 60 const sigset13_t *oss; 61 sigset_t *ss; 62{ 63 64 ss->__bits[0] = *oss; 65 ss->__bits[1] = 0; 66 ss->__bits[2] = 0; 67 ss->__bits[3] = 0; 68} 69 70void 71native_sigset_to_sigset13(ss, oss) 72 const sigset_t *ss; 73 sigset13_t *oss; 74{ 75 76 *oss = ss->__bits[0]; 77} 78 79void 80native_sigaction13_to_sigaction(osa, sa) 81 const struct sigaction13 *osa; 82 struct sigaction *sa; 83{ 84 85 sa->sa_handler = osa->osa_handler; 86 native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask); 87 sa->sa_flags = osa->osa_flags; 88} 89 90void 91native_sigaction_to_sigaction13(sa, osa) 92 const struct sigaction *sa; 93 struct sigaction13 *osa; 94{ 95 96 osa->osa_handler = sa->sa_handler; 97 native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask); 98 osa->osa_flags = sa->sa_flags; 99} 100 101int 102compat_13_sys_sigaltstack(struct lwp *l, void *v, register_t *retval) 103{ 104 struct compat_13_sys_sigaltstack_args /* { 105 syscallarg(const struct sigaltstack13 *) nss; 106 syscallarg(struct sigaltstack13 *) oss; 107 } */ *uap = v; 108 compat_sigaltstack(uap, sigaltstack13, SS_ONSTACK, SS_DISABLE); 109} 110 111int 112compat_13_sys_sigaction(struct lwp *l, void *v, register_t *retval) 113{ 114 struct compat_13_sys_sigaction_args /* { 115 syscallarg(int) signum; 116 syscallarg(const struct sigaction13 *) nsa; 117 syscallarg(struct sigaction13 *) osa; 118 } */ *uap = v; 119 struct sigaction13 nesa, oesa; 120 struct sigaction nbsa, obsa; 121 int error; 122 123 if (SCARG(uap, nsa)) { 124 error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa)); 125 if (error) 126 return (error); 127 native_sigaction13_to_sigaction(&nesa, &nbsa); 128 } 129 error = sigaction1(l, SCARG(uap, signum), 130 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0, 131 NULL, 0); 132 if (error) 133 return (error); 134 if (SCARG(uap, osa)) { 135 native_sigaction_to_sigaction13(&obsa, &oesa); 136 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa)); 137 if (error) 138 return (error); 139 } 140 return (0); 141} 142 143int 144compat_13_sys_sigprocmask(struct lwp *l, void *v, register_t *retval) 145{ 146 struct compat_13_sys_sigprocmask_args /* { 147 syscallarg(int) how; 148 syscallarg(int) mask; 149 } */ *uap = v; 150 struct proc *p = l->l_proc; 151 sigset13_t ness, oess; 152 sigset_t nbss, obss; 153 int error; 154 155 ness = SCARG(uap, mask); 156 native_sigset13_to_sigset(&ness, &nbss); 157 mutex_enter(&p->p_smutex); 158 error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss); 159 mutex_exit(&p->p_smutex); 160 if (error) 161 return (error); 162 native_sigset_to_sigset13(&obss, &oess); 163 *retval = oess; 164 return (0); 165} 166 167int 168compat_13_sys_sigpending(struct lwp *l, void *v, register_t *retval) 169{ 170 sigset13_t ess; 171 sigset_t bss; 172 173 sigpending1(l, &bss); 174 native_sigset_to_sigset13(&bss, &ess); 175 *retval = ess; 176 return (0); 177} 178 179int 180compat_13_sys_sigsuspend(struct lwp *l, void *v, register_t *retval) 181{ 182 struct compat_13_sys_sigsuspend_args /* { 183 syscallarg(sigset13_t) mask; 184 } */ *uap = v; 185 sigset13_t ess; 186 sigset_t bss; 187 188 ess = SCARG(uap, mask); 189 native_sigset13_to_sigset(&ess, &bss); 190 return (sigsuspend1(l, &bss)); 191} 192