Merge commit '5e2cca1843c61ee0ef1bb95c5dddc9b450b790c6'
[unleashed.git] / arch / x86 / kernel / os / sendsig.c
blob3856d057655c8ffc25451041ce2cf15fa7b593ad
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
29 /* All Rights Reserved */
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>
43 #include <sys/cred.h>
44 #include <sys/archsystm.h>
45 #include <sys/vmparam.h>
46 #include <sys/prsystm.h>
47 #include <sys/reboot.h>
48 #include <sys/uadmin.h>
49 #include <sys/vfs.h>
50 #include <sys/vnode.h>
51 #include <sys/file.h>
52 #include <sys/session.h>
53 #include <sys/ucontext.h>
54 #include <sys/dnlc.h>
55 #include <sys/var.h>
56 #include <sys/cmn_err.h>
57 #include <sys/debugreg.h>
58 #include <sys/thread.h>
59 #include <sys/vtrace.h>
60 #include <sys/consdev.h>
61 #include <sys/psw.h>
62 #include <sys/regset.h>
64 #include <sys/privregs.h>
66 #include <sys/stack.h>
67 #include <sys/swap.h>
68 #include <vm/hat.h>
69 #include <vm/anon.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 <sys/bootconf.h>
83 #include <sys/dumphdr.h>
84 #include <sys/promif.h>
85 #include <sys/systeminfo.h>
86 #include <sys/kdi.h>
87 #include <sys/contract_impl.h>
88 #include <sys/x86_archext.h>
91 * Construct the execution environment for the user's signal
92 * handler and arrange for control to be given to it on return
93 * to userland. The library code now calls setcontext() to
94 * clean up after the signal handler, so sigret() is no longer
95 * needed.
97 * (The various 'volatile' declarations are need to ensure that values
98 * are correct on the error return from on_fault().)
101 #if defined(__amd64)
104 * An amd64 signal frame looks like this on the stack:
106 * old %rsp:
107 * <128 bytes of untouched stack space>
108 * <a siginfo_t [optional]>
109 * <a ucontext_t>
110 * <siginfo_t *>
111 * <signal number>
112 * new %rsp: <return address (deliberately invalid)>
114 * The signal number and siginfo_t pointer are only pushed onto the stack in
115 * order to allow stack backtraces. The actual signal handling code expects the
116 * arguments in registers.
119 struct sigframe {
120 caddr_t retaddr;
121 long signo;
122 siginfo_t *sip;
126 sendsig(int sig, k_siginfo_t *sip, void (*hdlr)())
128 volatile int minstacksz;
129 int newstack;
130 label_t ljb;
131 volatile caddr_t sp;
132 caddr_t fp;
133 volatile struct regs *rp;
134 volatile greg_t upc;
135 volatile proc_t *p = ttoproc(curthread);
136 struct as *as = p->p_as;
137 klwp_t *lwp = ttolwp(curthread);
138 ucontext_t *volatile tuc = NULL;
139 ucontext_t *uc;
140 siginfo_t *sip_addr;
141 volatile int watched;
144 * This routine is utterly dependent upon STACK_ALIGN being
145 * 16 and STACK_ENTRY_ALIGN being 8. Let's just acknowledge
146 * that and require it.
149 #if STACK_ALIGN != 16 || STACK_ENTRY_ALIGN != 8
150 #error "sendsig() amd64 did not find the expected stack alignments"
151 #endif
153 rp = lwptoregs(lwp);
154 upc = rp->r_pc;
157 * Since we're setting up to run the signal handler we have to
158 * arrange that the stack at entry to the handler is (only)
159 * STACK_ENTRY_ALIGN (i.e. 8) byte aligned so that when the handler
160 * executes its push of %rbp, the stack realigns to STACK_ALIGN
161 * (i.e. 16) correctly.
163 * The new sp will point to the sigframe and the ucontext_t. The
164 * above means that sp (and thus sigframe) will be 8-byte aligned,
165 * but not 16-byte aligned. ucontext_t, however, contains %xmm regs
166 * which must be 16-byte aligned. Because of this, for correct
167 * alignment, sigframe must be a multiple of 8-bytes in length, but
168 * not 16-bytes. This will place ucontext_t at a nice 16-byte boundary.
171 /* LINTED: logical expression always true: op "||" */
172 ASSERT((sizeof (struct sigframe) % 16) == 8);
174 minstacksz = sizeof (struct sigframe) + SA(sizeof (*uc));
175 if (sip != NULL)
176 minstacksz += SA(sizeof (siginfo_t));
177 ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
180 * Figure out whether we will be handling this signal on
181 * an alternate stack specified by the user. Then allocate
182 * and validate the stack requirements for the signal handler
183 * context. on_fault will catch any faults.
185 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
186 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
188 if (newstack) {
189 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
190 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
191 } else {
193 * Drop below the 128-byte reserved region of the stack frame
194 * we're interrupting.
196 fp = (caddr_t)rp->r_sp - STACK_RESERVE;
200 * Force proper stack pointer alignment, even in the face of a
201 * misaligned stack pointer from user-level before the signal.
203 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
206 * Most of the time during normal execution, the stack pointer
207 * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
208 * (for example) just after a call instruction (which pushes
209 * the return address), the callers stack misaligns until the
210 * 'push %rbp' happens in the callee prolog. So while we should
211 * expect the stack pointer to be always at least STACK_ENTRY_ALIGN
212 * aligned, we should -not- expect it to always be STACK_ALIGN aligned.
213 * We now adjust to ensure that the new sp is aligned to
214 * STACK_ENTRY_ALIGN but not to STACK_ALIGN.
216 sp = fp - minstacksz;
217 if (((uintptr_t)sp & (STACK_ALIGN - 1ul)) == 0) {
218 sp -= STACK_ENTRY_ALIGN;
219 minstacksz = fp - sp;
223 * Now, make sure the resulting signal frame address is sane
225 if (sp >= as->a_userlimit || fp >= as->a_userlimit) {
226 #ifdef DEBUG
227 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
228 PTOU(p)->u_comm, p->p_pid, sig);
229 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
230 (void *)sp, (void *)hdlr, (uintptr_t)upc);
231 printf("sp above USERLIMIT\n");
232 #endif
233 return (0);
236 watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
238 if (on_fault(&ljb))
239 goto badstack;
241 if (sip != NULL) {
242 zoneid_t zoneid;
244 fp -= SA(sizeof (siginfo_t));
245 uzero(fp, sizeof (siginfo_t));
246 if (SI_FROMUSER(sip) &&
247 (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
248 zoneid != sip->si_zoneid) {
249 k_siginfo_t sani_sip = *sip;
251 sani_sip.si_pid = p->p_zone->zone_zsched->p_pid;
252 sani_sip.si_uid = 0;
253 sani_sip.si_ctid = -1;
254 sani_sip.si_zoneid = zoneid;
255 copyout_noerr(&sani_sip, fp, sizeof (sani_sip));
256 } else
257 copyout_noerr(sip, fp, sizeof (*sip));
258 sip_addr = (siginfo_t *)fp;
260 if (sig == SIGPROF &&
261 curthread->t_rprof != NULL &&
262 curthread->t_rprof->rp_anystate) {
264 * We stand on our head to deal with
265 * the real time profiling signal.
266 * Fill in the stuff that doesn't fit
267 * in a normal k_siginfo structure.
269 int i = sip->si_nsysarg;
271 while (--i >= 0)
272 sulword_noerr(
273 (ulong_t *)&(sip_addr->si_sysarg[i]),
274 (ulong_t)lwp->lwp_arg[i]);
275 copyout_noerr(curthread->t_rprof->rp_state,
276 sip_addr->si_mstate,
277 sizeof (curthread->t_rprof->rp_state));
279 } else
280 sip_addr = NULL;
283 * save the current context on the user stack directly after the
284 * sigframe. Since sigframe is 8-byte-but-not-16-byte aligned,
285 * and since sizeof (struct sigframe) is 24, this guarantees
286 * 16-byte alignment for ucontext_t and its %xmm registers.
288 uc = (ucontext_t *)(sp + sizeof (struct sigframe));
289 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
290 no_fault();
291 savecontext(tuc, &lwp->lwp_sigoldmask);
292 if (on_fault(&ljb))
293 goto badstack;
294 copyout_noerr(tuc, uc, sizeof (*tuc));
295 kmem_free(tuc, sizeof (*tuc));
296 tuc = NULL;
298 lwp->lwp_oldcontext = (uintptr_t)uc;
300 if (newstack) {
301 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
302 if (lwp->lwp_ustack)
303 copyout_noerr(&lwp->lwp_sigaltstack,
304 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
308 * Set up signal handler return and stack linkage
311 struct sigframe frame;
314 * ensure we never return "normally"
316 frame.retaddr = (caddr_t)(uintptr_t)-1L;
317 frame.signo = sig;
318 frame.sip = sip_addr;
319 copyout_noerr(&frame, sp, sizeof (frame));
322 no_fault();
323 if (watched)
324 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
327 * Set up user registers for execution of signal handler.
329 rp->r_sp = (greg_t)sp;
330 rp->r_pc = (greg_t)hdlr;
331 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
333 rp->r_rdi = sig;
334 rp->r_rsi = (uintptr_t)sip_addr;
335 rp->r_rdx = (uintptr_t)uc;
337 if ((rp->r_cs & 0xffff) != UCS_SEL ||
338 (rp->r_ss & 0xffff) != UDS_SEL) {
340 * Try our best to deliver the signal.
342 rp->r_cs = UCS_SEL;
343 rp->r_ss = UDS_SEL;
347 * Don't set lwp_eosys here. sendsig() is called via psig() after
348 * lwp_eosys is handled, so setting it here would affect the next
349 * system call.
351 return (1);
353 badstack:
354 no_fault();
355 if (watched)
356 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
357 if (tuc)
358 kmem_free(tuc, sizeof (*tuc));
359 #ifdef DEBUG
360 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
361 PTOU(p)->u_comm, p->p_pid, sig);
362 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
363 (void *)sp, (void *)hdlr, (uintptr_t)upc);
364 #endif
365 return (0);
368 #ifdef _SYSCALL32_IMPL
371 * An i386 SVR4/ABI signal frame looks like this on the stack:
373 * old %esp:
374 * <a siginfo32_t [optional]>
375 * <a ucontext32_t>
376 * <pointer to that ucontext32_t>
377 * <pointer to that siginfo32_t>
378 * <signo>
379 * new %esp: <return address (deliberately invalid)>
381 struct sigframe32 {
382 caddr32_t retaddr;
383 uint32_t signo;
384 caddr32_t sip;
385 caddr32_t ucp;
389 sendsig32(int sig, k_siginfo_t *sip, void (*hdlr)())
391 volatile int minstacksz;
392 int newstack;
393 label_t ljb;
394 volatile caddr_t sp;
395 caddr_t fp;
396 volatile struct regs *rp;
397 volatile greg_t upc;
398 volatile proc_t *p = ttoproc(curthread);
399 klwp_t *lwp = ttolwp(curthread);
400 ucontext32_t *volatile tuc = NULL;
401 ucontext32_t *uc;
402 siginfo32_t *sip_addr;
403 volatile int watched;
405 rp = lwptoregs(lwp);
406 upc = rp->r_pc;
408 minstacksz = SA32(sizeof (struct sigframe32)) + SA32(sizeof (*uc));
409 if (sip != NULL)
410 minstacksz += SA32(sizeof (siginfo32_t));
411 ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
414 * Figure out whether we will be handling this signal on
415 * an alternate stack specified by the user. Then allocate
416 * and validate the stack requirements for the signal handler
417 * context. on_fault will catch any faults.
419 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
420 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
422 if (newstack) {
423 fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
424 SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
425 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
426 user_desc_t *ldt;
428 * If the stack segment selector is -not- pointing at
429 * the UDS_SEL descriptor and we have an LDT entry for
430 * it instead, add the base address to find the effective va.
432 if ((ldt = p->p_ldt) != NULL)
433 fp = (caddr_t)rp->r_sp +
434 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
435 else
436 fp = (caddr_t)rp->r_sp;
437 } else
438 fp = (caddr_t)rp->r_sp;
441 * Force proper stack pointer alignment, even in the face of a
442 * misaligned stack pointer from user-level before the signal.
443 * Don't use the SA32() macro because that rounds up, not down.
445 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
446 sp = fp - minstacksz;
449 * Make sure lwp hasn't trashed its stack
451 if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
452 fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
453 #ifdef DEBUG
454 printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
455 PTOU(p)->u_comm, p->p_pid, sig);
456 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
457 (void *)sp, (void *)hdlr, (uintptr_t)upc);
458 printf("sp above USERLIMIT\n");
459 #endif
460 return (0);
463 watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
465 if (on_fault(&ljb))
466 goto badstack;
468 if (sip != NULL) {
469 siginfo32_t si32;
470 zoneid_t zoneid;
472 siginfo_kto32(sip, &si32);
473 if (SI_FROMUSER(sip) &&
474 (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
475 zoneid != sip->si_zoneid) {
476 si32.si_pid = p->p_zone->zone_zsched->p_pid;
477 si32.si_uid = 0;
478 si32.si_ctid = -1;
479 si32.si_zoneid = zoneid;
481 fp -= SA32(sizeof (si32));
482 uzero(fp, sizeof (si32));
483 copyout_noerr(&si32, fp, sizeof (si32));
484 sip_addr = (siginfo32_t *)fp;
486 if (sig == SIGPROF &&
487 curthread->t_rprof != NULL &&
488 curthread->t_rprof->rp_anystate) {
490 * We stand on our head to deal with
491 * the real-time profiling signal.
492 * Fill in the stuff that doesn't fit
493 * in a normal k_siginfo structure.
495 int i = sip->si_nsysarg;
497 while (--i >= 0)
498 suword32_noerr(&(sip_addr->si_sysarg[i]),
499 (uint32_t)lwp->lwp_arg[i]);
500 copyout_noerr(curthread->t_rprof->rp_state,
501 sip_addr->si_mstate,
502 sizeof (curthread->t_rprof->rp_state));
504 } else
505 sip_addr = NULL;
507 /* save the current context on the user stack */
508 fp -= SA32(sizeof (*tuc));
509 uc = (ucontext32_t *)fp;
510 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
511 no_fault();
512 savecontext32(tuc, &lwp->lwp_sigoldmask);
513 if (on_fault(&ljb))
514 goto badstack;
515 copyout_noerr(tuc, uc, sizeof (*tuc));
516 kmem_free(tuc, sizeof (*tuc));
517 tuc = NULL;
519 lwp->lwp_oldcontext = (uintptr_t)uc;
521 if (newstack) {
522 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
523 if (lwp->lwp_ustack) {
524 stack32_t stk32;
526 stk32.ss_sp = (caddr32_t)(uintptr_t)
527 lwp->lwp_sigaltstack.ss_sp;
528 stk32.ss_size = (size32_t)
529 lwp->lwp_sigaltstack.ss_size;
530 stk32.ss_flags = (int32_t)
531 lwp->lwp_sigaltstack.ss_flags;
532 copyout_noerr(&stk32,
533 (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
538 * Set up signal handler arguments
541 struct sigframe32 frame32;
543 frame32.sip = (caddr32_t)(uintptr_t)sip_addr;
544 frame32.ucp = (caddr32_t)(uintptr_t)uc;
545 frame32.signo = sig;
546 frame32.retaddr = 0xffffffff; /* never return! */
547 copyout_noerr(&frame32, sp, sizeof (frame32));
550 no_fault();
551 if (watched)
552 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
554 rp->r_sp = (greg_t)(uintptr_t)sp;
555 rp->r_pc = (greg_t)(uintptr_t)hdlr;
556 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
558 if ((rp->r_cs & 0xffff) != U32CS_SEL ||
559 (rp->r_ss & 0xffff) != UDS_SEL) {
561 * Try our best to deliver the signal.
563 rp->r_cs = U32CS_SEL;
564 rp->r_ss = UDS_SEL;
568 * Don't set lwp_eosys here. sendsig() is called via psig() after
569 * lwp_eosys is handled, so setting it here would affect the next
570 * system call.
572 return (1);
574 badstack:
575 no_fault();
576 if (watched)
577 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
578 if (tuc)
579 kmem_free(tuc, sizeof (*tuc));
580 #ifdef DEBUG
581 printf("sendsig32: bad signal stack cmd=%s pid=%d, sig=%d\n",
582 PTOU(p)->u_comm, p->p_pid, sig);
583 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
584 (void *)sp, (void *)hdlr, (uintptr_t)upc);
585 #endif
586 return (0);
589 #endif /* _SYSCALL32_IMPL */
591 #elif defined(__i386)
594 * An i386 SVR4/ABI signal frame looks like this on the stack:
596 * old %esp:
597 * <a siginfo32_t [optional]>
598 * <a ucontext32_t>
599 * <pointer to that ucontext32_t>
600 * <pointer to that siginfo32_t>
601 * <signo>
602 * new %esp: <return address (deliberately invalid)>
604 struct sigframe {
605 void (*retaddr)();
606 uint_t signo;
607 siginfo_t *sip;
608 ucontext_t *ucp;
612 sendsig(int sig, k_siginfo_t *sip, void (*hdlr)())
614 volatile int minstacksz;
615 int newstack;
616 label_t ljb;
617 volatile caddr_t sp;
618 caddr_t fp;
619 struct regs *rp;
620 volatile greg_t upc;
621 volatile proc_t *p = ttoproc(curthread);
622 klwp_t *lwp = ttolwp(curthread);
623 ucontext_t *volatile tuc = NULL;
624 ucontext_t *uc;
625 siginfo_t *sip_addr;
626 volatile int watched;
628 rp = lwptoregs(lwp);
629 upc = rp->r_pc;
631 minstacksz = SA(sizeof (struct sigframe)) + SA(sizeof (*uc));
632 if (sip != NULL)
633 minstacksz += SA(sizeof (siginfo_t));
634 ASSERT((minstacksz & (STACK_ALIGN - 1ul)) == 0);
637 * Figure out whether we will be handling this signal on
638 * an alternate stack specified by the user. Then allocate
639 * and validate the stack requirements for the signal handler
640 * context. on_fault will catch any faults.
642 newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
643 !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
645 if (newstack) {
646 fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
647 SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
648 } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
649 user_desc_t *ldt;
651 * If the stack segment selector is -not- pointing at
652 * the UDS_SEL descriptor and we have an LDT entry for
653 * it instead, add the base address to find the effective va.
655 if ((ldt = p->p_ldt) != NULL)
656 fp = (caddr_t)rp->r_sp +
657 USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
658 else
659 fp = (caddr_t)rp->r_sp;
660 } else
661 fp = (caddr_t)rp->r_sp;
664 * Force proper stack pointer alignment, even in the face of a
665 * misaligned stack pointer from user-level before the signal.
666 * Don't use the SA() macro because that rounds up, not down.
668 fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN - 1ul));
669 sp = fp - minstacksz;
672 * Make sure lwp hasn't trashed its stack.
674 if (sp >= (caddr_t)USERLIMIT || fp >= (caddr_t)USERLIMIT) {
675 #ifdef DEBUG
676 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
677 PTOU(p)->u_comm, p->p_pid, sig);
678 printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
679 (void *)sp, (void *)hdlr, (uintptr_t)upc);
680 printf("sp above USERLIMIT\n");
681 #endif
682 return (0);
685 watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
687 if (on_fault(&ljb))
688 goto badstack;
690 if (sip != NULL) {
691 zoneid_t zoneid;
693 fp -= SA(sizeof (siginfo_t));
694 uzero(fp, sizeof (siginfo_t));
695 if (SI_FROMUSER(sip) &&
696 (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
697 zoneid != sip->si_zoneid) {
698 k_siginfo_t sani_sip = *sip;
700 sani_sip.si_pid = p->p_zone->zone_zsched->p_pid;
701 sani_sip.si_uid = 0;
702 sani_sip.si_ctid = -1;
703 sani_sip.si_zoneid = zoneid;
704 copyout_noerr(&sani_sip, fp, sizeof (sani_sip));
705 } else
706 copyout_noerr(sip, fp, sizeof (*sip));
707 sip_addr = (siginfo_t *)fp;
709 if (sig == SIGPROF &&
710 curthread->t_rprof != NULL &&
711 curthread->t_rprof->rp_anystate) {
713 * We stand on our head to deal with
714 * the real time profiling signal.
715 * Fill in the stuff that doesn't fit
716 * in a normal k_siginfo structure.
718 int i = sip->si_nsysarg;
720 while (--i >= 0)
721 suword32_noerr(&(sip_addr->si_sysarg[i]),
722 (uint32_t)lwp->lwp_arg[i]);
723 copyout_noerr(curthread->t_rprof->rp_state,
724 sip_addr->si_mstate,
725 sizeof (curthread->t_rprof->rp_state));
727 } else
728 sip_addr = NULL;
730 /* save the current context on the user stack */
731 fp -= SA(sizeof (*tuc));
732 uc = (ucontext_t *)fp;
733 tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
734 savecontext(tuc, &lwp->lwp_sigoldmask);
735 copyout_noerr(tuc, uc, sizeof (*tuc));
736 kmem_free(tuc, sizeof (*tuc));
737 tuc = NULL;
739 lwp->lwp_oldcontext = (uintptr_t)uc;
741 if (newstack) {
742 lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
743 if (lwp->lwp_ustack)
744 copyout_noerr(&lwp->lwp_sigaltstack,
745 (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
749 * Set up signal handler arguments
752 struct sigframe frame;
754 frame.sip = sip_addr;
755 frame.ucp = uc;
756 frame.signo = sig;
757 frame.retaddr = (void (*)())0xffffffff; /* never return! */
758 copyout_noerr(&frame, sp, sizeof (frame));
761 no_fault();
762 if (watched)
763 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
765 rp->r_sp = (greg_t)sp;
766 rp->r_pc = (greg_t)hdlr;
767 rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
769 if ((rp->r_cs & 0xffff) != UCS_SEL ||
770 (rp->r_ss & 0xffff) != UDS_SEL) {
771 rp->r_cs = UCS_SEL;
772 rp->r_ss = UDS_SEL;
776 * Don't set lwp_eosys here. sendsig() is called via psig() after
777 * lwp_eosys is handled, so setting it here would affect the next
778 * system call.
780 return (1);
782 badstack:
783 no_fault();
784 if (watched)
785 watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
786 if (tuc)
787 kmem_free(tuc, sizeof (*tuc));
788 #ifdef DEBUG
789 printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
790 PTOU(p)->u_comm, p->p_pid, sig);
791 printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
792 (void *)sp, (void *)hdlr, (uintptr_t)upc);
793 #endif
794 return (0);
797 #endif /* __i386 */