1 /* $NetBSD: kern_sig_43.c,v 1.13 2000/06/28 15:39:25 mrg 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 "opt_compat_netbsd.h" 40 41 #include <sys/param.h> 42 #include <sys/signalvar.h> 43 #include <sys/resourcevar.h> 44 #include <sys/namei.h> 45 #include <sys/vnode.h> 46 #include <sys/proc.h> 47 #include <sys/systm.h> 48 #include <sys/timeb.h> 49 #include <sys/times.h> 50 #include <sys/buf.h> 51 #include <sys/acct.h> 52 #include <sys/file.h> 53 #include <sys/kernel.h> 54 #include <sys/wait.h> 55 #include <sys/ktrace.h> 56 #include <sys/syslog.h> 57 #include <sys/stat.h> 58 #include <sys/core.h> 59 60 #include <sys/mount.h> 61 #include <sys/syscallargs.h> 62 63 #include <machine/cpu.h> 64 65 #include <sys/user.h> /* for coredump */ 66 67 void compat_43_sigmask_to_sigset __P((const int *, sigset_t *)); 68 void compat_43_sigset_to_sigmask __P((const sigset_t *, int *)); 69 void compat_43_sigvec_to_sigaction __P((const struct sigvec *, struct sigaction *)); 70 void compat_43_sigaction_to_sigvec __P((const struct sigaction *, struct sigvec *)); 71 void compat_43_sigstack_to_sigaltstack __P((const struct sigstack *, struct sigaltstack *)); 72 void compat_43_sigaltstack_to_sigstack __P((const struct sigaltstack *, struct sigstack *)); 73 74 void 75 compat_43_sigmask_to_sigset(sm, ss) 76 const int *sm; 77 sigset_t *ss; 78 { 79 80 ss->__bits[0] = *sm; 81 ss->__bits[1] = 0; 82 ss->__bits[2] = 0; 83 ss->__bits[3] = 0; 84 } 85 86 void 87 compat_43_sigset_to_sigmask(ss, sm) 88 const sigset_t *ss; 89 int *sm; 90 { 91 92 *sm = ss->__bits[0]; 93 } 94 95 void 96 compat_43_sigvec_to_sigaction(sv, sa) 97 const struct sigvec *sv; 98 struct sigaction *sa; 99 { 100 sa->sa_handler = sv->sv_handler; 101 compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask); 102 sa->sa_flags = sv->sv_flags ^ SA_RESTART; 103 } 104 105 void 106 compat_43_sigaction_to_sigvec(sa, sv) 107 const struct sigaction *sa; 108 struct sigvec *sv; 109 { 110 sv->sv_handler = sa->sa_handler; 111 compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask); 112 sv->sv_flags = sa->sa_flags ^ SA_RESTART; 113 } 114 115 void 116 compat_43_sigstack_to_sigaltstack(ss, sa) 117 const struct sigstack *ss; 118 struct sigaltstack *sa; 119 { 120 sa->ss_sp = ss->ss_sp; 121 sa->ss_size = SIGSTKSZ; /* Use the recommended size */ 122 sa->ss_flags = 0; 123 if (ss->ss_onstack) 124 sa->ss_flags |= SS_ONSTACK; 125 } 126 127 void 128 compat_43_sigaltstack_to_sigstack(sa, ss) 129 const struct sigaltstack *sa; 130 struct sigstack *ss; 131 { 132 ss->ss_sp = sa->ss_sp; 133 if (sa->ss_flags & SS_ONSTACK) 134 ss->ss_onstack = 1; 135 else 136 ss->ss_onstack = 0; 137 } 138 139 int 140 compat_43_sys_sigblock(p, v, retval) 141 struct proc *p; 142 void *v; 143 register_t *retval; 144 { 145 struct compat_43_sys_sigblock_args /* { 146 syscallarg(int) mask; 147 } */ *uap = v; 148 int nsm, osm; 149 sigset_t nss, oss; 150 int error; 151 152 nsm = SCARG(uap, mask); 153 compat_43_sigmask_to_sigset(&nsm, &nss); 154 error = sigprocmask1(p, SIG_BLOCK, &nss, &oss); 155 if (error) 156 return (error); 157 compat_43_sigset_to_sigmask(&oss, &osm); 158 *retval = osm; 159 return (0); 160 } 161 162 int 163 compat_43_sys_sigsetmask(p, v, retval) 164 struct proc *p; 165 void *v; 166 register_t *retval; 167 { 168 struct compat_43_sys_sigsetmask_args /* { 169 syscallarg(int) mask; 170 } */ *uap = v; 171 int nsm, osm; 172 sigset_t nss, oss; 173 int error; 174 175 nsm = SCARG(uap, mask); 176 compat_43_sigmask_to_sigset(&nsm, &nss); 177 error = sigprocmask1(p, SIG_SETMASK, &nss, &oss); 178 if (error) 179 return (error); 180 compat_43_sigset_to_sigmask(&oss, &osm); 181 *retval = osm; 182 return (0); 183 } 184 185 /* ARGSUSED */ 186 int 187 compat_43_sys_sigstack(p, v, retval) 188 struct proc *p; 189 void *v; 190 register_t *retval; 191 { 192 struct compat_43_sys_sigstack_args /* { 193 syscallarg(struct sigstack *) nss; 194 syscallarg(struct sigstack *) oss; 195 } */ *uap = v; 196 struct sigstack nss, oss; 197 struct sigaltstack nsa, osa; 198 int error; 199 200 if (SCARG(uap, nss)) { 201 error = copyin(SCARG(uap, nss), &nss, sizeof(nss)); 202 if (error) 203 return (error); 204 compat_43_sigstack_to_sigaltstack(&nss, &nsa); 205 } 206 error = sigaltstack1(p, 207 SCARG(uap, nss) ? &nsa : 0, SCARG(uap, oss) ? &osa : 0); 208 if (error) 209 return (error); 210 if (SCARG(uap, oss)) { 211 compat_43_sigaltstack_to_sigstack(&osa, &oss); 212 error = copyout(&oss, SCARG(uap, oss), sizeof(oss)); 213 if (error) 214 return (error); 215 } 216 return (0); 217 } 218 219 /* 220 * Generalized interface signal handler, 4.3-compatible. 221 */ 222 /* ARGSUSED */ 223 int 224 compat_43_sys_sigvec(p, v, retval) 225 struct proc *p; 226 void *v; 227 register_t *retval; 228 { 229 struct compat_43_sys_sigvec_args /* { 230 syscallarg(int) signum; 231 syscallarg(const struct sigvec *) nsv; 232 syscallarg(struct sigvec *) osv; 233 } */ *uap = v; 234 struct sigvec nsv, osv; 235 struct sigaction nsa, osa; 236 int error; 237 238 if (SCARG(uap, nsv)) { 239 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv)); 240 if (error) 241 return (error); 242 compat_43_sigvec_to_sigaction(&nsv, &nsa); 243 } 244 error = sigaction1(p, SCARG(uap, signum), 245 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0); 246 if (error) 247 return (error); 248 if (SCARG(uap, osv)) { 249 compat_43_sigaction_to_sigvec(&osa, &osv); 250 error = copyout(&osv, SCARG(uap, osv), sizeof(osv)); 251 if (error) 252 return (error); 253 } 254 return (0); 255 } 256 257 258 /* ARGSUSED */ 259 int 260 compat_43_sys_killpg(p, v, retval) 261 struct proc *p; 262 void *v; 263 register_t *retval; 264 { 265 struct compat_43_sys_killpg_args /* { 266 syscallarg(int) pgid; 267 syscallarg(int) signum; 268 } */ *uap = v; 269 270 #ifdef COMPAT_09 271 SCARG(uap, pgid) = (short) SCARG(uap, pgid); 272 #endif 273 274 if ((u_int)SCARG(uap, signum) >= NSIG) 275 return (EINVAL); 276 return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0)); 277 } 278