1 /* $NetBSD: kern_sig_13.c,v 1.20 2011/01/19 10:21:16 tsutsui 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: kern_sig_13.c,v 1.20 2011/01/19 10:21:16 tsutsui Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/proc.h> 37 #include <sys/signal.h> 38 #include <sys/signalvar.h> 39 #include <sys/systm.h> 40 41 #include <sys/syscallargs.h> 42 43 #include <machine/limits.h> 44 45 #include <compat/sys/signal.h> 46 #include <compat/sys/signalvar.h> 47 #include <compat/common/compat_util.h> 48 #include <compat/common/compat_sigaltstack.h> 49 50 void 51 native_sigset13_to_sigset(const sigset13_t *oss, sigset_t *ss) 52 { 53 54 ss->__bits[0] = *oss; 55 ss->__bits[1] = 0; 56 ss->__bits[2] = 0; 57 ss->__bits[3] = 0; 58 } 59 60 void 61 native_sigset_to_sigset13(const sigset_t *ss, sigset13_t *oss) 62 { 63 64 *oss = ss->__bits[0]; 65 } 66 67 void 68 native_sigaction13_to_sigaction(const struct sigaction13 *osa, struct sigaction *sa) 69 { 70 71 sa->sa_handler = osa->osa_handler; 72 native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask); 73 sa->sa_flags = osa->osa_flags; 74 } 75 76 void 77 native_sigaction_to_sigaction13(const struct sigaction *sa, struct sigaction13 *osa) 78 { 79 80 osa->osa_handler = sa->sa_handler; 81 native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask); 82 osa->osa_flags = sa->sa_flags; 83 } 84 85 int 86 compat_13_sys_sigaltstack(struct lwp *l, const struct compat_13_sys_sigaltstack_args *uap, register_t *retval) 87 { 88 /* { 89 syscallarg(const struct sigaltstack13 *) nss; 90 syscallarg(struct sigaltstack13 *) oss; 91 } */ 92 compat_sigaltstack(uap, sigaltstack13, SS_ONSTACK, SS_DISABLE); 93 } 94 95 int 96 compat_13_sys_sigaction(struct lwp *l, const struct compat_13_sys_sigaction_args *uap, register_t *retval) 97 { 98 /* { 99 syscallarg(int) signum; 100 syscallarg(const struct sigaction13 *) nsa; 101 syscallarg(struct sigaction13 *) osa; 102 } */ 103 struct sigaction13 nesa, oesa; 104 struct sigaction nbsa, obsa; 105 int error; 106 107 if (SCARG(uap, nsa)) { 108 error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa)); 109 if (error) 110 return (error); 111 native_sigaction13_to_sigaction(&nesa, &nbsa); 112 } 113 error = sigaction1(l, SCARG(uap, signum), 114 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0, 115 NULL, 0); 116 if (error) 117 return (error); 118 if (SCARG(uap, osa)) { 119 native_sigaction_to_sigaction13(&obsa, &oesa); 120 error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa)); 121 if (error) 122 return (error); 123 } 124 return (0); 125 } 126 127 int 128 compat_13_sys_sigprocmask(struct lwp *l, const struct compat_13_sys_sigprocmask_args *uap, register_t *retval) 129 { 130 /* { 131 syscallarg(int) how; 132 syscallarg(int) mask; 133 } */ 134 struct proc *p = l->l_proc; 135 sigset13_t ness, oess; 136 sigset_t nbss, obss; 137 int error; 138 139 ness = SCARG(uap, mask); 140 native_sigset13_to_sigset(&ness, &nbss); 141 mutex_enter(p->p_lock); 142 error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss); 143 mutex_exit(p->p_lock); 144 if (error) 145 return (error); 146 native_sigset_to_sigset13(&obss, &oess); 147 *retval = oess; 148 return (0); 149 } 150 151 int 152 compat_13_sys_sigpending(struct lwp *l, const void *v, register_t *retval) 153 { 154 sigset13_t ess; 155 sigset_t bss; 156 157 sigpending1(l, &bss); 158 native_sigset_to_sigset13(&bss, &ess); 159 *retval = ess; 160 return (0); 161 } 162 163 int 164 compat_13_sys_sigsuspend(struct lwp *l, const struct compat_13_sys_sigsuspend_args *uap, register_t *retval) 165 { 166 /* { 167 syscallarg(sigset13_t) mask; 168 } */ 169 sigset13_t ess; 170 sigset_t bss; 171 172 ess = SCARG(uap, mask); 173 native_sigset13_to_sigset(&ess, &bss); 174 return (sigsuspend1(l, &bss)); 175 } 176