| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: netbsd32_machdep.c,v 1.105 2015/11/07 11:47:09 martin Exp $ */ | | 1 | /* $NetBSD: netbsd32_machdep.c,v 1.106 2015/11/07 21:07:18 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1998, 2001 Matthew R. Green | | 4 | * Copyright (c) 1998, 2001 Matthew R. Green |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.105 2015/11/07 11:47:09 martin Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.106 2015/11/07 21:07:18 martin Exp $"); |
31 | | | 31 | |
32 | #ifdef _KERNEL_OPT | | 32 | #ifdef _KERNEL_OPT |
33 | #include "opt_compat_netbsd.h" | | 33 | #include "opt_compat_netbsd.h" |
34 | #include "opt_compat_sunos.h" | | 34 | #include "opt_compat_sunos.h" |
35 | #include "opt_modular.h" | | 35 | #include "opt_modular.h" |
36 | #include "opt_execfmt.h" | | 36 | #include "opt_execfmt.h" |
37 | #include "firm_events.h" | | 37 | #include "firm_events.h" |
38 | #endif | | 38 | #endif |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/exec.h> | | 41 | #include <sys/exec.h> |
42 | #include <sys/exec_aout.h> | | 42 | #include <sys/exec_aout.h> |
43 | #include <sys/filedesc.h> | | 43 | #include <sys/filedesc.h> |
| @@ -306,72 +306,75 @@ struct sparc32_sigframe_siginfo { | | | @@ -306,72 +306,75 @@ struct sparc32_sigframe_siginfo { |
306 | ucontext32_t sf_uc; | | 306 | ucontext32_t sf_uc; |
307 | }; | | 307 | }; |
308 | | | 308 | |
309 | static void | | 309 | static void |
310 | netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) | | 310 | netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) |
311 | { | | 311 | { |
312 | struct lwp *l = curlwp; | | 312 | struct lwp *l = curlwp; |
313 | struct proc *p = l->l_proc; | | 313 | struct proc *p = l->l_proc; |
314 | struct sigacts *ps = p->p_sigacts; | | 314 | struct sigacts *ps = p->p_sigacts; |
315 | int onstack; | | 315 | int onstack; |
316 | int sig = ksi->ksi_signo; | | 316 | int sig = ksi->ksi_signo; |
317 | ucontext32_t uc; | | 317 | ucontext32_t uc; |
318 | struct sparc32_sigframe_siginfo *fp; | | 318 | struct sparc32_sigframe_siginfo *fp; |
| | | 319 | siginfo32_t si32; |
319 | netbsd32_intptr_t catcher; | | 320 | netbsd32_intptr_t catcher; |
320 | struct trapframe64 *tf = l->l_md.md_tf; | | 321 | struct trapframe64 *tf = l->l_md.md_tf; |
321 | struct rwindow32 *oldsp, *newsp; | | 322 | struct rwindow32 *oldsp, *newsp; |
322 | int ucsz, error; | | 323 | int ucsz, error; |
323 | | | 324 | |
324 | /* Need to attempt to zero extend this 32-bit pointer */ | | 325 | /* Need to attempt to zero extend this 32-bit pointer */ |
325 | oldsp = (struct rwindow32*)(u_long)(u_int)tf->tf_out[6]; | | 326 | oldsp = (struct rwindow32*)(u_long)(u_int)tf->tf_out[6]; |
326 | /* Do we need to jump onto the signal stack? */ | | 327 | /* Do we need to jump onto the signal stack? */ |
327 | onstack = | | 328 | onstack = |
328 | (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 && | | 329 | (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 && |
329 | (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0; | | 330 | (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0; |
330 | | | 331 | |
331 | /* Allocate space for the signal handler context. */ | | 332 | /* Allocate space for the signal handler context. */ |
332 | if (onstack) | | 333 | if (onstack) |
333 | fp = (struct sparc32_sigframe_siginfo *) | | 334 | fp = (struct sparc32_sigframe_siginfo *) |
334 | ((char *)l->l_sigstk.ss_sp + | | 335 | ((char *)l->l_sigstk.ss_sp + |
335 | l->l_sigstk.ss_size); | | 336 | l->l_sigstk.ss_size); |
336 | else | | 337 | else |
337 | fp = (struct sparc32_sigframe_siginfo *)oldsp; | | 338 | fp = (struct sparc32_sigframe_siginfo *)oldsp; |
338 | fp = (struct sparc32_sigframe_siginfo*)((u_long)(fp - 1) & ~7); | | 339 | fp = (struct sparc32_sigframe_siginfo*)((u_long)(fp - 1) & ~7); |
| | | 340 | |
339 | /* | | 341 | /* |
340 | * Build the signal context to be used by sigreturn. | | 342 | * Build the signal context to be used by sigreturn. |
341 | */ | | 343 | */ |
| | | 344 | memset(&uc, 0, sizeof uc); |
342 | uc.uc_flags = _UC_SIGMASK | | | 345 | uc.uc_flags = _UC_SIGMASK | |
343 | ((l->l_sigstk.ss_flags & SS_ONSTACK) | | 346 | ((l->l_sigstk.ss_flags & SS_ONSTACK) |
344 | ? _UC_SETSTACK : _UC_CLRSTACK); | | 347 | ? _UC_SETSTACK : _UC_CLRSTACK); |
345 | uc.uc_sigmask = *mask; | | 348 | uc.uc_sigmask = *mask; |
346 | uc.uc_link = (uint32_t)(uintptr_t)l->l_ctxlink; | | 349 | uc.uc_link = (uint32_t)(uintptr_t)l->l_ctxlink; |
347 | memset(&uc.uc_stack, 0, sizeof(uc.uc_stack)); | | | |
348 | | | 350 | |
349 | sendsig_reset(l, sig); | | 351 | sendsig_reset(l, sig); |
350 | | | 352 | |
351 | /* | | 353 | /* |
352 | * Now copy the stack contents out to user space. | | 354 | * Now copy the stack contents out to user space. |
353 | * We need to make sure that when we start the signal handler, | | 355 | * We need to make sure that when we start the signal handler, |
354 | * its %i6 (%fp), which is loaded from the newly allocated stack area, | | 356 | * its %i6 (%fp), which is loaded from the newly allocated stack area, |
355 | * joins seamlessly with the frame it was in when the signal occurred, | | 357 | * joins seamlessly with the frame it was in when the signal occurred, |
356 | * so that the debugger and _longjmp code can back up through it. | | 358 | * so that the debugger and _longjmp code can back up through it. |
357 | * Since we're calling the handler directly, allocate a full size | | 359 | * Since we're calling the handler directly, allocate a full size |
358 | * C stack frame. | | 360 | * C stack frame. |
359 | */ | | 361 | */ |
360 | mutex_exit(p->p_lock); | | 362 | mutex_exit(p->p_lock); |
361 | cpu_getmcontext32(l, &uc.uc_mcontext, &uc.uc_flags); | | 363 | cpu_getmcontext32(l, &uc.uc_mcontext, &uc.uc_flags); |
| | | 364 | netbsd32_si_to_si32(&si32, (const siginfo_t *)&ksi->ksi_info); |
362 | ucsz = (int)(intptr_t)&uc.__uc_pad - (int)(intptr_t)&uc; | | 365 | ucsz = (int)(intptr_t)&uc.__uc_pad - (int)(intptr_t)&uc; |
363 | newsp = (struct rwindow32*)((intptr_t)fp - sizeof(struct frame32)); | | 366 | newsp = (struct rwindow32*)((intptr_t)fp - sizeof(struct frame32)); |
364 | error = (copyout(&ksi->ksi_info, &fp->sf_si, sizeof ksi->ksi_info) || | | 367 | error = (copyout(&si32, &fp->sf_si, sizeof si32) || |
365 | copyout(&uc, &fp->sf_uc, ucsz) || | | 368 | copyout(&uc, &fp->sf_uc, ucsz) || |
366 | suword(&newsp->rw_in[6], (intptr_t)oldsp)); | | 369 | suword(&newsp->rw_in[6], (intptr_t)oldsp)); |
367 | mutex_enter(p->p_lock); | | 370 | mutex_enter(p->p_lock); |
368 | | | 371 | |
369 | if (error) { | | 372 | if (error) { |
370 | /* | | 373 | /* |
371 | * Process has trashed its stack; give it an illegal | | 374 | * Process has trashed its stack; give it an illegal |
372 | * instruction to halt it in its tracks. | | 375 | * instruction to halt it in its tracks. |
373 | */ | | 376 | */ |
374 | sigexit(l, SIGILL); | | 377 | sigexit(l, SIGILL); |
375 | /* NOTREACHED */ | | 378 | /* NOTREACHED */ |
376 | } | | 379 | } |
377 | | | 380 | |