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 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/sysmacros.h>
34 #include <sys/signal.h>
35 #include <sys/systm.h>
36 #include <sys/user.h>
37 #include <sys/mman.h>
38 #include <sys/class.h>
39 #include <sys/proc.h>
40 #include <sys/procfs.h>
41 #include <sys/buf.h>
42 #include <sys/kmem.h>
70 #include <vm/as.h>
71 #include <vm/page.h>
72 #include <vm/seg.h>
73 #include <vm/seg_kmem.h>
74 #include <vm/seg_map.h>
75 #include <vm/seg_vn.h>
76 #include <sys/exec.h>
77 #include <sys/acct.h>
78 #include <sys/core.h>
79 #include <sys/corectl.h>
80 #include <sys/modctl.h>
81 #include <sys/tuneable.h>
82 #include <c2/audit.h>
83 #include <sys/bootconf.h>
84 #include <sys/dumphdr.h>
85 #include <sys/promif.h>
86 #include <sys/systeminfo.h>
87 #include <sys/kdi.h>
88 #include <sys/contract_impl.h>
89 #include <sys/x86_archext.h>
90
91 /*
92 * Construct the execution environment for the user's signal
93 * handler and arrange for control to be given to it on return
94 * to userland. The library code now calls setcontext() to
95 * clean up after the signal handler, so sigret() is no longer
96 * needed.
97 *
98 * (The various 'volatile' declarations are need to ensure that values
99 * are correct on the error return from on_fault().)
100 */
101
102 #if defined(__amd64)
103
104 /*
105 * An amd64 signal frame looks like this on the stack:
106 *
107 * old %rsp:
108 * <128 bytes of untouched stack space>
109 * <a siginfo_t [optional]>
169 * not 16-bytes. This will place ucontext_t at a nice 16-byte boundary.
170 */
171
172 /* LINTED: logical expression always true: op "||" */
173 ASSERT((sizeof (struct sigframe) % 16) == 8);
174
175 minstacksz = sizeof (struct sigframe) + SA(sizeof (*uc));
176 if (sip != NULL)
177 minstacksz += SA(sizeof (siginfo_t));
178 ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
179
180 /*
181 * Figure out whether we will be handling this signal on
182 * an alternate stack specified by the user. Then allocate
183 * and validate the stack requirements for the signal handler
184 * context. on_fault will catch any faults.
185 */
186 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
187 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
188
189 if (newstack) {
190 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
191 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
192 } else {
193 /*
194 * Drop below the 128-byte reserved region of the stack frame
195 * we're interrupting.
196 */
197 fp = (caddr_t)rp->r_sp - STACK_RESERVE;
198 }
199
200 /*
201 * Force proper stack pointer alignment, even in the face of a
202 * misaligned stack pointer from user-level before the signal.
203 */
204 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
205
206 /*
207 * Most of the time during normal execution, the stack pointer
208 * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
209 * (for example) just after a call instruction (which pushes
279 }
280 } else
281 sip_addr = NULL;
282
283 /*
284 * save the current context on the user stack directly after the
285 * sigframe. Since sigframe is 8-byte-but-not-16-byte aligned,
286 * and since sizeof (struct sigframe) is 24, this guarantees
287 * 16-byte alignment for ucontext_t and its %xmm registers.
288 */
289 uc = (ucontext_t *)(sp + sizeof (struct sigframe));
290 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
291 no_fault();
292 savecontext(tuc, &lwp->lwp_sigoldmask);
293 if (on_fault(&ljb))
294 goto badstack;
295 copyout_noerr(tuc, uc, sizeof (*tuc));
296 kmem_free(tuc, sizeof (*tuc));
297 tuc = NULL;
298
299 lwp->lwp_oldcontext = (uintptr_t)uc;
300
301 if (newstack) {
302 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
303 if (lwp->lwp_ustack)
304 copyout_noerr(&lwp->lwp_sigaltstack,
305 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
306 }
307
308 /*
309 * Set up signal handler return and stack linkage
310 */
311 {
312 struct sigframe frame;
313
314 /*
315 * ensure we never return "normally"
316 */
317 frame.retaddr = (caddr_t)(uintptr_t)-1L;
318 frame.signo = sig;
328 * Set up user registers for execution of signal handler.
329 */
330 rp->r_sp = (greg_t)sp;
331 rp->r_pc = (greg_t)hdlr;
332 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
333
334 rp->r_rdi = sig;
335 rp->r_rsi = (uintptr_t)sip_addr;
336 rp->r_rdx = (uintptr_t)uc;
337
338 if ((rp->r_cs & 0xffff) != UCS_SEL ||
339 (rp->r_ss & 0xffff) != UDS_SEL) {
340 /*
341 * Try our best to deliver the signal.
342 */
343 rp->r_cs = UCS_SEL;
344 rp->r_ss = UDS_SEL;
345 }
346
347 /*
348 * Don't set lwp_eosys here. sendsig() is called via psig() after
349 * lwp_eosys is handled, so setting it here would affect the next
350 * system call.
351 */
352 return (1);
353
354 badstack:
355 no_fault();
356 if (watched)
357 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
358 if (tuc)
359 kmem_free(tuc, sizeof (*tuc));
360 #ifdef DEBUG
361 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
362 PTOU(p)->u_comm, p->p_pid, sig);
363 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
364 (void *)sp, (void *)hdlr, (uintptr_t)upc);
365 #endif
366 return (0);
367 }
403 siginfo32_t *sip_addr;
404 volatile int watched;
405
406 rp = lwptoregs(lwp);
407 upc = rp->r_pc;
408
409 minstacksz = SA32(sizeof (struct sigframe32)) + SA32(sizeof (*uc));
410 if (sip != NULL)
411 minstacksz += SA32(sizeof (siginfo32_t));
412 ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
413
414 /*
415 * Figure out whether we will be handling this signal on
416 * an alternate stack specified by the user. Then allocate
417 * and validate the stack requirements for the signal handler
418 * context. on_fault will catch any faults.
419 */
420 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
421 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
422
423 if (newstack) {
424 fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
425 SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
426 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
427 user_desc_t *ldt;
428 /*
429 * If the stack segment selector is -not- pointing at
430 * the UDS_SEL descriptor and we have an LDT entry for
431 * it instead, add the base address to find the effective va.
432 */
433 if ((ldt = p->p_ldt) != NULL)
434 fp = (caddr_t)rp->r_sp +
435 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
436 else
437 fp = (caddr_t)rp->r_sp;
438 } else
439 fp = (caddr_t)rp->r_sp;
440
441 /*
442 * Force proper stack pointer alignment, even in the face of a
443 * misaligned stack pointer from user-level before the signal.
444 * Don't use the SA32() macro because that rounds up, not down.
445 */
446 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
447 sp = fp - minstacksz;
448
449 /*
450 * Make sure lwp hasn't trashed its stack
451 */
452 if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
453 fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
454 #ifdef DEBUG
455 printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
456 PTOU(p)->u_comm, p->p_pid, sig);
457 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
458 (void *)sp, (void *)hdlr, (uintptr_t)upc);
459 printf("sp above USERLIMIT\n");
500 (uint32_t)lwp->lwp_arg[i]);
501 copyout_noerr(curthread->t_rprof->rp_state,
502 sip_addr->si_mstate,
503 sizeof (curthread->t_rprof->rp_state));
504 }
505 } else
506 sip_addr = NULL;
507
508 /* save the current context on the user stack */
509 fp -= SA32(sizeof (*tuc));
510 uc = (ucontext32_t *)fp;
511 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
512 no_fault();
513 savecontext32(tuc, &lwp->lwp_sigoldmask);
514 if (on_fault(&ljb))
515 goto badstack;
516 copyout_noerr(tuc, uc, sizeof (*tuc));
517 kmem_free(tuc, sizeof (*tuc));
518 tuc = NULL;
519
520 lwp->lwp_oldcontext = (uintptr_t)uc;
521
522 if (newstack) {
523 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
524 if (lwp->lwp_ustack) {
525 stack32_t stk32;
526
527 stk32.ss_sp = (caddr32_t)(uintptr_t)
528 lwp->lwp_sigaltstack.ss_sp;
529 stk32.ss_size = (size32_t)
530 lwp->lwp_sigaltstack.ss_size;
531 stk32.ss_flags = (int32_t)
532 lwp->lwp_sigaltstack.ss_flags;
533 copyout_noerr(&stk32,
534 (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
535 }
536 }
537
538 /*
539 * Set up signal handler arguments
549 }
550
551 no_fault();
552 if (watched)
553 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
554
555 rp->r_sp = (greg_t)(uintptr_t)sp;
556 rp->r_pc = (greg_t)(uintptr_t)hdlr;
557 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
558
559 if ((rp->r_cs & 0xffff) != U32CS_SEL ||
560 (rp->r_ss & 0xffff) != UDS_SEL) {
561 /*
562 * Try our best to deliver the signal.
563 */
564 rp->r_cs = U32CS_SEL;
565 rp->r_ss = UDS_SEL;
566 }
567
568 /*
569 * Don't set lwp_eosys here. sendsig() is called via psig() after
570 * lwp_eosys is handled, so setting it here would affect the next
571 * system call.
572 */
573 return (1);
574
575 badstack:
576 no_fault();
577 if (watched)
578 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
579 if (tuc)
580 kmem_free(tuc, sizeof (*tuc));
581 #ifdef DEBUG
582 printf("sendsig32: bad signal stack cmd=%s pid=%d, sig=%d\n",
583 PTOU(p)->u_comm, p->p_pid, sig);
584 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
585 (void *)sp, (void *)hdlr, (uintptr_t)upc);
586 #endif
587 return (0);
588 }
626 siginfo_t *sip_addr;
627 volatile int watched;
628
629 rp = lwptoregs(lwp);
630 upc = rp->r_pc;
631
632 minstacksz = SA(sizeof (struct sigframe)) + SA(sizeof (*uc));
633 if (sip != NULL)
634 minstacksz += SA(sizeof (siginfo_t));
635 ASSERT((minstacksz & (STACK_ALIGN - 1ul)) == 0);
636
637 /*
638 * Figure out whether we will be handling this signal on
639 * an alternate stack specified by the user. Then allocate
640 * and validate the stack requirements for the signal handler
641 * context. on_fault will catch any faults.
642 */
643 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
644 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
645
646 if (newstack) {
647 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
648 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
649 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
650 user_desc_t *ldt;
651 /*
652 * If the stack segment selector is -not- pointing at
653 * the UDS_SEL descriptor and we have an LDT entry for
654 * it instead, add the base address to find the effective va.
655 */
656 if ((ldt = p->p_ldt) != NULL)
657 fp = (caddr_t)rp->r_sp +
658 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
659 else
660 fp = (caddr_t)rp->r_sp;
661 } else
662 fp = (caddr_t)rp->r_sp;
663
664 /*
665 * Force proper stack pointer alignment, even in the face of a
666 * misaligned stack pointer from user-level before the signal.
667 * Don't use the SA() macro because that rounds up, not down.
668 */
669 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN - 1ul));
670 sp = fp - minstacksz;
671
672 /*
673 * Make sure lwp hasn't trashed its stack.
674 */
675 if (sp >= (caddr_t)USERLIMIT || fp >= (caddr_t)USERLIMIT) {
676 #ifdef DEBUG
677 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
678 PTOU(p)->u_comm, p->p_pid, sig);
679 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
680 (void *)sp, (void *)hdlr, (uintptr_t)upc);
681 printf("sp above USERLIMIT\n");
682 #endif
720
721 while (--i >= 0)
722 suword32_noerr(&(sip_addr->si_sysarg[i]),
723 (uint32_t)lwp->lwp_arg[i]);
724 copyout_noerr(curthread->t_rprof->rp_state,
725 sip_addr->si_mstate,
726 sizeof (curthread->t_rprof->rp_state));
727 }
728 } else
729 sip_addr = NULL;
730
731 /* save the current context on the user stack */
732 fp -= SA(sizeof (*tuc));
733 uc = (ucontext_t *)fp;
734 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
735 savecontext(tuc, &lwp->lwp_sigoldmask);
736 copyout_noerr(tuc, uc, sizeof (*tuc));
737 kmem_free(tuc, sizeof (*tuc));
738 tuc = NULL;
739
740 lwp->lwp_oldcontext = (uintptr_t)uc;
741
742 if (newstack) {
743 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
744 if (lwp->lwp_ustack)
745 copyout_noerr(&lwp->lwp_sigaltstack,
746 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
747 }
748
749 /*
750 * Set up signal handler arguments
751 */
752 {
753 struct sigframe frame;
754
755 frame.sip = sip_addr;
756 frame.ucp = uc;
757 frame.signo = sig;
758 frame.retaddr = (void (*)())0xffffffff; /* never return! */
759 copyout_noerr(&frame, sp, sizeof (frame));
760 }
761
762 no_fault();
763 if (watched)
764 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
765
766 rp->r_sp = (greg_t)sp;
767 rp->r_pc = (greg_t)hdlr;
768 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
769
770 if ((rp->r_cs & 0xffff) != UCS_SEL ||
771 (rp->r_ss & 0xffff) != UDS_SEL) {
772 rp->r_cs = UCS_SEL;
773 rp->r_ss = UDS_SEL;
774 }
775
776 /*
777 * Don't set lwp_eosys here. sendsig() is called via psig() after
778 * lwp_eosys is handled, so setting it here would affect the next
779 * system call.
780 */
781 return (1);
782
783 badstack:
784 no_fault();
785 if (watched)
786 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
787 if (tuc)
788 kmem_free(tuc, sizeof (*tuc));
789 #ifdef DEBUG
790 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
791 PTOU(p)->u_comm, p->p_pid, sig);
792 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
793 (void *)sp, (void *)hdlr, (uintptr_t)upc);
794 #endif
795 return (0);
|
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 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/sysmacros.h>
37 #include <sys/signal.h>
38 #include <sys/systm.h>
39 #include <sys/user.h>
40 #include <sys/mman.h>
41 #include <sys/class.h>
42 #include <sys/proc.h>
43 #include <sys/procfs.h>
44 #include <sys/buf.h>
45 #include <sys/kmem.h>
73 #include <vm/as.h>
74 #include <vm/page.h>
75 #include <vm/seg.h>
76 #include <vm/seg_kmem.h>
77 #include <vm/seg_map.h>
78 #include <vm/seg_vn.h>
79 #include <sys/exec.h>
80 #include <sys/acct.h>
81 #include <sys/core.h>
82 #include <sys/corectl.h>
83 #include <sys/modctl.h>
84 #include <sys/tuneable.h>
85 #include <c2/audit.h>
86 #include <sys/bootconf.h>
87 #include <sys/dumphdr.h>
88 #include <sys/promif.h>
89 #include <sys/systeminfo.h>
90 #include <sys/kdi.h>
91 #include <sys/contract_impl.h>
92 #include <sys/x86_archext.h>
93 #include <sys/brand.h>
94 #include <sys/sdt.h>
95
96 /*
97 * Construct the execution environment for the user's signal
98 * handler and arrange for control to be given to it on return
99 * to userland. The library code now calls setcontext() to
100 * clean up after the signal handler, so sigret() is no longer
101 * needed.
102 *
103 * (The various 'volatile' declarations are need to ensure that values
104 * are correct on the error return from on_fault().)
105 */
106
107 #if defined(__amd64)
108
109 /*
110 * An amd64 signal frame looks like this on the stack:
111 *
112 * old %rsp:
113 * <128 bytes of untouched stack space>
114 * <a siginfo_t [optional]>
174 * not 16-bytes. This will place ucontext_t at a nice 16-byte boundary.
175 */
176
177 /* LINTED: logical expression always true: op "||" */
178 ASSERT((sizeof (struct sigframe) % 16) == 8);
179
180 minstacksz = sizeof (struct sigframe) + SA(sizeof (*uc));
181 if (sip != NULL)
182 minstacksz += SA(sizeof (siginfo_t));
183 ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
184
185 /*
186 * Figure out whether we will be handling this signal on
187 * an alternate stack specified by the user. Then allocate
188 * and validate the stack requirements for the signal handler
189 * context. on_fault will catch any faults.
190 */
191 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
192 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
193
194 /*
195 * If this is a branded process, the brand may provide an alternate
196 * stack pointer for signal delivery:
197 */
198 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig_stack != NULL) {
199 /*
200 * Use the stack pointer value provided by the brand,
201 * accounting for the 128-byte reserved region.
202 */
203 newstack = 0;
204 fp = BROP(p)->b_sendsig_stack(sig) - STACK_RESERVE;
205 } else if (newstack) {
206 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
207 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
208 } else {
209 /*
210 * Drop below the 128-byte reserved region of the stack frame
211 * we're interrupting.
212 */
213 fp = (caddr_t)rp->r_sp - STACK_RESERVE;
214 }
215
216 /*
217 * Force proper stack pointer alignment, even in the face of a
218 * misaligned stack pointer from user-level before the signal.
219 */
220 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
221
222 /*
223 * Most of the time during normal execution, the stack pointer
224 * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
225 * (for example) just after a call instruction (which pushes
295 }
296 } else
297 sip_addr = NULL;
298
299 /*
300 * save the current context on the user stack directly after the
301 * sigframe. Since sigframe is 8-byte-but-not-16-byte aligned,
302 * and since sizeof (struct sigframe) is 24, this guarantees
303 * 16-byte alignment for ucontext_t and its %xmm registers.
304 */
305 uc = (ucontext_t *)(sp + sizeof (struct sigframe));
306 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
307 no_fault();
308 savecontext(tuc, &lwp->lwp_sigoldmask);
309 if (on_fault(&ljb))
310 goto badstack;
311 copyout_noerr(tuc, uc, sizeof (*tuc));
312 kmem_free(tuc, sizeof (*tuc));
313 tuc = NULL;
314
315 DTRACE_PROBE3(oldcontext__set, klwp_t *, lwp,
316 uintptr_t, lwp->lwp_oldcontext, uintptr_t, (uintptr_t)uc);
317 lwp->lwp_oldcontext = (uintptr_t)uc;
318
319 if (newstack) {
320 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
321 if (lwp->lwp_ustack)
322 copyout_noerr(&lwp->lwp_sigaltstack,
323 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
324 }
325
326 /*
327 * Set up signal handler return and stack linkage
328 */
329 {
330 struct sigframe frame;
331
332 /*
333 * ensure we never return "normally"
334 */
335 frame.retaddr = (caddr_t)(uintptr_t)-1L;
336 frame.signo = sig;
346 * Set up user registers for execution of signal handler.
347 */
348 rp->r_sp = (greg_t)sp;
349 rp->r_pc = (greg_t)hdlr;
350 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
351
352 rp->r_rdi = sig;
353 rp->r_rsi = (uintptr_t)sip_addr;
354 rp->r_rdx = (uintptr_t)uc;
355
356 if ((rp->r_cs & 0xffff) != UCS_SEL ||
357 (rp->r_ss & 0xffff) != UDS_SEL) {
358 /*
359 * Try our best to deliver the signal.
360 */
361 rp->r_cs = UCS_SEL;
362 rp->r_ss = UDS_SEL;
363 }
364
365 /*
366 * Allow the brand to perform additional book-keeping once the signal
367 * handling frame has been fully assembled:
368 */
369 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig != NULL) {
370 BROP(p)->b_sendsig(sig);
371 }
372
373 /*
374 * Don't set lwp_eosys here. sendsig() is called via psig() after
375 * lwp_eosys is handled, so setting it here would affect the next
376 * system call.
377 */
378 return (1);
379
380 badstack:
381 no_fault();
382 if (watched)
383 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
384 if (tuc)
385 kmem_free(tuc, sizeof (*tuc));
386 #ifdef DEBUG
387 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
388 PTOU(p)->u_comm, p->p_pid, sig);
389 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
390 (void *)sp, (void *)hdlr, (uintptr_t)upc);
391 #endif
392 return (0);
393 }
429 siginfo32_t *sip_addr;
430 volatile int watched;
431
432 rp = lwptoregs(lwp);
433 upc = rp->r_pc;
434
435 minstacksz = SA32(sizeof (struct sigframe32)) + SA32(sizeof (*uc));
436 if (sip != NULL)
437 minstacksz += SA32(sizeof (siginfo32_t));
438 ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
439
440 /*
441 * Figure out whether we will be handling this signal on
442 * an alternate stack specified by the user. Then allocate
443 * and validate the stack requirements for the signal handler
444 * context. on_fault will catch any faults.
445 */
446 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
447 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
448
449 /*
450 * If this is a branded process, the brand may provide an alternate
451 * stack pointer for signal delivery:
452 */
453 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig_stack != NULL) {
454 /*
455 * Use the stack pointer value provided by the brand:
456 */
457 newstack = 0;
458 fp = BROP(p)->b_sendsig_stack(sig);
459 } else if (newstack) {
460 fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
461 SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
462 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
463 user_desc_t *ldt;
464 /*
465 * If the stack segment selector is -not- pointing at
466 * the UDS_SEL descriptor and we have an LDT entry for
467 * it instead, add the base address to find the effective va.
468 */
469 if ((ldt = p->p_ldt) != NULL)
470 fp = (caddr_t)rp->r_sp +
471 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
472 else
473 fp = (caddr_t)rp->r_sp;
474 } else {
475 fp = (caddr_t)rp->r_sp;
476 }
477
478 /*
479 * Force proper stack pointer alignment, even in the face of a
480 * misaligned stack pointer from user-level before the signal.
481 * Don't use the SA32() macro because that rounds up, not down.
482 */
483 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
484 sp = fp - minstacksz;
485
486 /*
487 * Make sure lwp hasn't trashed its stack
488 */
489 if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
490 fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
491 #ifdef DEBUG
492 printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
493 PTOU(p)->u_comm, p->p_pid, sig);
494 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
495 (void *)sp, (void *)hdlr, (uintptr_t)upc);
496 printf("sp above USERLIMIT\n");
537 (uint32_t)lwp->lwp_arg[i]);
538 copyout_noerr(curthread->t_rprof->rp_state,
539 sip_addr->si_mstate,
540 sizeof (curthread->t_rprof->rp_state));
541 }
542 } else
543 sip_addr = NULL;
544
545 /* save the current context on the user stack */
546 fp -= SA32(sizeof (*tuc));
547 uc = (ucontext32_t *)fp;
548 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
549 no_fault();
550 savecontext32(tuc, &lwp->lwp_sigoldmask);
551 if (on_fault(&ljb))
552 goto badstack;
553 copyout_noerr(tuc, uc, sizeof (*tuc));
554 kmem_free(tuc, sizeof (*tuc));
555 tuc = NULL;
556
557 DTRACE_PROBE3(oldcontext__set, klwp_t *, lwp,
558 uintptr_t, lwp->lwp_oldcontext, uintptr_t, (uintptr_t)uc);
559 lwp->lwp_oldcontext = (uintptr_t)uc;
560
561 if (newstack) {
562 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
563 if (lwp->lwp_ustack) {
564 stack32_t stk32;
565
566 stk32.ss_sp = (caddr32_t)(uintptr_t)
567 lwp->lwp_sigaltstack.ss_sp;
568 stk32.ss_size = (size32_t)
569 lwp->lwp_sigaltstack.ss_size;
570 stk32.ss_flags = (int32_t)
571 lwp->lwp_sigaltstack.ss_flags;
572 copyout_noerr(&stk32,
573 (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
574 }
575 }
576
577 /*
578 * Set up signal handler arguments
588 }
589
590 no_fault();
591 if (watched)
592 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
593
594 rp->r_sp = (greg_t)(uintptr_t)sp;
595 rp->r_pc = (greg_t)(uintptr_t)hdlr;
596 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
597
598 if ((rp->r_cs & 0xffff) != U32CS_SEL ||
599 (rp->r_ss & 0xffff) != UDS_SEL) {
600 /*
601 * Try our best to deliver the signal.
602 */
603 rp->r_cs = U32CS_SEL;
604 rp->r_ss = UDS_SEL;
605 }
606
607 /*
608 * Allow the brand to perform additional book-keeping once the signal
609 * handling frame has been fully assembled:
610 */
611 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig != NULL) {
612 BROP(p)->b_sendsig(sig);
613 }
614
615 /*
616 * Don't set lwp_eosys here. sendsig() is called via psig() after
617 * lwp_eosys is handled, so setting it here would affect the next
618 * system call.
619 */
620 return (1);
621
622 badstack:
623 no_fault();
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
634 return (0);
635 }
673 siginfo_t *sip_addr;
674 volatile int watched;
675
676 rp = lwptoregs(lwp);
677 upc = rp->r_pc;
678
679 minstacksz = SA(sizeof (struct sigframe)) + SA(sizeof (*uc));
680 if (sip != NULL)
681 minstacksz += SA(sizeof (siginfo_t));
682 ASSERT((minstacksz & (STACK_ALIGN - 1ul)) == 0);
683
684 /*
685 * Figure out whether we will be handling this signal on
686 * an alternate stack specified by the user. Then allocate
687 * and validate the stack requirements for the signal handler
688 * context. on_fault will catch any faults.
689 */
690 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
691 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
692
693 /*
694 * If this is a branded process, the brand may provide an alternate
695 * stack pointer for signal delivery:
696 */
697 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig_stack != NULL) {
698 /*
699 * Use the stack pointer value provided by the brand:
700 */
701 newstack = 0;
702 fp = BROP(p)->b_sendsig_stack(sig);
703 } else if (newstack) {
704 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
705 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
706 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
707 user_desc_t *ldt;
708 /*
709 * If the stack segment selector is -not- pointing at
710 * the UDS_SEL descriptor and we have an LDT entry for
711 * it instead, add the base address to find the effective va.
712 */
713 if ((ldt = p->p_ldt) != NULL)
714 fp = (caddr_t)rp->r_sp +
715 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
716 else
717 fp = (caddr_t)rp->r_sp;
718 } else {
719 fp = (caddr_t)rp->r_sp;
720 }
721
722 /*
723 * Force proper stack pointer alignment, even in the face of a
724 * misaligned stack pointer from user-level before the signal.
725 * Don't use the SA() macro because that rounds up, not down.
726 */
727 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN - 1ul));
728 sp = fp - minstacksz;
729
730 /*
731 * Make sure lwp hasn't trashed its stack.
732 */
733 if (sp >= (caddr_t)USERLIMIT || fp >= (caddr_t)USERLIMIT) {
734 #ifdef DEBUG
735 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
736 PTOU(p)->u_comm, p->p_pid, sig);
737 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
738 (void *)sp, (void *)hdlr, (uintptr_t)upc);
739 printf("sp above USERLIMIT\n");
740 #endif
778
779 while (--i >= 0)
780 suword32_noerr(&(sip_addr->si_sysarg[i]),
781 (uint32_t)lwp->lwp_arg[i]);
782 copyout_noerr(curthread->t_rprof->rp_state,
783 sip_addr->si_mstate,
784 sizeof (curthread->t_rprof->rp_state));
785 }
786 } else
787 sip_addr = NULL;
788
789 /* save the current context on the user stack */
790 fp -= SA(sizeof (*tuc));
791 uc = (ucontext_t *)fp;
792 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
793 savecontext(tuc, &lwp->lwp_sigoldmask);
794 copyout_noerr(tuc, uc, sizeof (*tuc));
795 kmem_free(tuc, sizeof (*tuc));
796 tuc = NULL;
797
798 DTRACE_PROBE3(oldcontext__set, klwp_t *, lwp,
799 uintptr_t, lwp->lwp_oldcontext, uintptr_t, (uintptr_t)uc);
800 lwp->lwp_oldcontext = (uintptr_t)uc;
801
802 if (newstack) {
803 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
804 if (lwp->lwp_ustack)
805 copyout_noerr(&lwp->lwp_sigaltstack,
806 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
807 }
808
809 /*
810 * Set up signal handler arguments
811 */
812 {
813 struct sigframe frame;
814
815 frame.sip = sip_addr;
816 frame.ucp = uc;
817 frame.signo = sig;
818 frame.retaddr = (void (*)())0xffffffff; /* never return! */
819 copyout_noerr(&frame, sp, sizeof (frame));
820 }
821
822 no_fault();
823 if (watched)
824 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
825
826 rp->r_sp = (greg_t)sp;
827 rp->r_pc = (greg_t)hdlr;
828 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
829
830 if ((rp->r_cs & 0xffff) != UCS_SEL ||
831 (rp->r_ss & 0xffff) != UDS_SEL) {
832 rp->r_cs = UCS_SEL;
833 rp->r_ss = UDS_SEL;
834 }
835
836 /*
837 * Allow the brand to perform additional book-keeping once the signal
838 * handling frame has been fully assembled:
839 */
840 if (PROC_IS_BRANDED(p) && BROP(p)->b_sendsig != NULL) {
841 BROP(p)->b_sendsig(sig);
842 }
843
844 /*
845 * Don't set lwp_eosys here. sendsig() is called via psig() after
846 * lwp_eosys is handled, so setting it here would affect the next
847 * system call.
848 */
849 return (1);
850
851 badstack:
852 no_fault();
853 if (watched)
854 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
855 if (tuc)
856 kmem_free(tuc, sizeof (*tuc));
857 #ifdef DEBUG
858 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
859 PTOU(p)->u_comm, p->p_pid, sig);
860 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
861 (void *)sp, (void *)hdlr, (uintptr_t)upc);
862 #endif
863 return (0);
|