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