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