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