netbsd32_signal.c revision 1.52 1 1.52 riastrad /* $NetBSD: netbsd32_signal.c,v 1.52 2021/09/07 11:43:05 riastradh 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.52 riastrad __KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.52 2021/09/07 11:43:05 riastradh Exp $");
31 1.41 christos
32 1.41 christos #if defined(_KERNEL_OPT)
33 1.41 christos #include "opt_ktrace.h"
34 1.41 christos #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.40 martin #include <sys/ktrace.h>
43 1.1 mrg #include <sys/proc.h>
44 1.7 fvdl #include <sys/wait.h>
45 1.11 christos #include <sys/dirent.h>
46 1.7 fvdl
47 1.7 fvdl #include <uvm/uvm_extern.h>
48 1.1 mrg
49 1.1 mrg #include <compat/netbsd32/netbsd32.h>
50 1.10 cube #include <compat/netbsd32/netbsd32_conv.h>
51 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
52 1.1 mrg
53 1.12 christos #include <compat/sys/signal.h>
54 1.12 christos #include <compat/sys/signalvar.h>
55 1.13 christos #include <compat/sys/siginfo.h>
56 1.12 christos #include <compat/sys/ucontext.h>
57 1.25 dsl #include <compat/common/compat_sigaltstack.h>
58 1.12 christos
59 1.1 mrg int
60 1.28 dsl netbsd32_sigaction(struct lwp *l, const struct netbsd32_sigaction_args *uap, register_t *retval)
61 1.1 mrg {
62 1.28 dsl /* {
63 1.1 mrg syscallarg(int) signum;
64 1.1 mrg syscallarg(const netbsd32_sigactionp_t) nsa;
65 1.1 mrg syscallarg(netbsd32_sigactionp_t) osa;
66 1.28 dsl } */
67 1.1 mrg struct sigaction nsa, osa;
68 1.38 christos struct netbsd32_sigaction13 *sa32p, sa32;
69 1.1 mrg int error;
70 1.1 mrg
71 1.23 dsl if (SCARG_P32(uap, nsa)) {
72 1.23 dsl sa32p = SCARG_P32(uap, nsa);
73 1.1 mrg if (copyin(sa32p, &sa32, sizeof(sa32)))
74 1.1 mrg return EFAULT;
75 1.5 atatat nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler);
76 1.38 christos memset(&nsa.sa_mask, 0, sizeof(nsa.sa_mask));
77 1.38 christos nsa.sa_mask.__bits[0] = sa32.netbsd32_sa_mask;
78 1.5 atatat nsa.sa_flags = sa32.netbsd32_sa_flags;
79 1.1 mrg }
80 1.19 ad error = sigaction1(l, SCARG(uap, signum),
81 1.23 dsl SCARG_P32(uap, nsa) ? &nsa : 0,
82 1.23 dsl SCARG_P32(uap, osa) ? &osa : 0,
83 1.3 thorpej NULL, 0);
84 1.8 perry
85 1.1 mrg if (error)
86 1.51 simonb return error;
87 1.1 mrg
88 1.23 dsl if (SCARG_P32(uap, osa)) {
89 1.52 riastrad memset(&sa32, 0, sizeof(sa32));
90 1.22 dsl NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
91 1.38 christos sa32.netbsd32_sa_mask = osa.sa_mask.__bits[0];
92 1.5 atatat sa32.netbsd32_sa_flags = osa.sa_flags;
93 1.23 dsl sa32p = SCARG_P32(uap, osa);
94 1.1 mrg if (copyout(&sa32, sa32p, sizeof(sa32)))
95 1.1 mrg return EFAULT;
96 1.1 mrg }
97 1.1 mrg
98 1.51 simonb return 0;
99 1.1 mrg }
100 1.1 mrg
101 1.1 mrg int
102 1.28 dsl netbsd32___sigaltstack14(struct lwp *l, const struct netbsd32___sigaltstack14_args *uap, register_t *retval)
103 1.1 mrg {
104 1.28 dsl /* {
105 1.1 mrg syscallarg(const netbsd32_sigaltstackp_t) nss;
106 1.1 mrg syscallarg(netbsd32_sigaltstackp_t) oss;
107 1.28 dsl } */
108 1.25 dsl compat_sigaltstack(uap, netbsd32_sigaltstack, SS_ONSTACK, SS_DISABLE);
109 1.1 mrg }
110 1.1 mrg
111 1.1 mrg /* ARGSUSED */
112 1.1 mrg int
113 1.28 dsl netbsd32___sigaction14(struct lwp *l, const struct netbsd32___sigaction14_args *uap, register_t *retval)
114 1.1 mrg {
115 1.28 dsl /* {
116 1.1 mrg syscallarg(int) signum;
117 1.1 mrg syscallarg(const struct sigaction *) nsa;
118 1.1 mrg syscallarg(struct sigaction *) osa;
119 1.28 dsl } */
120 1.1 mrg struct netbsd32_sigaction sa32;
121 1.1 mrg struct sigaction nsa, osa;
122 1.1 mrg int error;
123 1.1 mrg
124 1.23 dsl if (SCARG_P32(uap, nsa)) {
125 1.23 dsl error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32));
126 1.1 mrg if (error)
127 1.51 simonb return error;
128 1.22 dsl nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler);
129 1.5 atatat nsa.sa_mask = sa32.netbsd32_sa_mask;
130 1.5 atatat nsa.sa_flags = sa32.netbsd32_sa_flags;
131 1.1 mrg }
132 1.19 ad error = sigaction1(l, SCARG(uap, signum),
133 1.23 dsl SCARG_P32(uap, nsa) ? &nsa : 0,
134 1.23 dsl SCARG_P32(uap, osa) ? &osa : 0,
135 1.22 dsl NULL, 0);
136 1.1 mrg if (error)
137 1.51 simonb return error;
138 1.23 dsl if (SCARG_P32(uap, osa)) {
139 1.52 riastrad memset(&sa32, 0, sizeof(sa32));
140 1.22 dsl NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
141 1.5 atatat sa32.netbsd32_sa_mask = osa.sa_mask;
142 1.5 atatat sa32.netbsd32_sa_flags = osa.sa_flags;
143 1.23 dsl error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32));
144 1.4 scw if (error)
145 1.51 simonb return error;
146 1.4 scw }
147 1.51 simonb return 0;
148 1.4 scw }
149 1.4 scw
150 1.4 scw /* ARGSUSED */
151 1.4 scw int
152 1.28 dsl netbsd32___sigaction_sigtramp(struct lwp *l, const struct netbsd32___sigaction_sigtramp_args *uap, register_t *retval)
153 1.4 scw {
154 1.28 dsl /* {
155 1.4 scw syscallarg(int) signum;
156 1.4 scw syscallarg(const netbsd32_sigactionp_t) nsa;
157 1.4 scw syscallarg(netbsd32_sigactionp_t) osa;
158 1.4 scw syscallarg(netbsd32_voidp) tramp;
159 1.4 scw syscallarg(int) vers;
160 1.28 dsl } */
161 1.4 scw struct netbsd32_sigaction sa32;
162 1.4 scw struct sigaction nsa, osa;
163 1.4 scw int error;
164 1.4 scw
165 1.23 dsl if (SCARG_P32(uap, nsa)) {
166 1.23 dsl error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32));
167 1.4 scw if (error)
168 1.51 simonb return error;
169 1.22 dsl nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler);
170 1.5 atatat nsa.sa_mask = sa32.netbsd32_sa_mask;
171 1.5 atatat nsa.sa_flags = sa32.netbsd32_sa_flags;
172 1.4 scw }
173 1.19 ad error = sigaction1(l, SCARG(uap, signum),
174 1.23 dsl SCARG_P32(uap, nsa) ? &nsa : 0,
175 1.23 dsl SCARG_P32(uap, osa) ? &osa : 0,
176 1.23 dsl SCARG_P32(uap, tramp), SCARG(uap, vers));
177 1.4 scw if (error)
178 1.51 simonb return error;
179 1.23 dsl if (SCARG_P32(uap, osa)) {
180 1.52 riastrad memset(&sa32, 0, sizeof(sa32));
181 1.22 dsl NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler);
182 1.5 atatat sa32.netbsd32_sa_mask = osa.sa_mask;
183 1.5 atatat sa32.netbsd32_sa_flags = osa.sa_flags;
184 1.23 dsl error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32));
185 1.1 mrg if (error)
186 1.51 simonb return error;
187 1.1 mrg }
188 1.51 simonb return 0;
189 1.7 fvdl }
190 1.7 fvdl
191 1.39 martin void
192 1.39 martin netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32)
193 1.7 fvdl {
194 1.46 rin size_t i;
195 1.46 rin
196 1.7 fvdl memset(si, 0, sizeof (*si));
197 1.39 martin si->_signo = si32->_signo;
198 1.39 martin si->_code = si32->_code;
199 1.39 martin si->_errno = si32->_errno;
200 1.7 fvdl
201 1.49 rin if (si32->_code == SI_NOINFO)
202 1.49 rin return;
203 1.49 rin else if (si32->_code <= 0) /* codes described in siginfo(2) */
204 1.49 rin goto fill_rt;
205 1.49 rin
206 1.39 martin switch (si32->_signo) {
207 1.7 fvdl case SIGILL:
208 1.47 rin case SIGFPE:
209 1.7 fvdl case SIGBUS:
210 1.7 fvdl case SIGSEGV:
211 1.46 rin fill_fault:
212 1.42 christos si->_reason._fault._addr =
213 1.42 christos NETBSD32IPTR64(si32->_reason._fault._addr);
214 1.39 martin si->_reason._fault._trap = si32->_reason._fault._trap;
215 1.7 fvdl break;
216 1.46 rin case SIGTRAP:
217 1.48 rin switch (si32->_code) {
218 1.48 rin case TRAP_EXEC:
219 1.50 rin break;
220 1.48 rin case TRAP_CHLD:
221 1.48 rin case TRAP_LWP:
222 1.48 rin si->_reason._ptrace_state._pe_report_event =
223 1.48 rin si32->_reason._ptrace_state._pe_report_event;
224 1.48 rin CTASSERT(sizeof(si->_reason._ptrace_state._option._pe_other_pid) ==
225 1.48 rin sizeof(si->_reason._ptrace_state._option._pe_lwp));
226 1.48 rin si->_reason._ptrace_state._option._pe_other_pid =
227 1.48 rin si32->_reason._ptrace_state._option._pe_other_pid;
228 1.48 rin break;
229 1.48 rin case TRAP_SCE:
230 1.48 rin case TRAP_SCX:
231 1.48 rin si->_reason._syscall._sysnum =
232 1.48 rin si32->_reason._syscall._sysnum;
233 1.48 rin si->_reason._syscall._retval[0] =
234 1.48 rin si32->_reason._syscall._retval[0];
235 1.48 rin si->_reason._syscall._retval[1] =
236 1.48 rin si32->_reason._syscall._retval[1];
237 1.48 rin si->_reason._syscall._error =
238 1.48 rin si32->_reason._syscall._error;
239 1.48 rin for (i = 0;
240 1.48 rin i < __arraycount(si->_reason._syscall._args); i++)
241 1.48 rin si->_reason._syscall._args[i] =
242 1.48 rin si32->_reason._syscall._args[i];
243 1.48 rin break;
244 1.48 rin default:
245 1.46 rin goto fill_fault;
246 1.48 rin }
247 1.46 rin break;
248 1.7 fvdl case SIGALRM:
249 1.7 fvdl case SIGVTALRM:
250 1.7 fvdl case SIGPROF:
251 1.39 martin default: /* see sigqueue() and kill1() */
252 1.49 rin fill_rt:
253 1.39 martin si->_reason._rt._pid = si32->_reason._rt._pid;
254 1.39 martin si->_reason._rt._uid = si32->_reason._rt._uid;
255 1.42 christos si->_reason._rt._value.sival_int =
256 1.42 christos si32->_reason._rt._value.sival_int;
257 1.7 fvdl break;
258 1.47 rin case SIGURG:
259 1.47 rin case SIGIO:
260 1.47 rin si->_reason._poll._band = si32->_reason._poll._band;
261 1.47 rin si->_reason._poll._fd = si32->_reason._poll._fd;
262 1.47 rin break;
263 1.7 fvdl case SIGCHLD:
264 1.39 martin si->_reason._child._pid = si32->_reason._child._pid;
265 1.39 martin si->_reason._child._uid = si32->_reason._child._uid;
266 1.46 rin si->_reason._child._status = si32->_reason._child._status;
267 1.39 martin si->_reason._child._utime = si32->_reason._child._utime;
268 1.39 martin si->_reason._child._stime = si32->_reason._child._stime;
269 1.7 fvdl break;
270 1.7 fvdl }
271 1.7 fvdl }
272 1.7 fvdl
273 1.47 rin void
274 1.47 rin netbsd32_si32_to_si(siginfo_t *si, const siginfo32_t *si32)
275 1.47 rin {
276 1.47 rin
277 1.47 rin memset(si, 0, sizeof (*si));
278 1.47 rin netbsd32_ksi32_to_ksi(&si->_info, &si32->_info);
279 1.47 rin }
280 1.47 rin
281 1.40 martin static void
282 1.40 martin netbsd32_ksi_to_ksi32(struct __ksiginfo32 *si32, const struct _ksiginfo *si)
283 1.40 martin {
284 1.46 rin size_t i;
285 1.46 rin
286 1.40 martin memset(si32, 0, sizeof (*si32));
287 1.40 martin si32->_signo = si->_signo;
288 1.40 martin si32->_code = si->_code;
289 1.40 martin si32->_errno = si->_errno;
290 1.40 martin
291 1.49 rin if (si->_code == SI_NOINFO)
292 1.49 rin return;
293 1.49 rin else if (si->_code <= 0) /* codes described in siginfo(2) */
294 1.49 rin goto fill_rt;
295 1.49 rin
296 1.40 martin switch (si->_signo) {
297 1.40 martin case SIGILL:
298 1.47 rin case SIGFPE:
299 1.40 martin case SIGBUS:
300 1.40 martin case SIGSEGV:
301 1.46 rin fill_fault:
302 1.40 martin si32->_reason._fault._addr =
303 1.40 martin NETBSD32PTR32I(si->_reason._fault._addr);
304 1.40 martin si32->_reason._fault._trap = si->_reason._fault._trap;
305 1.40 martin break;
306 1.46 rin case SIGTRAP:
307 1.48 rin switch (si->_code) {
308 1.48 rin case TRAP_EXEC:
309 1.50 rin break;
310 1.48 rin case TRAP_CHLD:
311 1.48 rin case TRAP_LWP:
312 1.48 rin si32->_reason._ptrace_state._pe_report_event =
313 1.48 rin si->_reason._ptrace_state._pe_report_event;
314 1.48 rin CTASSERT(sizeof(si32->_reason._ptrace_state._option._pe_other_pid) ==
315 1.48 rin sizeof(si32->_reason._ptrace_state._option._pe_lwp));
316 1.48 rin si32->_reason._ptrace_state._option._pe_other_pid =
317 1.48 rin si->_reason._ptrace_state._option._pe_other_pid;
318 1.48 rin break;
319 1.48 rin case TRAP_SCE:
320 1.48 rin case TRAP_SCX:
321 1.48 rin si32->_reason._syscall._sysnum =
322 1.48 rin si->_reason._syscall._sysnum;
323 1.48 rin si32->_reason._syscall._retval[0] =
324 1.48 rin si->_reason._syscall._retval[0];
325 1.48 rin si32->_reason._syscall._retval[1] =
326 1.48 rin si->_reason._syscall._retval[1];
327 1.48 rin si32->_reason._syscall._error =
328 1.48 rin si->_reason._syscall._error;
329 1.48 rin for (i = 0;
330 1.48 rin i < __arraycount(si->_reason._syscall._args); i++)
331 1.48 rin si32->_reason._syscall._args[i] =
332 1.48 rin si->_reason._syscall._args[i];
333 1.48 rin break;
334 1.48 rin default:
335 1.46 rin goto fill_fault;
336 1.48 rin }
337 1.46 rin break;
338 1.40 martin case SIGALRM:
339 1.40 martin case SIGVTALRM:
340 1.40 martin case SIGPROF:
341 1.40 martin default: /* see sigqueue() and kill1() */
342 1.49 rin fill_rt:
343 1.40 martin si32->_reason._rt._pid = si->_reason._rt._pid;
344 1.40 martin si32->_reason._rt._uid = si->_reason._rt._uid;
345 1.42 christos si32->_reason._rt._value.sival_int =
346 1.42 christos si->_reason._rt._value.sival_int;
347 1.40 martin break;
348 1.47 rin case SIGURG:
349 1.47 rin case SIGIO:
350 1.47 rin si32->_reason._poll._band = si->_reason._poll._band;
351 1.47 rin si32->_reason._poll._fd = si->_reason._poll._fd;
352 1.47 rin break;
353 1.40 martin case SIGCHLD:
354 1.40 martin si32->_reason._child._pid = si->_reason._child._pid;
355 1.40 martin si32->_reason._child._uid = si->_reason._child._uid;
356 1.46 rin si32->_reason._child._status = si->_reason._child._status;
357 1.40 martin si32->_reason._child._utime = si->_reason._child._utime;
358 1.40 martin si32->_reason._child._stime = si->_reason._child._stime;
359 1.40 martin break;
360 1.40 martin }
361 1.40 martin }
362 1.40 martin
363 1.15 chs void
364 1.9 drochner netbsd32_si_to_si32(siginfo32_t *si32, const siginfo_t *si)
365 1.7 fvdl {
366 1.46 rin
367 1.7 fvdl memset(si32, 0, sizeof (*si32));
368 1.46 rin netbsd32_ksi_to_ksi32(&si32->_info, &si->_info);
369 1.7 fvdl }
370 1.7 fvdl
371 1.7 fvdl void
372 1.7 fvdl getucontext32(struct lwp *l, ucontext32_t *ucp)
373 1.7 fvdl {
374 1.20 cube struct proc *p = l->l_proc;
375 1.7 fvdl
376 1.29 ad KASSERT(mutex_owned(p->p_lock));
377 1.7 fvdl
378 1.7 fvdl ucp->uc_flags = 0;
379 1.7 fvdl ucp->uc_link = (uint32_t)(intptr_t)l->l_ctxlink;
380 1.37 rmind ucp->uc_sigmask = l->l_sigmask;
381 1.7 fvdl ucp->uc_flags |= _UC_SIGMASK;
382 1.7 fvdl
383 1.7 fvdl /*
384 1.7 fvdl * The (unsupplied) definition of the `current execution stack'
385 1.7 fvdl * in the System V Interface Definition appears to allow returning
386 1.7 fvdl * the main context stack.
387 1.7 fvdl */
388 1.19 ad if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) {
389 1.7 fvdl ucp->uc_stack.ss_sp = USRSTACK32;
390 1.7 fvdl ucp->uc_stack.ss_size = ctob(p->p_vmspace->vm_ssize);
391 1.7 fvdl ucp->uc_stack.ss_flags = 0; /* XXX, def. is Very Fishy */
392 1.7 fvdl } else {
393 1.7 fvdl /* Simply copy alternate signal execution stack. */
394 1.7 fvdl ucp->uc_stack.ss_sp =
395 1.19 ad (uint32_t)(intptr_t)l->l_sigstk.ss_sp;
396 1.19 ad ucp->uc_stack.ss_size = l->l_sigstk.ss_size;
397 1.19 ad ucp->uc_stack.ss_flags = l->l_sigstk.ss_flags;
398 1.7 fvdl }
399 1.7 fvdl ucp->uc_flags |= _UC_STACK;
400 1.29 ad mutex_exit(p->p_lock);
401 1.7 fvdl cpu_getmcontext32(l, &ucp->uc_mcontext, &ucp->uc_flags);
402 1.29 ad mutex_enter(p->p_lock);
403 1.7 fvdl }
404 1.7 fvdl
405 1.7 fvdl int
406 1.28 dsl netbsd32_getcontext(struct lwp *l, const struct netbsd32_getcontext_args *uap, register_t *retval)
407 1.7 fvdl {
408 1.28 dsl /* {
409 1.7 fvdl syscallarg(netbsd32_ucontextp) ucp;
410 1.28 dsl } */
411 1.20 cube struct proc *p = l->l_proc;
412 1.7 fvdl ucontext32_t uc;
413 1.7 fvdl
414 1.35 joerg memset(&uc, 0, sizeof(uc));
415 1.35 joerg
416 1.29 ad mutex_enter(p->p_lock);
417 1.7 fvdl getucontext32(l, &uc);
418 1.29 ad mutex_exit(p->p_lock);
419 1.7 fvdl
420 1.23 dsl return copyout(&uc, SCARG_P32(uap, ucp), sizeof (ucontext32_t));
421 1.7 fvdl }
422 1.7 fvdl
423 1.7 fvdl int
424 1.7 fvdl setucontext32(struct lwp *l, const ucontext32_t *ucp)
425 1.7 fvdl {
426 1.20 cube struct proc *p = l->l_proc;
427 1.20 cube int error;
428 1.20 cube
429 1.29 ad KASSERT(mutex_owned(p->p_lock));
430 1.20 cube
431 1.20 cube if ((ucp->uc_flags & _UC_SIGMASK) != 0) {
432 1.20 cube error = sigprocmask1(l, SIG_SETMASK, &ucp->uc_sigmask, NULL);
433 1.20 cube if (error != 0)
434 1.20 cube return error;
435 1.20 cube }
436 1.7 fvdl
437 1.29 ad mutex_exit(p->p_lock);
438 1.20 cube error = cpu_setmcontext32(l, &ucp->uc_mcontext, ucp->uc_flags);
439 1.29 ad mutex_enter(p->p_lock);
440 1.20 cube if (error != 0)
441 1.51 simonb return error;
442 1.20 cube
443 1.7 fvdl l->l_ctxlink = (void *)(intptr_t)ucp->uc_link;
444 1.20 cube
445 1.7 fvdl /*
446 1.20 cube * If there was stack information, update whether or not we are
447 1.20 cube * still running on an alternate signal stack.
448 1.7 fvdl */
449 1.20 cube if ((ucp->uc_flags & _UC_STACK) != 0) {
450 1.20 cube if (ucp->uc_stack.ss_flags & SS_ONSTACK)
451 1.20 cube l->l_sigstk.ss_flags |= SS_ONSTACK;
452 1.20 cube else
453 1.20 cube l->l_sigstk.ss_flags &= ~SS_ONSTACK;
454 1.20 cube }
455 1.7 fvdl
456 1.7 fvdl return 0;
457 1.7 fvdl }
458 1.7 fvdl
459 1.7 fvdl /* ARGSUSED */
460 1.7 fvdl int
461 1.28 dsl netbsd32_setcontext(struct lwp *l, const struct netbsd32_setcontext_args *uap, register_t *retval)
462 1.7 fvdl {
463 1.28 dsl /* {
464 1.7 fvdl syscallarg(netbsd32_ucontextp) ucp;
465 1.28 dsl } */
466 1.7 fvdl ucontext32_t uc;
467 1.7 fvdl int error;
468 1.20 cube struct proc *p = l->l_proc;
469 1.7 fvdl
470 1.23 dsl error = copyin(SCARG_P32(uap, ucp), &uc, sizeof (uc));
471 1.18 drochner if (error)
472 1.51 simonb return error;
473 1.18 drochner if (!(uc.uc_flags & _UC_CPU))
474 1.51 simonb return EINVAL;
475 1.29 ad mutex_enter(p->p_lock);
476 1.18 drochner error = setucontext32(l, &uc);
477 1.29 ad mutex_exit(p->p_lock);
478 1.18 drochner if (error)
479 1.51 simonb return error;
480 1.7 fvdl
481 1.51 simonb return EJUSTRETURN;
482 1.1 mrg }
483 1.10 cube
484 1.10 cube static int
485 1.10 cube netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
486 1.10 cube {
487 1.10 cube const siginfo_t *info = src;
488 1.10 cube siginfo32_t info32;
489 1.10 cube
490 1.10 cube netbsd32_si_to_si32(&info32, info);
491 1.10 cube
492 1.10 cube return copyout(&info32, dst, sizeof(info32));
493 1.10 cube }
494 1.10 cube
495 1.10 cube static int
496 1.10 cube netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
497 1.10 cube {
498 1.10 cube struct timespec *ts = dst;
499 1.10 cube struct netbsd32_timespec ts32;
500 1.10 cube int error;
501 1.10 cube
502 1.10 cube error = copyin(src, &ts32, sizeof(ts32));
503 1.10 cube if (error)
504 1.10 cube return error;
505 1.10 cube
506 1.10 cube netbsd32_to_timespec(&ts32, ts);
507 1.10 cube return 0;
508 1.10 cube }
509 1.10 cube
510 1.10 cube static int
511 1.10 cube netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
512 1.10 cube {
513 1.10 cube const struct timespec *ts = src;
514 1.10 cube struct netbsd32_timespec ts32;
515 1.10 cube
516 1.10 cube netbsd32_from_timespec(ts, &ts32);
517 1.10 cube
518 1.10 cube return copyout(&ts32, dst, sizeof(ts32));
519 1.10 cube }
520 1.10 cube
521 1.10 cube int
522 1.32 christos netbsd32_____sigtimedwait50(struct lwp *l, const struct netbsd32_____sigtimedwait50_args *uap, register_t *retval)
523 1.10 cube {
524 1.28 dsl /* {
525 1.10 cube syscallarg(netbsd32_sigsetp_t) set;
526 1.10 cube syscallarg(netbsd32_siginfop_t) info;
527 1.32 christos syscallarg(netbsd32_timespec50p_t) timeout;
528 1.28 dsl } */
529 1.32 christos struct sys_____sigtimedwait50_args ua;
530 1.10 cube
531 1.10 cube NETBSD32TOP_UAP(set, const sigset_t);
532 1.10 cube NETBSD32TOP_UAP(info, siginfo_t);
533 1.10 cube NETBSD32TOP_UAP(timeout, struct timespec);
534 1.10 cube
535 1.33 pooka return sigtimedwait1(l, &ua, retval,
536 1.36 christos copyin,
537 1.32 christos netbsd32_sigtimedwait_put_info,
538 1.10 cube netbsd32_sigtimedwait_fetch_timeout,
539 1.10 cube netbsd32_sigtimedwait_put_timeout);
540 1.10 cube }
541 1.39 martin
542 1.39 martin int
543 1.39 martin netbsd32_sigqueueinfo(struct lwp *l,
544 1.39 martin const struct netbsd32_sigqueueinfo_args *uap, register_t *retval)
545 1.39 martin {
546 1.39 martin /* {
547 1.39 martin syscallarg(pid_t) pid;
548 1.39 martin syscallarg(const netbsd32_siginfop_t) info;
549 1.39 martin } */
550 1.39 martin struct __ksiginfo32 ksi32;
551 1.39 martin ksiginfo_t ksi;
552 1.39 martin int error;
553 1.39 martin
554 1.39 martin if ((error = copyin(SCARG_P32(uap, info), &ksi32,
555 1.39 martin sizeof(ksi32))) != 0)
556 1.39 martin return error;
557 1.39 martin
558 1.39 martin KSI_INIT(&ksi);
559 1.39 martin netbsd32_ksi32_to_ksi(&ksi.ksi_info, &ksi32);
560 1.39 martin
561 1.39 martin return kill1(l, SCARG(uap, pid), &ksi, retval);
562 1.39 martin }
563 1.40 martin
564 1.40 martin struct netbsd32_ktr_psig {
565 1.40 martin int signo;
566 1.40 martin netbsd32_pointer_t action;
567 1.40 martin sigset_t mask;
568 1.40 martin int code;
569 1.40 martin /* and optional siginfo_t */
570 1.40 martin };
571 1.40 martin
572 1.44 christos #ifdef notyet
573 1.41 christos #ifdef KTRACE
574 1.40 martin void
575 1.40 martin netbsd32_ktrpsig(int sig, sig_t action, const sigset_t *mask,
576 1.40 martin const ksiginfo_t *ksi)
577 1.40 martin {
578 1.40 martin struct ktrace_entry *kte;
579 1.40 martin lwp_t *l = curlwp;
580 1.40 martin struct {
581 1.40 martin struct netbsd32_ktr_psig kp;
582 1.40 martin siginfo32_t si;
583 1.40 martin } *kbuf;
584 1.40 martin
585 1.40 martin if (!KTRPOINT(l->l_proc, KTR_PSIG))
586 1.40 martin return;
587 1.40 martin
588 1.40 martin if (ktealloc(&kte, (void *)&kbuf, l, KTR_PSIG, sizeof(*kbuf)))
589 1.40 martin return;
590 1.40 martin
591 1.40 martin kbuf->kp.signo = (char)sig;
592 1.40 martin NETBSD32PTR32(kbuf->kp.action, action);
593 1.40 martin kbuf->kp.mask = *mask;
594 1.40 martin
595 1.40 martin if (ksi) {
596 1.40 martin kbuf->kp.code = KSI_TRAPCODE(ksi);
597 1.40 martin (void)memset(&kbuf->si, 0, sizeof(kbuf->si));
598 1.40 martin netbsd32_ksi_to_ksi32(&kbuf->si._info, &ksi->ksi_info);
599 1.40 martin ktesethdrlen(kte, sizeof(*kbuf));
600 1.40 martin } else {
601 1.40 martin kbuf->kp.code = 0;
602 1.40 martin ktesethdrlen(kte, sizeof(struct netbsd32_ktr_psig));
603 1.40 martin }
604 1.40 martin
605 1.40 martin ktraddentry(l, kte, KTA_WAITOK);
606 1.40 martin }
607 1.41 christos #endif
608 1.44 christos #endif
609