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