3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * Copyright 2023 Oxide Computer Company
33 */
34
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/sysmacros.h>
38 #include <sys/signal.h>
39 #include <sys/systm.h>
40 #include <sys/user.h>
41 #include <sys/mman.h>
42 #include <sys/class.h>
74 #include <vm/as.h>
75 #include <vm/page.h>
76 #include <vm/seg.h>
77 #include <vm/seg_kmem.h>
78 #include <vm/seg_map.h>
79 #include <vm/seg_vn.h>
80 #include <sys/exec.h>
81 #include <sys/acct.h>
82 #include <sys/core.h>
83 #include <sys/corectl.h>
84 #include <sys/modctl.h>
85 #include <sys/tuneable.h>
86 #include <c2/audit.h>
87 #include <sys/bootconf.h>
88 #include <sys/dumphdr.h>
89 #include <sys/promif.h>
90 #include <sys/systeminfo.h>
91 #include <sys/kdi.h>
92 #include <sys/contract_impl.h>
93 #include <sys/x86_archext.h>
94
95 /*
96 * Construct the execution environment for the user's signal
97 * handler and arrange for control to be given to it on return
98 * to userland. The library code now calls setcontext() to
99 * clean up after the signal handler, so sigret() is no longer
100 * needed.
101 *
102 * (The various 'volatile' declarations are need to ensure that values
103 * are correct on the error return from on_fault().)
104 */
105
106
107 /*
108 * An amd64 signal frame looks like this on the stack:
109 *
110 * old %rsp:
111 * <128 bytes of untouched stack space>
112 * <a siginfo_t [optional]>
113 * <a ucontext_t>
187 minstacksz += SA(sizeof (siginfo_t));
188
189 if (fpu_xsave_enabled()) {
190 xsave_size = SA(fpu_signal_size(lwp));
191 minstacksz += xsave_size;
192 } else {
193 xsave_size = 0;
194 }
195
196 ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
197
198 /*
199 * Figure out whether we will be handling this signal on
200 * an alternate stack specified by the user. Then allocate
201 * and validate the stack requirements for the signal handler
202 * context. on_fault will catch any faults.
203 */
204 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
205 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
206
207 if (newstack) {
208 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
209 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
210 } else {
211 /*
212 * Drop below the 128-byte reserved region of the stack frame
213 * we're interrupting.
214 */
215 fp = (caddr_t)rp->r_sp - STACK_RESERVE;
216 }
217
218 /*
219 * Force proper stack pointer alignment, even in the face of a
220 * misaligned stack pointer from user-level before the signal.
221 */
222 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
223
224 /*
225 * Most of the time during normal execution, the stack pointer
226 * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
227 * (for example) just after a call instruction (which pushes
307 * ucontext_t and its %xmm registers. The xsave state part of the
308 * ucontext_t may be inbetween these two. However, we have ensured that
309 * the size of the stack space is 16-byte aligned as the actual size may
310 * vary.
311 */
312 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
313 if (xsave_size != 0) {
314 tuc->uc_xsave = (unsigned long)(sp + sizeof (struct sigframe));
315 }
316 uc = (ucontext_t *)(sp + sizeof (struct sigframe) + xsave_size);
317 ret = savecontext(tuc, &lwp->lwp_sigoldmask, SAVECTXT_F_EXTD |
318 SAVECTXT_F_ONFAULT);
319 if (ret != 0)
320 goto postfault;
321 if (on_fault(&ljb))
322 goto badstack;
323 copyout_noerr(tuc, uc, sizeof (*tuc));
324 kmem_free(tuc, sizeof (*tuc));
325 tuc = NULL;
326
327 lwp->lwp_oldcontext = (uintptr_t)uc;
328
329 if (newstack) {
330 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
331 if (lwp->lwp_ustack)
332 copyout_noerr(&lwp->lwp_sigaltstack,
333 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
334 }
335
336 /*
337 * Set up signal handler return and stack linkage
338 */
339 {
340 struct sigframe frame;
341
342 /*
343 * ensure we never return "normally"
344 */
345 frame.retaddr = (caddr_t)(uintptr_t)-1L;
346 frame.signo = sig;
356 * Set up user registers for execution of signal handler.
357 */
358 rp->r_sp = (greg_t)sp;
359 rp->r_pc = (greg_t)hdlr;
360 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
361
362 rp->r_rdi = sig;
363 rp->r_rsi = (uintptr_t)sip_addr;
364 rp->r_rdx = (uintptr_t)uc;
365
366 if ((rp->r_cs & 0xffff) != UCS_SEL ||
367 (rp->r_ss & 0xffff) != UDS_SEL) {
368 /*
369 * Try our best to deliver the signal.
370 */
371 rp->r_cs = UCS_SEL;
372 rp->r_ss = UDS_SEL;
373 }
374
375 /*
376 * Don't set lwp_eosys here. sendsig() is called via psig() after
377 * lwp_eosys is handled, so setting it here would affect the next
378 * system call.
379 */
380 return (1);
381
382 badstack:
383 no_fault();
384 postfault:
385 if (watched)
386 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
387 if (tuc)
388 kmem_free(tuc, sizeof (*tuc));
389 #ifdef DEBUG
390 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
391 PTOU(p)->u_comm, p->p_pid, sig);
392 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
393 (void *)sp, (void *)hdlr, (uintptr_t)upc);
394 #endif
395 return (0);
442 if (sip != NULL)
443 minstacksz += SA32(sizeof (siginfo32_t));
444
445 if (fpu_xsave_enabled()) {
446 xsave_size = SA32(fpu_signal_size(lwp));
447 minstacksz += xsave_size;
448 } else {
449 xsave_size = 0;
450 }
451 ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
452
453 /*
454 * Figure out whether we will be handling this signal on
455 * an alternate stack specified by the user. Then allocate
456 * and validate the stack requirements for the signal handler
457 * context. on_fault will catch any faults.
458 */
459 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
460 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
461
462 if (newstack) {
463 fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
464 SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
465 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
466 user_desc_t *ldt;
467 /*
468 * If the stack segment selector is -not- pointing at
469 * the UDS_SEL descriptor and we have an LDT entry for
470 * it instead, add the base address to find the effective va.
471 */
472 if ((ldt = p->p_ldt) != NULL)
473 fp = (caddr_t)rp->r_sp +
474 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
475 else
476 fp = (caddr_t)rp->r_sp;
477 } else
478 fp = (caddr_t)rp->r_sp;
479
480 /*
481 * Force proper stack pointer alignment, even in the face of a
482 * misaligned stack pointer from user-level before the signal.
483 * Don't use the SA32() macro because that rounds up, not down.
484 */
485 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
486 sp = fp - minstacksz;
487
488 /*
489 * Make sure lwp hasn't trashed its stack
490 */
491 if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
492 fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
493 #ifdef DEBUG
494 printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
495 PTOU(p)->u_comm, p->p_pid, sig);
496 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
497 (void *)sp, (void *)hdlr, (uintptr_t)upc);
498 printf("sp above USERLIMIT\n");
546 no_fault();
547
548 /* save the current context on the user stack */
549 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
550 fp -= SA32(sizeof (*tuc));
551 uc = (ucontext32_t *)fp;
552 if (xsave_size != 0) {
553 fp -= xsave_size;
554 tuc->uc_xsave = (int32_t)(uintptr_t)fp;
555 }
556 ret = savecontext32(tuc, &lwp->lwp_sigoldmask, SAVECTXT_F_EXTD |
557 SAVECTXT_F_ONFAULT);
558 if (ret != 0)
559 goto postfault;
560 if (on_fault(&ljb))
561 goto badstack;
562 copyout_noerr(tuc, uc, sizeof (*tuc));
563 kmem_free(tuc, sizeof (*tuc));
564 tuc = NULL;
565
566 lwp->lwp_oldcontext = (uintptr_t)uc;
567
568 if (newstack) {
569 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
570 if (lwp->lwp_ustack) {
571 stack32_t stk32;
572
573 stk32.ss_sp = (caddr32_t)(uintptr_t)
574 lwp->lwp_sigaltstack.ss_sp;
575 stk32.ss_size = (size32_t)
576 lwp->lwp_sigaltstack.ss_size;
577 stk32.ss_flags = (int32_t)
578 lwp->lwp_sigaltstack.ss_flags;
579 copyout_noerr(&stk32,
580 (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
581 }
582 }
583
584 /*
585 * Set up signal handler arguments
594 copyout_noerr(&frame32, sp, sizeof (frame32));
595 }
596
597 no_fault();
598 if (watched)
599 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
600
601 rp->r_sp = (greg_t)(uintptr_t)sp;
602 rp->r_pc = (greg_t)(uintptr_t)hdlr;
603 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
604
605 if ((rp->r_cs & 0xffff) != U32CS_SEL ||
606 (rp->r_ss & 0xffff) != UDS_SEL) {
607 /*
608 * Try our best to deliver the signal.
609 */
610 rp->r_cs = U32CS_SEL;
611 rp->r_ss = UDS_SEL;
612 }
613
614 /*
615 * Don't set lwp_eosys here. sendsig() is called via psig() after
616 * lwp_eosys is handled, so setting it here would affect the next
617 * system call.
618 */
619 return (1);
620
621 badstack:
622 no_fault();
623 postfault:
624 if (watched)
625 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
626 if (tuc)
627 kmem_free(tuc, sizeof (*tuc));
628 #ifdef DEBUG
629 printf("sendsig32: bad signal stack cmd=%s pid=%d, sig=%d\n",
630 PTOU(p)->u_comm, p->p_pid, sig);
631 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
632 (void *)sp, (void *)hdlr, (uintptr_t)upc);
633 #endif
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 Joyent, Inc.
24 */
25 /*
26 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
32 /* All Rights Reserved */
33
34 /*
35 * Copyright 2023 Oxide Computer Company
36 */
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/sysmacros.h>
41 #include <sys/signal.h>
42 #include <sys/systm.h>
43 #include <sys/user.h>
44 #include <sys/mman.h>
45 #include <sys/class.h>
77 #include <vm/as.h>
78 #include <vm/page.h>
79 #include <vm/seg.h>
80 #include <vm/seg_kmem.h>
81 #include <vm/seg_map.h>
82 #include <vm/seg_vn.h>
83 #include <sys/exec.h>
84 #include <sys/acct.h>
85 #include <sys/core.h>
86 #include <sys/corectl.h>
87 #include <sys/modctl.h>
88 #include <sys/tuneable.h>
89 #include <c2/audit.h>
90 #include <sys/bootconf.h>
91 #include <sys/dumphdr.h>
92 #include <sys/promif.h>
93 #include <sys/systeminfo.h>
94 #include <sys/kdi.h>
95 #include <sys/contract_impl.h>
96 #include <sys/x86_archext.h>
97 #include <sys/brand.h>
98 #include <sys/sdt.h>
99
100 /*
101 * Construct the execution environment for the user's signal
102 * handler and arrange for control to be given to it on return
103 * to userland. The library code now calls setcontext() to
104 * clean up after the signal handler, so sigret() is no longer
105 * needed.
106 *
107 * (The various 'volatile' declarations are need to ensure that values
108 * are correct on the error return from on_fault().)
109 */
110
111
112 /*
113 * An amd64 signal frame looks like this on the stack:
114 *
115 * old %rsp:
116 * <128 bytes of untouched stack space>
117 * <a siginfo_t [optional]>
118 * <a ucontext_t>
192 minstacksz += SA(sizeof (siginfo_t));
193
194 if (fpu_xsave_enabled()) {
195 xsave_size = SA(fpu_signal_size(lwp));
196 minstacksz += xsave_size;
197 } else {
198 xsave_size = 0;
199 }
200
201 ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
202
203 /*
204 * Figure out whether we will be handling this signal on
205 * an alternate stack specified by the user. Then allocate
206 * and validate the stack requirements for the signal handler
207 * context. on_fault will catch any faults.
208 */
209 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
210 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
211
212 /*
213 * If this is a branded process, the brand may provide an alternate
214 * stack pointer for signal delivery:
215 */
216 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig_stack != NULL) {
217 /*
218 * Use the stack pointer value provided by the brand,
219 * accounting for the 128-byte reserved region.
220 */
221 newstack = 0;
222 fp = BROP(p)->b_sendsig_stack(sig) - STACK_RESERVE;
223 } else if (newstack) {
224 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
225 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
226 } else {
227 /*
228 * Drop below the 128-byte reserved region of the stack frame
229 * we're interrupting.
230 */
231 fp = (caddr_t)rp->r_sp - STACK_RESERVE;
232 }
233
234 /*
235 * Force proper stack pointer alignment, even in the face of a
236 * misaligned stack pointer from user-level before the signal.
237 */
238 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
239
240 /*
241 * Most of the time during normal execution, the stack pointer
242 * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
243 * (for example) just after a call instruction (which pushes
323 * ucontext_t and its %xmm registers. The xsave state part of the
324 * ucontext_t may be inbetween these two. However, we have ensured that
325 * the size of the stack space is 16-byte aligned as the actual size may
326 * vary.
327 */
328 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
329 if (xsave_size != 0) {
330 tuc->uc_xsave = (unsigned long)(sp + sizeof (struct sigframe));
331 }
332 uc = (ucontext_t *)(sp + sizeof (struct sigframe) + xsave_size);
333 ret = savecontext(tuc, &lwp->lwp_sigoldmask, SAVECTXT_F_EXTD |
334 SAVECTXT_F_ONFAULT);
335 if (ret != 0)
336 goto postfault;
337 if (on_fault(&ljb))
338 goto badstack;
339 copyout_noerr(tuc, uc, sizeof (*tuc));
340 kmem_free(tuc, sizeof (*tuc));
341 tuc = NULL;
342
343 DTRACE_PROBE3(oldcontext__set, klwp_t *, lwp,
344 uintptr_t, lwp->lwp_oldcontext, uintptr_t, (uintptr_t)uc);
345 lwp->lwp_oldcontext = (uintptr_t)uc;
346
347 if (newstack) {
348 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
349 if (lwp->lwp_ustack)
350 copyout_noerr(&lwp->lwp_sigaltstack,
351 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
352 }
353
354 /*
355 * Set up signal handler return and stack linkage
356 */
357 {
358 struct sigframe frame;
359
360 /*
361 * ensure we never return "normally"
362 */
363 frame.retaddr = (caddr_t)(uintptr_t)-1L;
364 frame.signo = sig;
374 * Set up user registers for execution of signal handler.
375 */
376 rp->r_sp = (greg_t)sp;
377 rp->r_pc = (greg_t)hdlr;
378 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
379
380 rp->r_rdi = sig;
381 rp->r_rsi = (uintptr_t)sip_addr;
382 rp->r_rdx = (uintptr_t)uc;
383
384 if ((rp->r_cs & 0xffff) != UCS_SEL ||
385 (rp->r_ss & 0xffff) != UDS_SEL) {
386 /*
387 * Try our best to deliver the signal.
388 */
389 rp->r_cs = UCS_SEL;
390 rp->r_ss = UDS_SEL;
391 }
392
393 /*
394 * Allow the brand to perform additional book-keeping once the signal
395 * handling frame has been fully assembled:
396 */
397 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig != NULL) {
398 BROP(p)->b_sendsig(sig);
399 }
400
401 /*
402 * Don't set lwp_eosys here. sendsig() is called via psig() after
403 * lwp_eosys is handled, so setting it here would affect the next
404 * system call.
405 */
406 return (1);
407
408 badstack:
409 no_fault();
410 postfault:
411 if (watched)
412 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
413 if (tuc)
414 kmem_free(tuc, sizeof (*tuc));
415 #ifdef DEBUG
416 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
417 PTOU(p)->u_comm, p->p_pid, sig);
418 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
419 (void *)sp, (void *)hdlr, (uintptr_t)upc);
420 #endif
421 return (0);
468 if (sip != NULL)
469 minstacksz += SA32(sizeof (siginfo32_t));
470
471 if (fpu_xsave_enabled()) {
472 xsave_size = SA32(fpu_signal_size(lwp));
473 minstacksz += xsave_size;
474 } else {
475 xsave_size = 0;
476 }
477 ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
478
479 /*
480 * Figure out whether we will be handling this signal on
481 * an alternate stack specified by the user. Then allocate
482 * and validate the stack requirements for the signal handler
483 * context. on_fault will catch any faults.
484 */
485 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
486 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
487
488 /*
489 * If this is a branded process, the brand may provide an alternate
490 * stack pointer for signal delivery:
491 */
492 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig_stack != NULL) {
493 /*
494 * Use the stack pointer value provided by the brand:
495 */
496 newstack = 0;
497 fp = BROP(p)->b_sendsig_stack(sig);
498 } else if (newstack) {
499 fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
500 SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
501 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
502 user_desc_t *ldt;
503 /*
504 * If the stack segment selector is -not- pointing at
505 * the UDS_SEL descriptor and we have an LDT entry for
506 * it instead, add the base address to find the effective va.
507 */
508 if ((ldt = p->p_ldt) != NULL)
509 fp = (caddr_t)rp->r_sp +
510 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
511 else
512 fp = (caddr_t)rp->r_sp;
513 } else {
514 fp = (caddr_t)rp->r_sp;
515 }
516
517 /*
518 * Force proper stack pointer alignment, even in the face of a
519 * misaligned stack pointer from user-level before the signal.
520 * Don't use the SA32() macro because that rounds up, not down.
521 */
522 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
523 sp = fp - minstacksz;
524
525 /*
526 * Make sure lwp hasn't trashed its stack
527 */
528 if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
529 fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
530 #ifdef DEBUG
531 printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
532 PTOU(p)->u_comm, p->p_pid, sig);
533 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
534 (void *)sp, (void *)hdlr, (uintptr_t)upc);
535 printf("sp above USERLIMIT\n");
583 no_fault();
584
585 /* save the current context on the user stack */
586 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
587 fp -= SA32(sizeof (*tuc));
588 uc = (ucontext32_t *)fp;
589 if (xsave_size != 0) {
590 fp -= xsave_size;
591 tuc->uc_xsave = (int32_t)(uintptr_t)fp;
592 }
593 ret = savecontext32(tuc, &lwp->lwp_sigoldmask, SAVECTXT_F_EXTD |
594 SAVECTXT_F_ONFAULT);
595 if (ret != 0)
596 goto postfault;
597 if (on_fault(&ljb))
598 goto badstack;
599 copyout_noerr(tuc, uc, sizeof (*tuc));
600 kmem_free(tuc, sizeof (*tuc));
601 tuc = NULL;
602
603 DTRACE_PROBE3(oldcontext__set, klwp_t *, lwp,
604 uintptr_t, lwp->lwp_oldcontext, uintptr_t, (uintptr_t)uc);
605 lwp->lwp_oldcontext = (uintptr_t)uc;
606
607 if (newstack) {
608 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
609 if (lwp->lwp_ustack) {
610 stack32_t stk32;
611
612 stk32.ss_sp = (caddr32_t)(uintptr_t)
613 lwp->lwp_sigaltstack.ss_sp;
614 stk32.ss_size = (size32_t)
615 lwp->lwp_sigaltstack.ss_size;
616 stk32.ss_flags = (int32_t)
617 lwp->lwp_sigaltstack.ss_flags;
618 copyout_noerr(&stk32,
619 (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
620 }
621 }
622
623 /*
624 * Set up signal handler arguments
633 copyout_noerr(&frame32, sp, sizeof (frame32));
634 }
635
636 no_fault();
637 if (watched)
638 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
639
640 rp->r_sp = (greg_t)(uintptr_t)sp;
641 rp->r_pc = (greg_t)(uintptr_t)hdlr;
642 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
643
644 if ((rp->r_cs & 0xffff) != U32CS_SEL ||
645 (rp->r_ss & 0xffff) != UDS_SEL) {
646 /*
647 * Try our best to deliver the signal.
648 */
649 rp->r_cs = U32CS_SEL;
650 rp->r_ss = UDS_SEL;
651 }
652
653 /*
654 * Allow the brand to perform additional book-keeping once the signal
655 * handling frame has been fully assembled:
656 */
657 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig != NULL) {
658 BROP(p)->b_sendsig(sig);
659 }
660
661 /*
662 * Don't set lwp_eosys here. sendsig() is called via psig() after
663 * lwp_eosys is handled, so setting it here would affect the next
664 * system call.
665 */
666 return (1);
667
668 badstack:
669 no_fault();
670 postfault:
671 if (watched)
672 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
673 if (tuc)
674 kmem_free(tuc, sizeof (*tuc));
675 #ifdef DEBUG
676 printf("sendsig32: bad signal stack cmd=%s pid=%d, sig=%d\n",
677 PTOU(p)->u_comm, p->p_pid, sig);
678 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
679 (void *)sp, (void *)hdlr, (uintptr_t)upc);
680 #endif
|