netbsd32_signal.c revision 1.39.2.1 1 1.39.2.1 pgoyette /* $NetBSD: netbsd32_signal.c,v 1.39.2.1 2016/11/04 14:49:07 pgoyette Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1998, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg *
16 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 mrg * SUCH DAMAGE.
27 1.1 mrg */
28 1.2 lukem
29 1.2 lukem #include <sys/cdefs.h>
30 1.39.2.1 pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.39.2.1 2016/11/04 14:49:07 pgoyette Exp $");
31 1.39.2.1 pgoyette
32 1.39.2.1 pgoyette #if defined(_KERNEL_OPT)
33 1.39.2.1 pgoyette #include "opt_ktrace.h"
34 1.39.2.1 pgoyette #endif
35 1.1 mrg
36 1.1 mrg #include <sys/param.h>
37 1.1 mrg #include <sys/systm.h>
38 1.1 mrg #include <sys/mount.h>
39 1.1 mrg #include <sys/stat.h>
40 1.1 mrg #include <sys/time.h>
41 1.1 mrg #include <sys/signalvar.h>
42 1.1 mrg #include <sys/proc.h>
43 1.7 fvdl #include <sys/wait.h>
44 1.11 christos #include <sys/dirent.h>
45 1.7 fvdl
46 1.7 fvdl #include <uvm/uvm_extern.h>
47 1.1 mrg
48 1.1 mrg #include <compat/netbsd32/netbsd32.h>
49 1.10 cube #include <compat/netbsd32/netbsd32_conv.h>
50 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
51 1.1 mrg
52 1.12 christos #include <compat/sys/signal.h>
53 1.12 christos #include <compat/sys/signalvar.h>
54 1.13 christos #include <compat/sys/siginfo.h>
55 1.12 christos #include <compat/sys/ucontext.h>
56 1.25 dsl #include <compat/common/compat_sigaltstack.h>
57 1.12 christos
58 1.1 mrg int
59 1.28 dsl netbsd32_sigaction(struct lwp *l, const struct netbsd32_sigaction_args *uap, register_t *retval)
60 1.1 mrg {
61 1.28 dsl /* {
62 1.1 mrg syscallarg(int) signum;
63 1.1 mrg syscallarg(const netbsd32_sigactionp_t) nsa;
64 1.1 mrg syscallarg(netbsd32_sigactionp_t) osa;
65 1.28 dsl } */
66 1.1 mrg struct sigaction nsa, osa;
67 1.38 christos struct netbsd32_sigaction13 *sa32p, sa32;
68 1.1 mrg int error;
69 1.1 mrg
70 1.23 dsl if (SCARG_P32(uap, nsa)) {
71 1.23 dsl sa32p = SCARG_P32(uap, nsa);
72 1.1 mrg if (copyin(sa32p, &sa32, sizeof(sa32)))
73 1.1 mrg return EFAULT;
74 1.5 atatat nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler);
75 1.38 christos memset(&nsa.sa_mask, 0, sizeof(nsa.sa_mask));
76 1.38 christos nsa.sa_mask.__bits[0] = sa32.netbsd32_sa_mask;
77 1.5 atatat nsa.sa_flags = sa32.netbsd32_sa_flags;
78 1.1 mrg }
79 1.19 ad error = sigaction1(l, SCARG(uap, signum),
80 1.23 dsl SCARG_P32(uap, nsa) ? &nsa : 0,
81 1.23 dsl SCARG_P32(uap, osa) ? &osa : 0,
82 1.3 thorpej NULL, 0);
83 1.8 perry
84 1.1 mrg if (error)
85 1.1 mrg return (error);
86 1.1 mrg
87 1.23 dsl if (SCARG_P32(uap, osa)) {
88 1.22 dsl NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
89 1.38 christos sa32.netbsd32_sa_mask = osa.sa_mask.__bits[0];
90 1.5 atatat sa32.netbsd32_sa_flags = osa.sa_flags;
91 1.23 dsl sa32p = SCARG_P32(uap, osa);
92 1.1 mrg if (copyout(&sa32, sa32p, sizeof(sa32)))
93 1.1 mrg return EFAULT;
94 1.1 mrg }
95 1.1 mrg
96 1.1 mrg return (0);
97 1.1 mrg }
98 1.1 mrg
99 1.1 mrg int
100 1.28 dsl netbsd32___sigaltstack14(struct lwp *l, const struct netbsd32___sigaltstack14_args *uap, register_t *retval)
101 1.1 mrg {
102 1.28 dsl /* {
103 1.1 mrg syscallarg(const netbsd32_sigaltstackp_t) nss;
104 1.1 mrg syscallarg(netbsd32_sigaltstackp_t) oss;
105 1.28 dsl } */
106 1.25 dsl compat_sigaltstack(uap, netbsd32_sigaltstack, SS_ONSTACK, SS_DISABLE);
107 1.1 mrg }
108 1.1 mrg
109 1.1 mrg /* ARGSUSED */
110 1.1 mrg int
111 1.28 dsl netbsd32___sigaction14(struct lwp *l, const struct netbsd32___sigaction14_args *uap, register_t *retval)
112 1.1 mrg {
113 1.28 dsl /* {
114 1.1 mrg syscallarg(int) signum;
115 1.1 mrg syscallarg(const struct sigaction *) nsa;
116 1.1 mrg syscallarg(struct sigaction *) osa;
117 1.28 dsl } */
118 1.1 mrg struct netbsd32_sigaction sa32;
119 1.1 mrg struct sigaction nsa, osa;
120 1.1 mrg int error;
121 1.1 mrg
122 1.23 dsl if (SCARG_P32(uap, nsa)) {
123 1.23 dsl error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32));
124 1.1 mrg if (error)
125 1.1 mrg return (error);
126 1.22 dsl nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler);
127 1.5 atatat nsa.sa_mask = sa32.netbsd32_sa_mask;
128 1.5 atatat nsa.sa_flags = sa32.netbsd32_sa_flags;
129 1.1 mrg }
130 1.19 ad error = sigaction1(l, SCARG(uap, signum),
131 1.23 dsl SCARG_P32(uap, nsa) ? &nsa : 0,
132 1.23 dsl SCARG_P32(uap, osa) ? &osa : 0,
133 1.22 dsl NULL, 0);
134 1.1 mrg if (error)
135 1.1 mrg return (error);
136 1.23 dsl if (SCARG_P32(uap, osa)) {
137 1.22 dsl NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
138 1.5 atatat sa32.netbsd32_sa_mask = osa.sa_mask;
139 1.5 atatat sa32.netbsd32_sa_flags = osa.sa_flags;
140 1.23 dsl error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32));
141 1.4 scw if (error)
142 1.4 scw return (error);
143 1.4 scw }
144 1.4 scw return (0);
145 1.4 scw }
146 1.4 scw
147 1.4 scw /* ARGSUSED */
148 1.4 scw int
149 1.28 dsl netbsd32___sigaction_sigtramp(struct lwp *l, const struct netbsd32___sigaction_sigtramp_args *uap, register_t *retval)
150 1.4 scw {
151 1.28 dsl /* {
152 1.4 scw syscallarg(int) signum;
153 1.4 scw syscallarg(const netbsd32_sigactionp_t) nsa;
154 1.4 scw syscallarg(netbsd32_sigactionp_t) osa;
155 1.4 scw syscallarg(netbsd32_voidp) tramp;
156 1.4 scw syscallarg(int) vers;
157 1.28 dsl } */
158 1.4 scw struct netbsd32_sigaction sa32;
159 1.4 scw struct sigaction nsa, osa;
160 1.4 scw int error;
161 1.4 scw
162 1.23 dsl if (SCARG_P32(uap, nsa)) {
163 1.23 dsl error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32));
164 1.4 scw if (error)
165 1.4 scw return (error);
166 1.22 dsl nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler);
167 1.5 atatat nsa.sa_mask = sa32.netbsd32_sa_mask;
168 1.5 atatat nsa.sa_flags = sa32.netbsd32_sa_flags;
169 1.4 scw }
170 1.19 ad error = sigaction1(l, SCARG(uap, signum),
171 1.23 dsl SCARG_P32(uap, nsa) ? &nsa : 0,
172 1.23 dsl SCARG_P32(uap, osa) ? &osa : 0,
173 1.23 dsl SCARG_P32(uap, tramp), SCARG(uap, vers));
174 1.4 scw if (error)
175 1.4 scw return (error);
176 1.23 dsl if (SCARG_P32(uap, osa)) {
177 1.22 dsl NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
178 1.5 atatat sa32.netbsd32_sa_mask = osa.sa_mask;
179 1.5 atatat sa32.netbsd32_sa_flags = osa.sa_flags;
180 1.23 dsl error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32));
181 1.1 mrg if (error)
182 1.1 mrg return (error);
183 1.1 mrg }
184 1.1 mrg return (0);
185 1.7 fvdl }
186 1.7 fvdl
187 1.39 martin void
188 1.39 martin netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32)
189 1.7 fvdl {
190 1.7 fvdl memset(si, 0, sizeof (*si));
191 1.39 martin si->_signo = si32->_signo;
192 1.39 martin si->_code = si32->_code;
193 1.39 martin si->_errno = si32->_errno;
194 1.7 fvdl
195 1.39 martin switch (si32->_signo) {
196 1.7 fvdl case SIGILL:
197 1.7 fvdl case SIGBUS:
198 1.7 fvdl case SIGSEGV:
199 1.7 fvdl case SIGFPE:
200 1.7 fvdl case SIGTRAP:
201 1.39.2.1 pgoyette si->_reason._fault._addr =
202 1.39.2.1 pgoyette NETBSD32IPTR64(si32->_reason._fault._addr);
203 1.39 martin si->_reason._fault._trap = si32->_reason._fault._trap;
204 1.7 fvdl break;
205 1.7 fvdl case SIGALRM:
206 1.7 fvdl case SIGVTALRM:
207 1.7 fvdl case SIGPROF:
208 1.39 martin default: /* see sigqueue() and kill1() */
209 1.39 martin si->_reason._rt._pid = si32->_reason._rt._pid;
210 1.39 martin si->_reason._rt._uid = si32->_reason._rt._uid;
211 1.39.2.1 pgoyette si->_reason._rt._value.sival_int =
212 1.39.2.1 pgoyette si32->_reason._rt._value.sival_int;
213 1.7 fvdl break;
214 1.7 fvdl case SIGCHLD:
215 1.39 martin si->_reason._child._pid = si32->_reason._child._pid;
216 1.39 martin si->_reason._child._uid = si32->_reason._child._uid;
217 1.39 martin si->_reason._child._utime = si32->_reason._child._utime;
218 1.39 martin si->_reason._child._stime = si32->_reason._child._stime;
219 1.7 fvdl break;
220 1.7 fvdl case SIGURG:
221 1.7 fvdl case SIGIO:
222 1.39 martin si->_reason._poll._band = si32->_reason._poll._band;
223 1.39 martin si->_reason._poll._fd = si32->_reason._poll._fd;
224 1.7 fvdl break;
225 1.7 fvdl }
226 1.7 fvdl }
227 1.7 fvdl
228 1.39.2.1 pgoyette #ifdef KTRACE
229 1.39.2.1 pgoyette static void
230 1.39.2.1 pgoyette netbsd32_ksi_to_ksi32(struct __ksiginfo32 *si32, const struct _ksiginfo *si)
231 1.39.2.1 pgoyette {
232 1.39.2.1 pgoyette memset(si32, 0, sizeof (*si32));
233 1.39.2.1 pgoyette si32->_signo = si->_signo;
234 1.39.2.1 pgoyette si32->_code = si->_code;
235 1.39.2.1 pgoyette si32->_errno = si->_errno;
236 1.39.2.1 pgoyette
237 1.39.2.1 pgoyette switch (si->_signo) {
238 1.39.2.1 pgoyette case SIGILL:
239 1.39.2.1 pgoyette case SIGBUS:
240 1.39.2.1 pgoyette case SIGSEGV:
241 1.39.2.1 pgoyette case SIGFPE:
242 1.39.2.1 pgoyette case SIGTRAP:
243 1.39.2.1 pgoyette si32->_reason._fault._addr =
244 1.39.2.1 pgoyette NETBSD32PTR32I(si->_reason._fault._addr);
245 1.39.2.1 pgoyette si32->_reason._fault._trap = si->_reason._fault._trap;
246 1.39.2.1 pgoyette break;
247 1.39.2.1 pgoyette case SIGALRM:
248 1.39.2.1 pgoyette case SIGVTALRM:
249 1.39.2.1 pgoyette case SIGPROF:
250 1.39.2.1 pgoyette default: /* see sigqueue() and kill1() */
251 1.39.2.1 pgoyette si32->_reason._rt._pid = si->_reason._rt._pid;
252 1.39.2.1 pgoyette si32->_reason._rt._uid = si->_reason._rt._uid;
253 1.39.2.1 pgoyette si32->_reason._rt._value.sival_int =
254 1.39.2.1 pgoyette si->_reason._rt._value.sival_int;
255 1.39.2.1 pgoyette break;
256 1.39.2.1 pgoyette case SIGCHLD:
257 1.39.2.1 pgoyette si32->_reason._child._pid = si->_reason._child._pid;
258 1.39.2.1 pgoyette si32->_reason._child._uid = si->_reason._child._uid;
259 1.39.2.1 pgoyette si32->_reason._child._utime = si->_reason._child._utime;
260 1.39.2.1 pgoyette si32->_reason._child._stime = si->_reason._child._stime;
261 1.39.2.1 pgoyette break;
262 1.39.2.1 pgoyette case SIGURG:
263 1.39.2.1 pgoyette case SIGIO:
264 1.39.2.1 pgoyette si32->_reason._poll._band = si->_reason._poll._band;
265 1.39.2.1 pgoyette si32->_reason._poll._fd = si->_reason._poll._fd;
266 1.39.2.1 pgoyette break;
267 1.39.2.1 pgoyette }
268 1.39.2.1 pgoyette }
269 1.39.2.1 pgoyette #endif
270 1.39.2.1 pgoyette
271 1.15 chs void
272 1.9 drochner netbsd32_si_to_si32(siginfo32_t *si32, const siginfo_t *si)
273 1.7 fvdl {
274 1.7 fvdl memset(si32, 0, sizeof (*si32));
275 1.7 fvdl si32->si_signo = si->si_signo;
276 1.7 fvdl si32->si_code = si->si_code;
277 1.7 fvdl si32->si_errno = si->si_errno;
278 1.7 fvdl
279 1.7 fvdl switch (si32->si_signo) {
280 1.17 cube case 0: /* SA */
281 1.24 christos si32->si_value.sival_int = si->si_value.sival_int;
282 1.17 cube break;
283 1.7 fvdl case SIGILL:
284 1.7 fvdl case SIGBUS:
285 1.7 fvdl case SIGSEGV:
286 1.7 fvdl case SIGFPE:
287 1.7 fvdl case SIGTRAP:
288 1.7 fvdl si32->si_addr = (uint32_t)(uintptr_t)si->si_addr;
289 1.7 fvdl si32->si_trap = si->si_trap;
290 1.7 fvdl break;
291 1.7 fvdl case SIGALRM:
292 1.7 fvdl case SIGVTALRM:
293 1.7 fvdl case SIGPROF:
294 1.39 martin default:
295 1.7 fvdl si32->si_pid = si->si_pid;
296 1.7 fvdl si32->si_uid = si->si_uid;
297 1.24 christos si32->si_value.sival_int = si->si_value.sival_int;
298 1.7 fvdl break;
299 1.7 fvdl case SIGCHLD:
300 1.7 fvdl si32->si_pid = si->si_pid;
301 1.7 fvdl si32->si_uid = si->si_uid;
302 1.7 fvdl si32->si_status = si->si_status;
303 1.7 fvdl si32->si_utime = si->si_utime;
304 1.7 fvdl si32->si_stime = si->si_stime;
305 1.7 fvdl break;
306 1.7 fvdl case SIGURG:
307 1.7 fvdl case SIGIO:
308 1.7 fvdl si32->si_band = si->si_band;
309 1.7 fvdl si32->si_fd = si->si_fd;
310 1.7 fvdl break;
311 1.7 fvdl }
312 1.7 fvdl }
313 1.7 fvdl
314 1.7 fvdl void
315 1.7 fvdl getucontext32(struct lwp *l, ucontext32_t *ucp)
316 1.7 fvdl {
317 1.20 cube struct proc *p = l->l_proc;
318 1.7 fvdl
319 1.29 ad KASSERT(mutex_owned(p->p_lock));
320 1.7 fvdl
321 1.7 fvdl ucp->uc_flags = 0;
322 1.7 fvdl ucp->uc_link = (uint32_t)(intptr_t)l->l_ctxlink;
323 1.37 rmind ucp->uc_sigmask = l->l_sigmask;
324 1.7 fvdl ucp->uc_flags |= _UC_SIGMASK;
325 1.7 fvdl
326 1.7 fvdl /*
327 1.7 fvdl * The (unsupplied) definition of the `current execution stack'
328 1.7 fvdl * in the System V Interface Definition appears to allow returning
329 1.7 fvdl * the main context stack.
330 1.7 fvdl */
331 1.19 ad if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) {
332 1.7 fvdl ucp->uc_stack.ss_sp = USRSTACK32;
333 1.7 fvdl ucp->uc_stack.ss_size = ctob(p->p_vmspace->vm_ssize);
334 1.7 fvdl ucp->uc_stack.ss_flags = 0; /* XXX, def. is Very Fishy */
335 1.7 fvdl } else {
336 1.7 fvdl /* Simply copy alternate signal execution stack. */
337 1.7 fvdl ucp->uc_stack.ss_sp =
338 1.19 ad (uint32_t)(intptr_t)l->l_sigstk.ss_sp;
339 1.19 ad ucp->uc_stack.ss_size = l->l_sigstk.ss_size;
340 1.19 ad ucp->uc_stack.ss_flags = l->l_sigstk.ss_flags;
341 1.7 fvdl }
342 1.7 fvdl ucp->uc_flags |= _UC_STACK;
343 1.29 ad mutex_exit(p->p_lock);
344 1.7 fvdl cpu_getmcontext32(l, &ucp->uc_mcontext, &ucp->uc_flags);
345 1.29 ad mutex_enter(p->p_lock);
346 1.7 fvdl }
347 1.7 fvdl
348 1.7 fvdl int
349 1.28 dsl netbsd32_getcontext(struct lwp *l, const struct netbsd32_getcontext_args *uap, register_t *retval)
350 1.7 fvdl {
351 1.28 dsl /* {
352 1.7 fvdl syscallarg(netbsd32_ucontextp) ucp;
353 1.28 dsl } */
354 1.20 cube struct proc *p = l->l_proc;
355 1.7 fvdl ucontext32_t uc;
356 1.7 fvdl
357 1.35 joerg memset(&uc, 0, sizeof(uc));
358 1.35 joerg
359 1.29 ad mutex_enter(p->p_lock);
360 1.7 fvdl getucontext32(l, &uc);
361 1.29 ad mutex_exit(p->p_lock);
362 1.7 fvdl
363 1.23 dsl return copyout(&uc, SCARG_P32(uap, ucp), sizeof (ucontext32_t));
364 1.7 fvdl }
365 1.7 fvdl
366 1.7 fvdl int
367 1.7 fvdl setucontext32(struct lwp *l, const ucontext32_t *ucp)
368 1.7 fvdl {
369 1.20 cube struct proc *p = l->l_proc;
370 1.20 cube int error;
371 1.20 cube
372 1.29 ad KASSERT(mutex_owned(p->p_lock));
373 1.20 cube
374 1.20 cube if ((ucp->uc_flags & _UC_SIGMASK) != 0) {
375 1.20 cube error = sigprocmask1(l, SIG_SETMASK, &ucp->uc_sigmask, NULL);
376 1.20 cube if (error != 0)
377 1.20 cube return error;
378 1.20 cube }
379 1.7 fvdl
380 1.29 ad mutex_exit(p->p_lock);
381 1.20 cube error = cpu_setmcontext32(l, &ucp->uc_mcontext, ucp->uc_flags);
382 1.29 ad mutex_enter(p->p_lock);
383 1.20 cube if (error != 0)
384 1.7 fvdl return (error);
385 1.20 cube
386 1.7 fvdl l->l_ctxlink = (void *)(intptr_t)ucp->uc_link;
387 1.20 cube
388 1.7 fvdl /*
389 1.20 cube * If there was stack information, update whether or not we are
390 1.20 cube * still running on an alternate signal stack.
391 1.7 fvdl */
392 1.20 cube if ((ucp->uc_flags & _UC_STACK) != 0) {
393 1.20 cube if (ucp->uc_stack.ss_flags & SS_ONSTACK)
394 1.20 cube l->l_sigstk.ss_flags |= SS_ONSTACK;
395 1.20 cube else
396 1.20 cube l->l_sigstk.ss_flags &= ~SS_ONSTACK;
397 1.20 cube }
398 1.7 fvdl
399 1.7 fvdl return 0;
400 1.7 fvdl }
401 1.7 fvdl
402 1.7 fvdl /* ARGSUSED */
403 1.7 fvdl int
404 1.28 dsl netbsd32_setcontext(struct lwp *l, const struct netbsd32_setcontext_args *uap, register_t *retval)
405 1.7 fvdl {
406 1.28 dsl /* {
407 1.7 fvdl syscallarg(netbsd32_ucontextp) ucp;
408 1.28 dsl } */
409 1.7 fvdl ucontext32_t uc;
410 1.7 fvdl int error;
411 1.20 cube struct proc *p = l->l_proc;
412 1.7 fvdl
413 1.23 dsl error = copyin(SCARG_P32(uap, ucp), &uc, sizeof (uc));
414 1.18 drochner if (error)
415 1.18 drochner return (error);
416 1.18 drochner if (!(uc.uc_flags & _UC_CPU))
417 1.18 drochner return (EINVAL);
418 1.29 ad mutex_enter(p->p_lock);
419 1.18 drochner error = setucontext32(l, &uc);
420 1.29 ad mutex_exit(p->p_lock);
421 1.18 drochner if (error)
422 1.7 fvdl return (error);
423 1.7 fvdl
424 1.7 fvdl return (EJUSTRETURN);
425 1.1 mrg }
426 1.10 cube
427 1.10 cube static int
428 1.10 cube netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
429 1.10 cube {
430 1.10 cube const siginfo_t *info = src;
431 1.10 cube siginfo32_t info32;
432 1.10 cube
433 1.10 cube netbsd32_si_to_si32(&info32, info);
434 1.10 cube
435 1.10 cube return copyout(&info32, dst, sizeof(info32));
436 1.10 cube }
437 1.10 cube
438 1.10 cube static int
439 1.10 cube netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
440 1.10 cube {
441 1.10 cube struct timespec *ts = dst;
442 1.10 cube struct netbsd32_timespec ts32;
443 1.10 cube int error;
444 1.10 cube
445 1.10 cube error = copyin(src, &ts32, sizeof(ts32));
446 1.10 cube if (error)
447 1.10 cube return error;
448 1.10 cube
449 1.10 cube netbsd32_to_timespec(&ts32, ts);
450 1.10 cube return 0;
451 1.10 cube }
452 1.10 cube
453 1.10 cube static int
454 1.10 cube netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
455 1.10 cube {
456 1.10 cube const struct timespec *ts = src;
457 1.10 cube struct netbsd32_timespec ts32;
458 1.10 cube
459 1.10 cube netbsd32_from_timespec(ts, &ts32);
460 1.10 cube
461 1.10 cube return copyout(&ts32, dst, sizeof(ts32));
462 1.10 cube }
463 1.10 cube
464 1.10 cube int
465 1.32 christos netbsd32_____sigtimedwait50(struct lwp *l, const struct netbsd32_____sigtimedwait50_args *uap, register_t *retval)
466 1.10 cube {
467 1.28 dsl /* {
468 1.10 cube syscallarg(netbsd32_sigsetp_t) set;
469 1.10 cube syscallarg(netbsd32_siginfop_t) info;
470 1.32 christos syscallarg(netbsd32_timespec50p_t) timeout;
471 1.28 dsl } */
472 1.32 christos struct sys_____sigtimedwait50_args ua;
473 1.10 cube
474 1.10 cube NETBSD32TOP_UAP(set, const sigset_t);
475 1.10 cube NETBSD32TOP_UAP(info, siginfo_t);
476 1.10 cube NETBSD32TOP_UAP(timeout, struct timespec);
477 1.10 cube
478 1.33 pooka return sigtimedwait1(l, &ua, retval,
479 1.36 christos copyin,
480 1.32 christos netbsd32_sigtimedwait_put_info,
481 1.10 cube netbsd32_sigtimedwait_fetch_timeout,
482 1.10 cube netbsd32_sigtimedwait_put_timeout);
483 1.10 cube }
484 1.39 martin
485 1.39 martin int
486 1.39 martin netbsd32_sigqueueinfo(struct lwp *l,
487 1.39 martin const struct netbsd32_sigqueueinfo_args *uap, register_t *retval)
488 1.39 martin {
489 1.39 martin /* {
490 1.39 martin syscallarg(pid_t) pid;
491 1.39 martin syscallarg(const netbsd32_siginfop_t) info;
492 1.39 martin } */
493 1.39 martin struct __ksiginfo32 ksi32;
494 1.39 martin ksiginfo_t ksi;
495 1.39 martin int error;
496 1.39 martin
497 1.39 martin if ((error = copyin(SCARG_P32(uap, info), &ksi32,
498 1.39 martin sizeof(ksi32))) != 0)
499 1.39 martin return error;
500 1.39 martin
501 1.39 martin KSI_INIT(&ksi);
502 1.39 martin netbsd32_ksi32_to_ksi(&ksi.ksi_info, &ksi32);
503 1.39 martin
504 1.39 martin return kill1(l, SCARG(uap, pid), &ksi, retval);
505 1.39 martin }
506 1.39.2.1 pgoyette
507 1.39.2.1 pgoyette struct netbsd32_ktr_psig {
508 1.39.2.1 pgoyette int signo;
509 1.39.2.1 pgoyette netbsd32_pointer_t action;
510 1.39.2.1 pgoyette sigset_t mask;
511 1.39.2.1 pgoyette int code;
512 1.39.2.1 pgoyette /* and optional siginfo_t */
513 1.39.2.1 pgoyette };
514 1.39.2.1 pgoyette
515 1.39.2.1 pgoyette #ifdef KTRACE
516 1.39.2.1 pgoyette void
517 1.39.2.1 pgoyette netbsd32_ktrpsig(int sig, sig_t action, const sigset_t *mask,
518 1.39.2.1 pgoyette const ksiginfo_t *ksi)
519 1.39.2.1 pgoyette {
520 1.39.2.1 pgoyette struct ktrace_entry *kte;
521 1.39.2.1 pgoyette lwp_t *l = curlwp;
522 1.39.2.1 pgoyette struct {
523 1.39.2.1 pgoyette struct netbsd32_ktr_psig kp;
524 1.39.2.1 pgoyette siginfo32_t si;
525 1.39.2.1 pgoyette } *kbuf;
526 1.39.2.1 pgoyette
527 1.39.2.1 pgoyette if (!KTRPOINT(l->l_proc, KTR_PSIG))
528 1.39.2.1 pgoyette return;
529 1.39.2.1 pgoyette
530 1.39.2.1 pgoyette if (ktealloc(&kte, (void *)&kbuf, l, KTR_PSIG, sizeof(*kbuf)))
531 1.39.2.1 pgoyette return;
532 1.39.2.1 pgoyette
533 1.39.2.1 pgoyette kbuf->kp.signo = (char)sig;
534 1.39.2.1 pgoyette NETBSD32PTR32(kbuf->kp.action, action);
535 1.39.2.1 pgoyette kbuf->kp.mask = *mask;
536 1.39.2.1 pgoyette
537 1.39.2.1 pgoyette if (ksi) {
538 1.39.2.1 pgoyette kbuf->kp.code = KSI_TRAPCODE(ksi);
539 1.39.2.1 pgoyette (void)memset(&kbuf->si, 0, sizeof(kbuf->si));
540 1.39.2.1 pgoyette netbsd32_ksi_to_ksi32(&kbuf->si._info, &ksi->ksi_info);
541 1.39.2.1 pgoyette ktesethdrlen(kte, sizeof(*kbuf));
542 1.39.2.1 pgoyette } else {
543 1.39.2.1 pgoyette kbuf->kp.code = 0;
544 1.39.2.1 pgoyette ktesethdrlen(kte, sizeof(struct netbsd32_ktr_psig));
545 1.39.2.1 pgoyette }
546 1.39.2.1 pgoyette
547 1.39.2.1 pgoyette ktraddentry(l, kte, KTA_WAITOK);
548 1.39.2.1 pgoyette }
549 1.39.2.1 pgoyette #endif
550 1.39.2.1 pgoyette
551 1.39.2.1 pgoyette
552