10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51629Sraf * Common Development and Distribution License (the "License").
61629Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211629Sraf
220Sstevel@tonic-gate /*
23*11913SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
280Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/param.h>
330Sstevel@tonic-gate #include <sys/sysmacros.h>
340Sstevel@tonic-gate #include <sys/signal.h>
350Sstevel@tonic-gate #include <sys/systm.h>
360Sstevel@tonic-gate #include <sys/user.h>
370Sstevel@tonic-gate #include <sys/mman.h>
380Sstevel@tonic-gate #include <sys/class.h>
390Sstevel@tonic-gate #include <sys/proc.h>
400Sstevel@tonic-gate #include <sys/procfs.h>
410Sstevel@tonic-gate #include <sys/buf.h>
420Sstevel@tonic-gate #include <sys/kmem.h>
430Sstevel@tonic-gate #include <sys/cred.h>
440Sstevel@tonic-gate #include <sys/archsystm.h>
450Sstevel@tonic-gate #include <sys/vmparam.h>
460Sstevel@tonic-gate #include <sys/prsystm.h>
470Sstevel@tonic-gate #include <sys/reboot.h>
480Sstevel@tonic-gate #include <sys/uadmin.h>
490Sstevel@tonic-gate #include <sys/vfs.h>
500Sstevel@tonic-gate #include <sys/vnode.h>
510Sstevel@tonic-gate #include <sys/file.h>
520Sstevel@tonic-gate #include <sys/session.h>
530Sstevel@tonic-gate #include <sys/ucontext.h>
540Sstevel@tonic-gate #include <sys/dnlc.h>
550Sstevel@tonic-gate #include <sys/var.h>
560Sstevel@tonic-gate #include <sys/cmn_err.h>
570Sstevel@tonic-gate #include <sys/debugreg.h>
580Sstevel@tonic-gate #include <sys/thread.h>
590Sstevel@tonic-gate #include <sys/vtrace.h>
600Sstevel@tonic-gate #include <sys/consdev.h>
610Sstevel@tonic-gate #include <sys/psw.h>
620Sstevel@tonic-gate #include <sys/regset.h>
630Sstevel@tonic-gate
640Sstevel@tonic-gate #include <sys/privregs.h>
650Sstevel@tonic-gate
660Sstevel@tonic-gate #include <sys/stack.h>
670Sstevel@tonic-gate #include <sys/swap.h>
680Sstevel@tonic-gate #include <vm/hat.h>
690Sstevel@tonic-gate #include <vm/anon.h>
700Sstevel@tonic-gate #include <vm/as.h>
710Sstevel@tonic-gate #include <vm/page.h>
720Sstevel@tonic-gate #include <vm/seg.h>
730Sstevel@tonic-gate #include <vm/seg_kmem.h>
740Sstevel@tonic-gate #include <vm/seg_map.h>
750Sstevel@tonic-gate #include <vm/seg_vn.h>
760Sstevel@tonic-gate #include <sys/exec.h>
770Sstevel@tonic-gate #include <sys/acct.h>
780Sstevel@tonic-gate #include <sys/core.h>
790Sstevel@tonic-gate #include <sys/corectl.h>
800Sstevel@tonic-gate #include <sys/modctl.h>
810Sstevel@tonic-gate #include <sys/tuneable.h>
820Sstevel@tonic-gate #include <c2/audit.h>
830Sstevel@tonic-gate #include <sys/bootconf.h>
840Sstevel@tonic-gate #include <sys/dumphdr.h>
850Sstevel@tonic-gate #include <sys/promif.h>
860Sstevel@tonic-gate #include <sys/systeminfo.h>
870Sstevel@tonic-gate #include <sys/kdi.h>
880Sstevel@tonic-gate #include <sys/contract_impl.h>
890Sstevel@tonic-gate #include <sys/x86_archext.h>
900Sstevel@tonic-gate
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate * Construct the execution environment for the user's signal
930Sstevel@tonic-gate * handler and arrange for control to be given to it on return
940Sstevel@tonic-gate * to userland. The library code now calls setcontext() to
950Sstevel@tonic-gate * clean up after the signal handler, so sigret() is no longer
960Sstevel@tonic-gate * needed.
970Sstevel@tonic-gate *
980Sstevel@tonic-gate * (The various 'volatile' declarations are need to ensure that values
990Sstevel@tonic-gate * are correct on the error return from on_fault().)
1000Sstevel@tonic-gate */
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate #if defined(__amd64)
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate /*
1050Sstevel@tonic-gate * An amd64 signal frame looks like this on the stack:
1060Sstevel@tonic-gate *
1070Sstevel@tonic-gate * old %rsp:
1080Sstevel@tonic-gate * <128 bytes of untouched stack space>
1090Sstevel@tonic-gate * <a siginfo_t [optional]>
1100Sstevel@tonic-gate * <a ucontext_t>
1110Sstevel@tonic-gate * <siginfo_t *>
1120Sstevel@tonic-gate * <signal number>
1130Sstevel@tonic-gate * new %rsp: <return address (deliberately invalid)>
1140Sstevel@tonic-gate *
1150Sstevel@tonic-gate * The signal number and siginfo_t pointer are only pushed onto the stack in
1160Sstevel@tonic-gate * order to allow stack backtraces. The actual signal handling code expects the
1170Sstevel@tonic-gate * arguments in registers.
1180Sstevel@tonic-gate */
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate struct sigframe {
1210Sstevel@tonic-gate caddr_t retaddr;
1220Sstevel@tonic-gate long signo;
1230Sstevel@tonic-gate siginfo_t *sip;
1240Sstevel@tonic-gate };
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate int
sendsig(int sig,k_siginfo_t * sip,void (* hdlr)())1270Sstevel@tonic-gate sendsig(int sig, k_siginfo_t *sip, void (*hdlr)())
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate volatile int minstacksz;
1300Sstevel@tonic-gate int newstack;
1310Sstevel@tonic-gate label_t ljb;
1320Sstevel@tonic-gate volatile caddr_t sp;
1330Sstevel@tonic-gate caddr_t fp;
1340Sstevel@tonic-gate volatile struct regs *rp;
1350Sstevel@tonic-gate volatile greg_t upc;
1360Sstevel@tonic-gate volatile proc_t *p = ttoproc(curthread);
1377838SRoger.Faulkner@Sun.COM struct as *as = p->p_as;
1380Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread);
1390Sstevel@tonic-gate ucontext_t *volatile tuc = NULL;
1400Sstevel@tonic-gate ucontext_t *uc;
1410Sstevel@tonic-gate siginfo_t *sip_addr;
1420Sstevel@tonic-gate volatile int watched;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate /*
1450Sstevel@tonic-gate * This routine is utterly dependent upon STACK_ALIGN being
1460Sstevel@tonic-gate * 16 and STACK_ENTRY_ALIGN being 8. Let's just acknowledge
1470Sstevel@tonic-gate * that and require it.
1480Sstevel@tonic-gate */
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate #if STACK_ALIGN != 16 || STACK_ENTRY_ALIGN != 8
1510Sstevel@tonic-gate #error "sendsig() amd64 did not find the expected stack alignments"
1520Sstevel@tonic-gate #endif
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate rp = lwptoregs(lwp);
1550Sstevel@tonic-gate upc = rp->r_pc;
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate /*
1580Sstevel@tonic-gate * Since we're setting up to run the signal handler we have to
1590Sstevel@tonic-gate * arrange that the stack at entry to the handler is (only)
1600Sstevel@tonic-gate * STACK_ENTRY_ALIGN (i.e. 8) byte aligned so that when the handler
1610Sstevel@tonic-gate * executes its push of %rbp, the stack realigns to STACK_ALIGN
1620Sstevel@tonic-gate * (i.e. 16) correctly.
1630Sstevel@tonic-gate *
1640Sstevel@tonic-gate * The new sp will point to the sigframe and the ucontext_t. The
1650Sstevel@tonic-gate * above means that sp (and thus sigframe) will be 8-byte aligned,
1660Sstevel@tonic-gate * but not 16-byte aligned. ucontext_t, however, contains %xmm regs
1670Sstevel@tonic-gate * which must be 16-byte aligned. Because of this, for correct
1680Sstevel@tonic-gate * alignment, sigframe must be a multiple of 8-bytes in length, but
1690Sstevel@tonic-gate * not 16-bytes. This will place ucontext_t at a nice 16-byte boundary.
1700Sstevel@tonic-gate */
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate /* LINTED: logical expression always true: op "||" */
1730Sstevel@tonic-gate ASSERT((sizeof (struct sigframe) % 16) == 8);
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate minstacksz = sizeof (struct sigframe) + SA(sizeof (*uc));
1760Sstevel@tonic-gate if (sip != NULL)
1770Sstevel@tonic-gate minstacksz += SA(sizeof (siginfo_t));
1780Sstevel@tonic-gate ASSERT((minstacksz & (STACK_ENTRY_ALIGN - 1ul)) == 0);
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate /*
1810Sstevel@tonic-gate * Figure out whether we will be handling this signal on
1820Sstevel@tonic-gate * an alternate stack specified by the user. Then allocate
1830Sstevel@tonic-gate * and validate the stack requirements for the signal handler
1840Sstevel@tonic-gate * context. on_fault will catch any faults.
1850Sstevel@tonic-gate */
1863446Smrj newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
1870Sstevel@tonic-gate !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate if (newstack) {
1900Sstevel@tonic-gate fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
1910Sstevel@tonic-gate SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
1920Sstevel@tonic-gate } else {
1930Sstevel@tonic-gate /*
1940Sstevel@tonic-gate * Drop below the 128-byte reserved region of the stack frame
1950Sstevel@tonic-gate * we're interrupting.
1960Sstevel@tonic-gate */
1970Sstevel@tonic-gate fp = (caddr_t)rp->r_sp - STACK_RESERVE;
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate /*
2011629Sraf * Force proper stack pointer alignment, even in the face of a
2021629Sraf * misaligned stack pointer from user-level before the signal.
2031629Sraf */
2041629Sraf fp = (caddr_t)((uintptr_t)fp & ~(STACK_ENTRY_ALIGN - 1ul));
2051629Sraf
2061629Sraf /*
2070Sstevel@tonic-gate * Most of the time during normal execution, the stack pointer
2080Sstevel@tonic-gate * is aligned on a STACK_ALIGN (i.e. 16 byte) boundary. However,
2090Sstevel@tonic-gate * (for example) just after a call instruction (which pushes
2100Sstevel@tonic-gate * the return address), the callers stack misaligns until the
2110Sstevel@tonic-gate * 'push %rbp' happens in the callee prolog. So while we should
2120Sstevel@tonic-gate * expect the stack pointer to be always at least STACK_ENTRY_ALIGN
2130Sstevel@tonic-gate * aligned, we should -not- expect it to always be STACK_ALIGN aligned.
2140Sstevel@tonic-gate * We now adjust to ensure that the new sp is aligned to
2150Sstevel@tonic-gate * STACK_ENTRY_ALIGN but not to STACK_ALIGN.
2160Sstevel@tonic-gate */
2170Sstevel@tonic-gate sp = fp - minstacksz;
2180Sstevel@tonic-gate if (((uintptr_t)sp & (STACK_ALIGN - 1ul)) == 0) {
2190Sstevel@tonic-gate sp -= STACK_ENTRY_ALIGN;
2200Sstevel@tonic-gate minstacksz = fp - sp;
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate * Now, make sure the resulting signal frame address is sane
2250Sstevel@tonic-gate */
2267838SRoger.Faulkner@Sun.COM if (sp >= as->a_userlimit || fp >= as->a_userlimit) {
2270Sstevel@tonic-gate #ifdef DEBUG
2280Sstevel@tonic-gate printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
2290Sstevel@tonic-gate PTOU(p)->u_comm, p->p_pid, sig);
2300Sstevel@tonic-gate printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
2310Sstevel@tonic-gate (void *)sp, (void *)hdlr, (uintptr_t)upc);
2321629Sraf printf("sp above USERLIMIT\n");
2330Sstevel@tonic-gate #endif
2340Sstevel@tonic-gate return (0);
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate if (on_fault(&ljb))
2400Sstevel@tonic-gate goto badstack;
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate if (sip != NULL) {
2430Sstevel@tonic-gate zoneid_t zoneid;
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate fp -= SA(sizeof (siginfo_t));
2460Sstevel@tonic-gate uzero(fp, sizeof (siginfo_t));
2470Sstevel@tonic-gate if (SI_FROMUSER(sip) &&
2480Sstevel@tonic-gate (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
2490Sstevel@tonic-gate zoneid != sip->si_zoneid) {
2500Sstevel@tonic-gate k_siginfo_t sani_sip = *sip;
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate sani_sip.si_pid = p->p_zone->zone_zsched->p_pid;
2530Sstevel@tonic-gate sani_sip.si_uid = 0;
2540Sstevel@tonic-gate sani_sip.si_ctid = -1;
2550Sstevel@tonic-gate sani_sip.si_zoneid = zoneid;
2560Sstevel@tonic-gate copyout_noerr(&sani_sip, fp, sizeof (sani_sip));
2570Sstevel@tonic-gate } else
2580Sstevel@tonic-gate copyout_noerr(sip, fp, sizeof (*sip));
2590Sstevel@tonic-gate sip_addr = (siginfo_t *)fp;
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate if (sig == SIGPROF &&
2620Sstevel@tonic-gate curthread->t_rprof != NULL &&
2630Sstevel@tonic-gate curthread->t_rprof->rp_anystate) {
2640Sstevel@tonic-gate /*
2650Sstevel@tonic-gate * We stand on our head to deal with
2660Sstevel@tonic-gate * the real time profiling signal.
2670Sstevel@tonic-gate * Fill in the stuff that doesn't fit
2680Sstevel@tonic-gate * in a normal k_siginfo structure.
2690Sstevel@tonic-gate */
2700Sstevel@tonic-gate int i = sip->si_nsysarg;
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate while (--i >= 0)
2730Sstevel@tonic-gate sulword_noerr(
2740Sstevel@tonic-gate (ulong_t *)&(sip_addr->si_sysarg[i]),
2750Sstevel@tonic-gate (ulong_t)lwp->lwp_arg[i]);
2760Sstevel@tonic-gate copyout_noerr(curthread->t_rprof->rp_state,
2770Sstevel@tonic-gate sip_addr->si_mstate,
2780Sstevel@tonic-gate sizeof (curthread->t_rprof->rp_state));
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate } else
2810Sstevel@tonic-gate sip_addr = NULL;
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate /*
2840Sstevel@tonic-gate * save the current context on the user stack directly after the
2850Sstevel@tonic-gate * sigframe. Since sigframe is 8-byte-but-not-16-byte aligned,
2860Sstevel@tonic-gate * and since sizeof (struct sigframe) is 24, this guarantees
2870Sstevel@tonic-gate * 16-byte alignment for ucontext_t and its %xmm registers.
2880Sstevel@tonic-gate */
2890Sstevel@tonic-gate uc = (ucontext_t *)(sp + sizeof (struct sigframe));
2900Sstevel@tonic-gate tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
291*11913SRoger.Faulkner@Sun.COM savecontext(tuc, &lwp->lwp_sigoldmask);
2920Sstevel@tonic-gate copyout_noerr(tuc, uc, sizeof (*tuc));
2930Sstevel@tonic-gate kmem_free(tuc, sizeof (*tuc));
2940Sstevel@tonic-gate tuc = NULL;
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate lwp->lwp_oldcontext = (uintptr_t)uc;
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate if (newstack) {
2990Sstevel@tonic-gate lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
3000Sstevel@tonic-gate if (lwp->lwp_ustack)
3010Sstevel@tonic-gate copyout_noerr(&lwp->lwp_sigaltstack,
3020Sstevel@tonic-gate (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate * Set up signal handler return and stack linkage
3070Sstevel@tonic-gate */
3080Sstevel@tonic-gate {
3090Sstevel@tonic-gate struct sigframe frame;
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate /*
3120Sstevel@tonic-gate * ensure we never return "normally"
3130Sstevel@tonic-gate */
3140Sstevel@tonic-gate frame.retaddr = (caddr_t)(uintptr_t)-1L;
3150Sstevel@tonic-gate frame.signo = sig;
3160Sstevel@tonic-gate frame.sip = sip_addr;
3170Sstevel@tonic-gate copyout_noerr(&frame, sp, sizeof (frame));
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate no_fault();
3210Sstevel@tonic-gate if (watched)
3220Sstevel@tonic-gate watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate /*
3250Sstevel@tonic-gate * Set up user registers for execution of signal handler.
3260Sstevel@tonic-gate */
3270Sstevel@tonic-gate rp->r_sp = (greg_t)sp;
3280Sstevel@tonic-gate rp->r_pc = (greg_t)hdlr;
3290Sstevel@tonic-gate rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate rp->r_rdi = sig;
3320Sstevel@tonic-gate rp->r_rsi = (uintptr_t)sip_addr;
3330Sstevel@tonic-gate rp->r_rdx = (uintptr_t)uc;
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate if ((rp->r_cs & 0xffff) != UCS_SEL ||
3360Sstevel@tonic-gate (rp->r_ss & 0xffff) != UDS_SEL) {
3370Sstevel@tonic-gate /*
3380Sstevel@tonic-gate * Try our best to deliver the signal.
3390Sstevel@tonic-gate */
3400Sstevel@tonic-gate rp->r_cs = UCS_SEL;
3410Sstevel@tonic-gate rp->r_ss = UDS_SEL;
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate /*
3450Sstevel@tonic-gate * Don't set lwp_eosys here. sendsig() is called via psig() after
3460Sstevel@tonic-gate * lwp_eosys is handled, so setting it here would affect the next
3470Sstevel@tonic-gate * system call.
3480Sstevel@tonic-gate */
3490Sstevel@tonic-gate return (1);
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate badstack:
3520Sstevel@tonic-gate no_fault();
3530Sstevel@tonic-gate if (watched)
3540Sstevel@tonic-gate watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
3550Sstevel@tonic-gate if (tuc)
3560Sstevel@tonic-gate kmem_free(tuc, sizeof (*tuc));
3570Sstevel@tonic-gate #ifdef DEBUG
3580Sstevel@tonic-gate printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
3590Sstevel@tonic-gate PTOU(p)->u_comm, p->p_pid, sig);
3600Sstevel@tonic-gate printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
3610Sstevel@tonic-gate (void *)sp, (void *)hdlr, (uintptr_t)upc);
3620Sstevel@tonic-gate #endif
3630Sstevel@tonic-gate return (0);
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate /*
3690Sstevel@tonic-gate * An i386 SVR4/ABI signal frame looks like this on the stack:
3700Sstevel@tonic-gate *
3710Sstevel@tonic-gate * old %esp:
3720Sstevel@tonic-gate * <a siginfo32_t [optional]>
3730Sstevel@tonic-gate * <a ucontext32_t>
3740Sstevel@tonic-gate * <pointer to that ucontext32_t>
3750Sstevel@tonic-gate * <pointer to that siginfo32_t>
3760Sstevel@tonic-gate * <signo>
3770Sstevel@tonic-gate * new %esp: <return address (deliberately invalid)>
3780Sstevel@tonic-gate */
3790Sstevel@tonic-gate struct sigframe32 {
3800Sstevel@tonic-gate caddr32_t retaddr;
3810Sstevel@tonic-gate uint32_t signo;
3820Sstevel@tonic-gate caddr32_t sip;
3830Sstevel@tonic-gate caddr32_t ucp;
3840Sstevel@tonic-gate };
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate int
sendsig32(int sig,k_siginfo_t * sip,void (* hdlr)())3870Sstevel@tonic-gate sendsig32(int sig, k_siginfo_t *sip, void (*hdlr)())
3880Sstevel@tonic-gate {
3890Sstevel@tonic-gate volatile int minstacksz;
3900Sstevel@tonic-gate int newstack;
3910Sstevel@tonic-gate label_t ljb;
3920Sstevel@tonic-gate volatile caddr_t sp;
3930Sstevel@tonic-gate caddr_t fp;
3940Sstevel@tonic-gate volatile struct regs *rp;
3950Sstevel@tonic-gate volatile greg_t upc;
3960Sstevel@tonic-gate volatile proc_t *p = ttoproc(curthread);
3970Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread);
3980Sstevel@tonic-gate ucontext32_t *volatile tuc = NULL;
3990Sstevel@tonic-gate ucontext32_t *uc;
4000Sstevel@tonic-gate siginfo32_t *sip_addr;
4010Sstevel@tonic-gate volatile int watched;
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate rp = lwptoregs(lwp);
4040Sstevel@tonic-gate upc = rp->r_pc;
4050Sstevel@tonic-gate
4060Sstevel@tonic-gate minstacksz = SA32(sizeof (struct sigframe32)) + SA32(sizeof (*uc));
4070Sstevel@tonic-gate if (sip != NULL)
4080Sstevel@tonic-gate minstacksz += SA32(sizeof (siginfo32_t));
4090Sstevel@tonic-gate ASSERT((minstacksz & (STACK_ALIGN32 - 1)) == 0);
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate * Figure out whether we will be handling this signal on
4130Sstevel@tonic-gate * an alternate stack specified by the user. Then allocate
4140Sstevel@tonic-gate * and validate the stack requirements for the signal handler
4150Sstevel@tonic-gate * context. on_fault will catch any faults.
4160Sstevel@tonic-gate */
4173446Smrj newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
4180Sstevel@tonic-gate !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate if (newstack) {
4210Sstevel@tonic-gate fp = (caddr_t)(SA32((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
4220Sstevel@tonic-gate SA32(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN32);
4230Sstevel@tonic-gate } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
4240Sstevel@tonic-gate user_desc_t *ldt;
4250Sstevel@tonic-gate /*
4260Sstevel@tonic-gate * If the stack segment selector is -not- pointing at
4270Sstevel@tonic-gate * the UDS_SEL descriptor and we have an LDT entry for
4280Sstevel@tonic-gate * it instead, add the base address to find the effective va.
4290Sstevel@tonic-gate */
4300Sstevel@tonic-gate if ((ldt = p->p_ldt) != NULL)
4310Sstevel@tonic-gate fp = (caddr_t)rp->r_sp +
4320Sstevel@tonic-gate USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
4330Sstevel@tonic-gate else
4340Sstevel@tonic-gate fp = (caddr_t)rp->r_sp;
4350Sstevel@tonic-gate } else
4360Sstevel@tonic-gate fp = (caddr_t)rp->r_sp;
4371629Sraf
4381629Sraf /*
4391629Sraf * Force proper stack pointer alignment, even in the face of a
4401629Sraf * misaligned stack pointer from user-level before the signal.
4411629Sraf * Don't use the SA32() macro because that rounds up, not down.
4421629Sraf */
4431629Sraf fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN32 - 1));
4440Sstevel@tonic-gate sp = fp - minstacksz;
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate /*
4470Sstevel@tonic-gate * Make sure lwp hasn't trashed its stack
4480Sstevel@tonic-gate */
4491629Sraf if (sp >= (caddr_t)(uintptr_t)USERLIMIT32 ||
4500Sstevel@tonic-gate fp >= (caddr_t)(uintptr_t)USERLIMIT32) {
4510Sstevel@tonic-gate #ifdef DEBUG
4520Sstevel@tonic-gate printf("sendsig32: bad signal stack cmd=%s, pid=%d, sig=%d\n",
4530Sstevel@tonic-gate PTOU(p)->u_comm, p->p_pid, sig);
4540Sstevel@tonic-gate printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
4550Sstevel@tonic-gate (void *)sp, (void *)hdlr, (uintptr_t)upc);
4561629Sraf printf("sp above USERLIMIT\n");
4570Sstevel@tonic-gate #endif
4580Sstevel@tonic-gate return (0);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
4620Sstevel@tonic-gate
4630Sstevel@tonic-gate if (on_fault(&ljb))
4640Sstevel@tonic-gate goto badstack;
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate if (sip != NULL) {
4670Sstevel@tonic-gate siginfo32_t si32;
4680Sstevel@tonic-gate zoneid_t zoneid;
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate siginfo_kto32(sip, &si32);
4710Sstevel@tonic-gate if (SI_FROMUSER(sip) &&
4720Sstevel@tonic-gate (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
4730Sstevel@tonic-gate zoneid != sip->si_zoneid) {
4740Sstevel@tonic-gate si32.si_pid = p->p_zone->zone_zsched->p_pid;
4750Sstevel@tonic-gate si32.si_uid = 0;
4760Sstevel@tonic-gate si32.si_ctid = -1;
4770Sstevel@tonic-gate si32.si_zoneid = zoneid;
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate fp -= SA32(sizeof (si32));
4800Sstevel@tonic-gate uzero(fp, sizeof (si32));
4810Sstevel@tonic-gate copyout_noerr(&si32, fp, sizeof (si32));
4820Sstevel@tonic-gate sip_addr = (siginfo32_t *)fp;
4830Sstevel@tonic-gate
4840Sstevel@tonic-gate if (sig == SIGPROF &&
4850Sstevel@tonic-gate curthread->t_rprof != NULL &&
4860Sstevel@tonic-gate curthread->t_rprof->rp_anystate) {
4870Sstevel@tonic-gate /*
4880Sstevel@tonic-gate * We stand on our head to deal with
4890Sstevel@tonic-gate * the real-time profiling signal.
4900Sstevel@tonic-gate * Fill in the stuff that doesn't fit
4910Sstevel@tonic-gate * in a normal k_siginfo structure.
4920Sstevel@tonic-gate */
4930Sstevel@tonic-gate int i = sip->si_nsysarg;
4940Sstevel@tonic-gate
4950Sstevel@tonic-gate while (--i >= 0)
4960Sstevel@tonic-gate suword32_noerr(&(sip_addr->si_sysarg[i]),
4970Sstevel@tonic-gate (uint32_t)lwp->lwp_arg[i]);
4980Sstevel@tonic-gate copyout_noerr(curthread->t_rprof->rp_state,
4990Sstevel@tonic-gate sip_addr->si_mstate,
5000Sstevel@tonic-gate sizeof (curthread->t_rprof->rp_state));
5010Sstevel@tonic-gate }
5020Sstevel@tonic-gate } else
5030Sstevel@tonic-gate sip_addr = NULL;
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate /* save the current context on the user stack */
5060Sstevel@tonic-gate fp -= SA32(sizeof (*tuc));
5070Sstevel@tonic-gate uc = (ucontext32_t *)fp;
5080Sstevel@tonic-gate tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
509*11913SRoger.Faulkner@Sun.COM savecontext32(tuc, &lwp->lwp_sigoldmask);
5100Sstevel@tonic-gate copyout_noerr(tuc, uc, sizeof (*tuc));
5110Sstevel@tonic-gate kmem_free(tuc, sizeof (*tuc));
5120Sstevel@tonic-gate tuc = NULL;
5130Sstevel@tonic-gate
5140Sstevel@tonic-gate lwp->lwp_oldcontext = (uintptr_t)uc;
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate if (newstack) {
5170Sstevel@tonic-gate lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
5180Sstevel@tonic-gate if (lwp->lwp_ustack) {
5190Sstevel@tonic-gate stack32_t stk32;
5200Sstevel@tonic-gate
5210Sstevel@tonic-gate stk32.ss_sp = (caddr32_t)(uintptr_t)
5220Sstevel@tonic-gate lwp->lwp_sigaltstack.ss_sp;
5230Sstevel@tonic-gate stk32.ss_size = (size32_t)
5240Sstevel@tonic-gate lwp->lwp_sigaltstack.ss_size;
5250Sstevel@tonic-gate stk32.ss_flags = (int32_t)
5260Sstevel@tonic-gate lwp->lwp_sigaltstack.ss_flags;
5270Sstevel@tonic-gate copyout_noerr(&stk32,
5280Sstevel@tonic-gate (stack32_t *)lwp->lwp_ustack, sizeof (stk32));
5290Sstevel@tonic-gate }
5300Sstevel@tonic-gate }
5310Sstevel@tonic-gate
5320Sstevel@tonic-gate /*
5330Sstevel@tonic-gate * Set up signal handler arguments
5340Sstevel@tonic-gate */
5350Sstevel@tonic-gate {
5360Sstevel@tonic-gate struct sigframe32 frame32;
5370Sstevel@tonic-gate
5380Sstevel@tonic-gate frame32.sip = (caddr32_t)(uintptr_t)sip_addr;
5390Sstevel@tonic-gate frame32.ucp = (caddr32_t)(uintptr_t)uc;
5400Sstevel@tonic-gate frame32.signo = sig;
5410Sstevel@tonic-gate frame32.retaddr = 0xffffffff; /* never return! */
5420Sstevel@tonic-gate copyout_noerr(&frame32, sp, sizeof (frame32));
5430Sstevel@tonic-gate }
5440Sstevel@tonic-gate
5450Sstevel@tonic-gate no_fault();
5460Sstevel@tonic-gate if (watched)
5470Sstevel@tonic-gate watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
5480Sstevel@tonic-gate
5490Sstevel@tonic-gate rp->r_sp = (greg_t)(uintptr_t)sp;
5500Sstevel@tonic-gate rp->r_pc = (greg_t)(uintptr_t)hdlr;
5510Sstevel@tonic-gate rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
5520Sstevel@tonic-gate
5530Sstevel@tonic-gate if ((rp->r_cs & 0xffff) != U32CS_SEL ||
5540Sstevel@tonic-gate (rp->r_ss & 0xffff) != UDS_SEL) {
5550Sstevel@tonic-gate /*
5560Sstevel@tonic-gate * Try our best to deliver the signal.
5570Sstevel@tonic-gate */
5580Sstevel@tonic-gate rp->r_cs = U32CS_SEL;
5590Sstevel@tonic-gate rp->r_ss = UDS_SEL;
5600Sstevel@tonic-gate }
5610Sstevel@tonic-gate
5620Sstevel@tonic-gate /*
5630Sstevel@tonic-gate * Don't set lwp_eosys here. sendsig() is called via psig() after
5640Sstevel@tonic-gate * lwp_eosys is handled, so setting it here would affect the next
5650Sstevel@tonic-gate * system call.
5660Sstevel@tonic-gate */
5670Sstevel@tonic-gate return (1);
5680Sstevel@tonic-gate
5690Sstevel@tonic-gate badstack:
5700Sstevel@tonic-gate no_fault();
5710Sstevel@tonic-gate if (watched)
5720Sstevel@tonic-gate watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
5730Sstevel@tonic-gate if (tuc)
5740Sstevel@tonic-gate kmem_free(tuc, sizeof (*tuc));
5750Sstevel@tonic-gate #ifdef DEBUG
5760Sstevel@tonic-gate printf("sendsig32: bad signal stack cmd=%s pid=%d, sig=%d\n",
5770Sstevel@tonic-gate PTOU(p)->u_comm, p->p_pid, sig);
5780Sstevel@tonic-gate printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
5790Sstevel@tonic-gate (void *)sp, (void *)hdlr, (uintptr_t)upc);
5800Sstevel@tonic-gate #endif
5810Sstevel@tonic-gate return (0);
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate
5840Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate #elif defined(__i386)
5870Sstevel@tonic-gate
5880Sstevel@tonic-gate /*
5890Sstevel@tonic-gate * An i386 SVR4/ABI signal frame looks like this on the stack:
5900Sstevel@tonic-gate *
5910Sstevel@tonic-gate * old %esp:
5920Sstevel@tonic-gate * <a siginfo32_t [optional]>
5930Sstevel@tonic-gate * <a ucontext32_t>
5940Sstevel@tonic-gate * <pointer to that ucontext32_t>
5950Sstevel@tonic-gate * <pointer to that siginfo32_t>
5960Sstevel@tonic-gate * <signo>
5970Sstevel@tonic-gate * new %esp: <return address (deliberately invalid)>
5980Sstevel@tonic-gate */
5990Sstevel@tonic-gate struct sigframe {
6000Sstevel@tonic-gate void (*retaddr)();
6010Sstevel@tonic-gate uint_t signo;
6020Sstevel@tonic-gate siginfo_t *sip;
6030Sstevel@tonic-gate ucontext_t *ucp;
6040Sstevel@tonic-gate };
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate int
sendsig(int sig,k_siginfo_t * sip,void (* hdlr)())6070Sstevel@tonic-gate sendsig(int sig, k_siginfo_t *sip, void (*hdlr)())
6080Sstevel@tonic-gate {
6090Sstevel@tonic-gate volatile int minstacksz;
6100Sstevel@tonic-gate int newstack;
6110Sstevel@tonic-gate label_t ljb;
6120Sstevel@tonic-gate volatile caddr_t sp;
6130Sstevel@tonic-gate caddr_t fp;
6140Sstevel@tonic-gate struct regs *rp;
6150Sstevel@tonic-gate volatile greg_t upc;
6160Sstevel@tonic-gate volatile proc_t *p = ttoproc(curthread);
6170Sstevel@tonic-gate klwp_t *lwp = ttolwp(curthread);
6180Sstevel@tonic-gate ucontext_t *volatile tuc = NULL;
6190Sstevel@tonic-gate ucontext_t *uc;
6200Sstevel@tonic-gate siginfo_t *sip_addr;
6210Sstevel@tonic-gate volatile int watched;
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate rp = lwptoregs(lwp);
6240Sstevel@tonic-gate upc = rp->r_pc;
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate minstacksz = SA(sizeof (struct sigframe)) + SA(sizeof (*uc));
6270Sstevel@tonic-gate if (sip != NULL)
6280Sstevel@tonic-gate minstacksz += SA(sizeof (siginfo_t));
6290Sstevel@tonic-gate ASSERT((minstacksz & (STACK_ALIGN - 1ul)) == 0);
6300Sstevel@tonic-gate
6310Sstevel@tonic-gate /*
6320Sstevel@tonic-gate * Figure out whether we will be handling this signal on
6330Sstevel@tonic-gate * an alternate stack specified by the user. Then allocate
6340Sstevel@tonic-gate * and validate the stack requirements for the signal handler
6350Sstevel@tonic-gate * context. on_fault will catch any faults.
6360Sstevel@tonic-gate */
6373446Smrj newstack = sigismember(&PTOU(curproc)->u_sigonstack, sig) &&
6380Sstevel@tonic-gate !(lwp->lwp_sigaltstack.ss_flags & (SS_ONSTACK|SS_DISABLE));
6390Sstevel@tonic-gate
6400Sstevel@tonic-gate if (newstack) {
6410Sstevel@tonic-gate fp = (caddr_t)(SA((uintptr_t)lwp->lwp_sigaltstack.ss_sp) +
6420Sstevel@tonic-gate SA(lwp->lwp_sigaltstack.ss_size) - STACK_ALIGN);
6430Sstevel@tonic-gate } else if ((rp->r_ss & 0xffff) != UDS_SEL) {
6440Sstevel@tonic-gate user_desc_t *ldt;
6450Sstevel@tonic-gate /*
6460Sstevel@tonic-gate * If the stack segment selector is -not- pointing at
6470Sstevel@tonic-gate * the UDS_SEL descriptor and we have an LDT entry for
6480Sstevel@tonic-gate * it instead, add the base address to find the effective va.
6490Sstevel@tonic-gate */
6500Sstevel@tonic-gate if ((ldt = p->p_ldt) != NULL)
6510Sstevel@tonic-gate fp = (caddr_t)rp->r_sp +
6520Sstevel@tonic-gate USEGD_GETBASE(&ldt[SELTOIDX(rp->r_ss)]);
6530Sstevel@tonic-gate else
6540Sstevel@tonic-gate fp = (caddr_t)rp->r_sp;
6550Sstevel@tonic-gate } else
6560Sstevel@tonic-gate fp = (caddr_t)rp->r_sp;
6571629Sraf
6581629Sraf /*
6591629Sraf * Force proper stack pointer alignment, even in the face of a
6601629Sraf * misaligned stack pointer from user-level before the signal.
6611629Sraf * Don't use the SA() macro because that rounds up, not down.
6621629Sraf */
6631629Sraf fp = (caddr_t)((uintptr_t)fp & ~(STACK_ALIGN - 1ul));
6640Sstevel@tonic-gate sp = fp - minstacksz;
6650Sstevel@tonic-gate
6660Sstevel@tonic-gate /*
6670Sstevel@tonic-gate * Make sure lwp hasn't trashed its stack.
6680Sstevel@tonic-gate */
6691629Sraf if (sp >= (caddr_t)USERLIMIT || fp >= (caddr_t)USERLIMIT) {
6700Sstevel@tonic-gate #ifdef DEBUG
6710Sstevel@tonic-gate printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
6720Sstevel@tonic-gate PTOU(p)->u_comm, p->p_pid, sig);
6730Sstevel@tonic-gate printf("sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
6740Sstevel@tonic-gate (void *)sp, (void *)hdlr, (uintptr_t)upc);
6751629Sraf printf("sp above USERLIMIT\n");
6760Sstevel@tonic-gate #endif
6770Sstevel@tonic-gate return (0);
6780Sstevel@tonic-gate }
6790Sstevel@tonic-gate
6800Sstevel@tonic-gate watched = watch_disable_addr((caddr_t)sp, minstacksz, S_WRITE);
6810Sstevel@tonic-gate
6820Sstevel@tonic-gate if (on_fault(&ljb))
6830Sstevel@tonic-gate goto badstack;
6840Sstevel@tonic-gate
6850Sstevel@tonic-gate if (sip != NULL) {
6860Sstevel@tonic-gate zoneid_t zoneid;
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate fp -= SA(sizeof (siginfo_t));
6890Sstevel@tonic-gate uzero(fp, sizeof (siginfo_t));
6900Sstevel@tonic-gate if (SI_FROMUSER(sip) &&
6910Sstevel@tonic-gate (zoneid = p->p_zone->zone_id) != GLOBAL_ZONEID &&
6920Sstevel@tonic-gate zoneid != sip->si_zoneid) {
6930Sstevel@tonic-gate k_siginfo_t sani_sip = *sip;
6940Sstevel@tonic-gate
6950Sstevel@tonic-gate sani_sip.si_pid = p->p_zone->zone_zsched->p_pid;
6960Sstevel@tonic-gate sani_sip.si_uid = 0;
6970Sstevel@tonic-gate sani_sip.si_ctid = -1;
6980Sstevel@tonic-gate sani_sip.si_zoneid = zoneid;
6990Sstevel@tonic-gate copyout_noerr(&sani_sip, fp, sizeof (sani_sip));
7000Sstevel@tonic-gate } else
7010Sstevel@tonic-gate copyout_noerr(sip, fp, sizeof (*sip));
7020Sstevel@tonic-gate sip_addr = (siginfo_t *)fp;
7030Sstevel@tonic-gate
7040Sstevel@tonic-gate if (sig == SIGPROF &&
7050Sstevel@tonic-gate curthread->t_rprof != NULL &&
7060Sstevel@tonic-gate curthread->t_rprof->rp_anystate) {
7070Sstevel@tonic-gate /*
7080Sstevel@tonic-gate * We stand on our head to deal with
7090Sstevel@tonic-gate * the real time profiling signal.
7100Sstevel@tonic-gate * Fill in the stuff that doesn't fit
7110Sstevel@tonic-gate * in a normal k_siginfo structure.
7120Sstevel@tonic-gate */
7130Sstevel@tonic-gate int i = sip->si_nsysarg;
7140Sstevel@tonic-gate
7150Sstevel@tonic-gate while (--i >= 0)
7160Sstevel@tonic-gate suword32_noerr(&(sip_addr->si_sysarg[i]),
7170Sstevel@tonic-gate (uint32_t)lwp->lwp_arg[i]);
7180Sstevel@tonic-gate copyout_noerr(curthread->t_rprof->rp_state,
7190Sstevel@tonic-gate sip_addr->si_mstate,
7200Sstevel@tonic-gate sizeof (curthread->t_rprof->rp_state));
7210Sstevel@tonic-gate }
7220Sstevel@tonic-gate } else
7230Sstevel@tonic-gate sip_addr = NULL;
7240Sstevel@tonic-gate
7250Sstevel@tonic-gate /* save the current context on the user stack */
7260Sstevel@tonic-gate fp -= SA(sizeof (*tuc));
7270Sstevel@tonic-gate uc = (ucontext_t *)fp;
7280Sstevel@tonic-gate tuc = kmem_alloc(sizeof (*tuc), KM_SLEEP);
729*11913SRoger.Faulkner@Sun.COM savecontext(tuc, &lwp->lwp_sigoldmask);
7300Sstevel@tonic-gate copyout_noerr(tuc, uc, sizeof (*tuc));
7310Sstevel@tonic-gate kmem_free(tuc, sizeof (*tuc));
7320Sstevel@tonic-gate tuc = NULL;
7330Sstevel@tonic-gate
7340Sstevel@tonic-gate lwp->lwp_oldcontext = (uintptr_t)uc;
7350Sstevel@tonic-gate
7360Sstevel@tonic-gate if (newstack) {
7370Sstevel@tonic-gate lwp->lwp_sigaltstack.ss_flags |= SS_ONSTACK;
7380Sstevel@tonic-gate if (lwp->lwp_ustack)
7390Sstevel@tonic-gate copyout_noerr(&lwp->lwp_sigaltstack,
7400Sstevel@tonic-gate (stack_t *)lwp->lwp_ustack, sizeof (stack_t));
7410Sstevel@tonic-gate }
7420Sstevel@tonic-gate
7430Sstevel@tonic-gate /*
7440Sstevel@tonic-gate * Set up signal handler arguments
7450Sstevel@tonic-gate */
7460Sstevel@tonic-gate {
7470Sstevel@tonic-gate struct sigframe frame;
7480Sstevel@tonic-gate
7490Sstevel@tonic-gate frame.sip = sip_addr;
7500Sstevel@tonic-gate frame.ucp = uc;
7510Sstevel@tonic-gate frame.signo = sig;
7520Sstevel@tonic-gate frame.retaddr = (void (*)())0xffffffff; /* never return! */
7530Sstevel@tonic-gate copyout_noerr(&frame, sp, sizeof (frame));
7540Sstevel@tonic-gate }
7550Sstevel@tonic-gate
7560Sstevel@tonic-gate no_fault();
7570Sstevel@tonic-gate if (watched)
7580Sstevel@tonic-gate watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
7590Sstevel@tonic-gate
7600Sstevel@tonic-gate rp->r_sp = (greg_t)sp;
7610Sstevel@tonic-gate rp->r_pc = (greg_t)hdlr;
7620Sstevel@tonic-gate rp->r_ps = PSL_USER | (rp->r_ps & PS_IOPL);
7630Sstevel@tonic-gate
7640Sstevel@tonic-gate if ((rp->r_cs & 0xffff) != UCS_SEL ||
7650Sstevel@tonic-gate (rp->r_ss & 0xffff) != UDS_SEL) {
7660Sstevel@tonic-gate rp->r_cs = UCS_SEL;
7670Sstevel@tonic-gate rp->r_ss = UDS_SEL;
7680Sstevel@tonic-gate }
7690Sstevel@tonic-gate
7700Sstevel@tonic-gate /*
7710Sstevel@tonic-gate * Don't set lwp_eosys here. sendsig() is called via psig() after
7720Sstevel@tonic-gate * lwp_eosys is handled, so setting it here would affect the next
7730Sstevel@tonic-gate * system call.
7740Sstevel@tonic-gate */
7750Sstevel@tonic-gate return (1);
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate badstack:
7780Sstevel@tonic-gate no_fault();
7790Sstevel@tonic-gate if (watched)
7800Sstevel@tonic-gate watch_enable_addr((caddr_t)sp, minstacksz, S_WRITE);
7810Sstevel@tonic-gate if (tuc)
7820Sstevel@tonic-gate kmem_free(tuc, sizeof (*tuc));
7830Sstevel@tonic-gate #ifdef DEBUG
7840Sstevel@tonic-gate printf("sendsig: bad signal stack cmd=%s, pid=%d, sig=%d\n",
7850Sstevel@tonic-gate PTOU(p)->u_comm, p->p_pid, sig);
7860Sstevel@tonic-gate printf("on fault, sigsp = 0x%p, action = 0x%p, upc = 0x%lx\n",
7870Sstevel@tonic-gate (void *)sp, (void *)hdlr, (uintptr_t)upc);
7880Sstevel@tonic-gate #endif
7890Sstevel@tonic-gate return (0);
7900Sstevel@tonic-gate }
7910Sstevel@tonic-gate
7920Sstevel@tonic-gate #endif /* __i386 */
793