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