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
51829Ssudheer  * Common Development and Distribution License (the "License").
61829Ssudheer  * 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  */
210Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
26*5235Sksadhukh  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
270Sstevel@tonic-gate  * Use is subject to license terms.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/param.h>
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <sys/vmparam.h>
350Sstevel@tonic-gate #include <sys/systm.h>
360Sstevel@tonic-gate #include <sys/signal.h>
370Sstevel@tonic-gate #include <sys/stack.h>
380Sstevel@tonic-gate #include <sys/regset.h>
390Sstevel@tonic-gate #include <sys/privregs.h>
400Sstevel@tonic-gate #include <sys/frame.h>
410Sstevel@tonic-gate #include <sys/proc.h>
420Sstevel@tonic-gate #include <sys/psw.h>
430Sstevel@tonic-gate #include <sys/ucontext.h>
440Sstevel@tonic-gate #include <sys/asm_linkage.h>
450Sstevel@tonic-gate #include <sys/errno.h>
460Sstevel@tonic-gate #include <sys/archsystm.h>
470Sstevel@tonic-gate #include <sys/schedctl.h>
480Sstevel@tonic-gate #include <sys/debug.h>
490Sstevel@tonic-gate #include <sys/sysmacros.h>
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * Save user context.
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate void
550Sstevel@tonic-gate savecontext(ucontext_t *ucp, k_sigset_t mask)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
580Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
591829Ssudheer 	struct regs *rp = lwptoregs(lwp);
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	/*
620Sstevel@tonic-gate 	 * We unconditionally assign to every field through the end
630Sstevel@tonic-gate 	 * of the gregs, but we need to bzero() everything -after- that
640Sstevel@tonic-gate 	 * to avoid having any kernel stack garbage escape to userland.
650Sstevel@tonic-gate 	 */
660Sstevel@tonic-gate 	bzero(&ucp->uc_mcontext.fpregs, sizeof (ucontext_t) -
670Sstevel@tonic-gate 	    offsetof(ucontext_t, uc_mcontext.fpregs));
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	ucp->uc_flags = UC_ALL;
700Sstevel@tonic-gate 	ucp->uc_link = (struct ucontext *)lwp->lwp_oldcontext;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	/*
730Sstevel@tonic-gate 	 * Try to copyin() the ustack if one is registered. If the stack
740Sstevel@tonic-gate 	 * has zero size, this indicates that stack bounds checking has
750Sstevel@tonic-gate 	 * been disabled for this LWP. If stack bounds checking is disabled
760Sstevel@tonic-gate 	 * or the copyin() fails, we fall back to the legacy behavior.
770Sstevel@tonic-gate 	 */
780Sstevel@tonic-gate 	if (lwp->lwp_ustack == NULL ||
790Sstevel@tonic-gate 	    copyin((void *)lwp->lwp_ustack, &ucp->uc_stack,
800Sstevel@tonic-gate 	    sizeof (ucp->uc_stack)) != 0 ||
810Sstevel@tonic-gate 	    ucp->uc_stack.ss_size == 0) {
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 		if (lwp->lwp_sigaltstack.ss_flags == SS_ONSTACK) {
840Sstevel@tonic-gate 			ucp->uc_stack = lwp->lwp_sigaltstack;
850Sstevel@tonic-gate 		} else {
860Sstevel@tonic-gate 			ucp->uc_stack.ss_sp = p->p_usrstack - p->p_stksize;
870Sstevel@tonic-gate 			ucp->uc_stack.ss_size = p->p_stksize;
880Sstevel@tonic-gate 			ucp->uc_stack.ss_flags = 0;
890Sstevel@tonic-gate 		}
900Sstevel@tonic-gate 	}
910Sstevel@tonic-gate 
92*5235Sksadhukh 	/*
93*5235Sksadhukh 	 * If either the trace flag or REQUEST_STEP is set,
94*5235Sksadhukh 	 * arrange for single-stepping and turn off the trace flag.
95*5235Sksadhukh 	 */
96*5235Sksadhukh 	if ((rp->r_ps & PS_T) || (lwp->lwp_pcb.pcb_flags & REQUEST_STEP)) {
97*5235Sksadhukh 		/*
98*5235Sksadhukh 		 * Clear PS_T so that saved user context won't have trace
99*5235Sksadhukh 		 * flag set.
100*5235Sksadhukh 		 */
101*5235Sksadhukh 		rp->r_ps &= ~PS_T;
102*5235Sksadhukh 
103*5235Sksadhukh 		if (!(lwp->lwp_pcb.pcb_flags & REQUEST_NOSTEP)) {
104*5235Sksadhukh 			lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
105*5235Sksadhukh 			/*
106*5235Sksadhukh 			 * trap() always checks DEBUG_PENDING before
107*5235Sksadhukh 			 * checking for any pending signal. This at times
108*5235Sksadhukh 			 * can potentially lead to DEBUG_PENDING not being
109*5235Sksadhukh 			 * honoured. (for eg: the lwp is stopped by
110*5235Sksadhukh 			 * stop_on_fault() called from trap(), after being
111*5235Sksadhukh 			 * awakened it might see a pending signal and call
112*5235Sksadhukh 			 * savecontext(), however on the way back to userland
113*5235Sksadhukh 			 * there is no place it can be detected). Hence in
114*5235Sksadhukh 			 * anticipation of such occassions, set AST flag for
115*5235Sksadhukh 			 * the thread which will make the thread take an
116*5235Sksadhukh 			 * excursion through trap() where it will be handled
117*5235Sksadhukh 			 * appropriately.
118*5235Sksadhukh 			 */
119*5235Sksadhukh 			aston(curthread);
120*5235Sksadhukh 		}
121*5235Sksadhukh 	}
122*5235Sksadhukh 
1230Sstevel@tonic-gate 	getgregs(lwp, ucp->uc_mcontext.gregs);
1240Sstevel@tonic-gate 	if (lwp->lwp_pcb.pcb_fpu.fpu_flags & FPU_EN)
1250Sstevel@tonic-gate 		getfpregs(lwp, &ucp->uc_mcontext.fpregs);
1260Sstevel@tonic-gate 	else
1270Sstevel@tonic-gate 		ucp->uc_flags &= ~UC_FPU;
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	sigktou(&mask, &ucp->uc_sigmask);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate /*
1330Sstevel@tonic-gate  * Restore user context.
1340Sstevel@tonic-gate  */
1350Sstevel@tonic-gate void
1360Sstevel@tonic-gate restorecontext(ucontext_t *ucp)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate 	kthread_t *t = curthread;
1390Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(t);
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	lwp->lwp_oldcontext = (uintptr_t)ucp->uc_link;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	if (ucp->uc_flags & UC_STACK) {
1440Sstevel@tonic-gate 		if (ucp->uc_stack.ss_flags == SS_ONSTACK)
1450Sstevel@tonic-gate 			lwp->lwp_sigaltstack = ucp->uc_stack;
1460Sstevel@tonic-gate 		else
1470Sstevel@tonic-gate 			lwp->lwp_sigaltstack.ss_flags &= ~SS_ONSTACK;
1480Sstevel@tonic-gate 	}
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	if (ucp->uc_flags & UC_CPU) {
1511829Ssudheer 		/*
1521829Ssudheer 		 * If the trace flag is set, mark the lwp to take a
1531829Ssudheer 		 * single-step trap on return to user level (below).
1541829Ssudheer 		 * The x86 lcall interface and sysenter has already done this,
1551829Ssudheer 		 * and turned off the flag, but amd64 syscall interface has not.
1561829Ssudheer 		 */
1571829Ssudheer 		if (lwptoregs(lwp)->r_ps & PS_T)
1581829Ssudheer 			lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
1590Sstevel@tonic-gate 		setgregs(lwp, ucp->uc_mcontext.gregs);
1600Sstevel@tonic-gate 		lwp->lwp_eosys = JUSTRETURN;
1610Sstevel@tonic-gate 		t->t_post_sys = 1;
1622086Ssudheer 		aston(curthread);
1630Sstevel@tonic-gate 	}
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	if (ucp->uc_flags & UC_FPU)
1660Sstevel@tonic-gate 		setfpregs(lwp, &ucp->uc_mcontext.fpregs);
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	if (ucp->uc_flags & UC_SIGMASK) {
1690Sstevel@tonic-gate 		proc_t *p = ttoproc(t);
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 		mutex_enter(&p->p_lock);
1720Sstevel@tonic-gate 		schedctl_finish_sigblock(t);
1730Sstevel@tonic-gate 		sigutok(&ucp->uc_sigmask, &t->t_hold);
1740Sstevel@tonic-gate 		if (sigcheck(p, t))
1750Sstevel@tonic-gate 			t->t_sig_check = 1;
1760Sstevel@tonic-gate 		mutex_exit(&p->p_lock);
1770Sstevel@tonic-gate 	}
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate int
1820Sstevel@tonic-gate getsetcontext(int flag, void *arg)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate 	ucontext_t uc;
1850Sstevel@tonic-gate 	ucontext_t *ucp;
1860Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
1870Sstevel@tonic-gate 	stack_t dummy_stk;
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	/*
1900Sstevel@tonic-gate 	 * In future releases, when the ucontext structure grows,
1910Sstevel@tonic-gate 	 * getcontext should be modified to only return the fields
1920Sstevel@tonic-gate 	 * specified in the uc_flags.  That way, the structure can grow
1930Sstevel@tonic-gate 	 * and still be binary compatible will all .o's which will only
1940Sstevel@tonic-gate 	 * have old fields defined in uc_flags
1950Sstevel@tonic-gate 	 */
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	switch (flag) {
1980Sstevel@tonic-gate 	default:
1990Sstevel@tonic-gate 		return (set_errno(EINVAL));
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	case GETCONTEXT:
2020Sstevel@tonic-gate 		if (schedctl_sigblock(curthread)) {
2030Sstevel@tonic-gate 			proc_t *p = ttoproc(curthread);
2040Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
2050Sstevel@tonic-gate 			schedctl_finish_sigblock(curthread);
2060Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
2070Sstevel@tonic-gate 		}
2080Sstevel@tonic-gate 		savecontext(&uc, curthread->t_hold);
2090Sstevel@tonic-gate 		if (copyout(&uc, arg, sizeof (uc)))
2100Sstevel@tonic-gate 			return (set_errno(EFAULT));
2110Sstevel@tonic-gate 		return (0);
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	case SETCONTEXT:
2140Sstevel@tonic-gate 		ucp = arg;
2150Sstevel@tonic-gate 		if (ucp == NULL)
2160Sstevel@tonic-gate 			exit(CLD_EXITED, 0);
2170Sstevel@tonic-gate 		/*
2180Sstevel@tonic-gate 		 * Don't copyin filler or floating state unless we need it.
2190Sstevel@tonic-gate 		 * The ucontext_t struct and fields are specified in the ABI.
2200Sstevel@tonic-gate 		 */
2210Sstevel@tonic-gate 		if (copyin(ucp, &uc, sizeof (ucontext_t) -
2220Sstevel@tonic-gate 		    sizeof (uc.uc_filler) -
2230Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
2240Sstevel@tonic-gate 			return (set_errno(EFAULT));
2250Sstevel@tonic-gate 		}
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 		if ((uc.uc_flags & UC_FPU) &&
2280Sstevel@tonic-gate 		    copyin(&ucp->uc_mcontext.fpregs, &uc.uc_mcontext.fpregs,
2290Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
2300Sstevel@tonic-gate 			return (set_errno(EFAULT));
2310Sstevel@tonic-gate 		}
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 		restorecontext(&uc);
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 		if ((uc.uc_flags & UC_STACK) && (lwp->lwp_ustack != 0))
2360Sstevel@tonic-gate 			(void) copyout(&uc.uc_stack, (stack_t *)lwp->lwp_ustack,
2370Sstevel@tonic-gate 			    sizeof (uc.uc_stack));
2380Sstevel@tonic-gate 		return (0);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	case GETUSTACK:
2410Sstevel@tonic-gate 		if (copyout(&lwp->lwp_ustack, arg, sizeof (caddr_t)))
2420Sstevel@tonic-gate 			return (set_errno(EFAULT));
2430Sstevel@tonic-gate 		return (0);
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	case SETUSTACK:
2460Sstevel@tonic-gate 		if (copyin(arg, &dummy_stk, sizeof (dummy_stk)))
2470Sstevel@tonic-gate 			return (set_errno(EFAULT));
2480Sstevel@tonic-gate 		lwp->lwp_ustack = (uintptr_t)arg;
2490Sstevel@tonic-gate 		return (0);
2500Sstevel@tonic-gate 	}
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate /*
2560Sstevel@tonic-gate  * Save user context for 32-bit processes.
2570Sstevel@tonic-gate  */
2580Sstevel@tonic-gate void
2590Sstevel@tonic-gate savecontext32(ucontext32_t *ucp, k_sigset_t mask)
2600Sstevel@tonic-gate {
2610Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
2620Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
2631829Ssudheer 	struct regs *rp = lwptoregs(lwp);
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	bzero(&ucp->uc_mcontext.fpregs, sizeof (ucontext32_t) -
2660Sstevel@tonic-gate 	    offsetof(ucontext32_t, uc_mcontext.fpregs));
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	ucp->uc_flags = UC_ALL;
2690Sstevel@tonic-gate 	ucp->uc_link = (caddr32_t)lwp->lwp_oldcontext;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate 	if (lwp->lwp_ustack == NULL ||
2720Sstevel@tonic-gate 	    copyin((void *)lwp->lwp_ustack, &ucp->uc_stack,
2730Sstevel@tonic-gate 	    sizeof (ucp->uc_stack)) != 0 ||
2740Sstevel@tonic-gate 	    ucp->uc_stack.ss_size == 0) {
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 		if (lwp->lwp_sigaltstack.ss_flags == SS_ONSTACK) {
2770Sstevel@tonic-gate 			ucp->uc_stack.ss_sp =
2780Sstevel@tonic-gate 			    (caddr32_t)(uintptr_t)lwp->lwp_sigaltstack.ss_sp;
2790Sstevel@tonic-gate 			ucp->uc_stack.ss_size =
2800Sstevel@tonic-gate 			    (size32_t)lwp->lwp_sigaltstack.ss_size;
2810Sstevel@tonic-gate 			ucp->uc_stack.ss_flags = SS_ONSTACK;
2820Sstevel@tonic-gate 		} else {
2830Sstevel@tonic-gate 			ucp->uc_stack.ss_sp = (caddr32_t)(uintptr_t)
2840Sstevel@tonic-gate 			    (p->p_usrstack - p->p_stksize);
2850Sstevel@tonic-gate 			ucp->uc_stack.ss_size = (size32_t)p->p_stksize;
2860Sstevel@tonic-gate 			ucp->uc_stack.ss_flags = 0;
2870Sstevel@tonic-gate 		}
2880Sstevel@tonic-gate 	}
2890Sstevel@tonic-gate 
290*5235Sksadhukh 	/*
291*5235Sksadhukh 	 * If either the trace flag or REQUEST_STEP is set, arrange
292*5235Sksadhukh 	 * for single-stepping and turn off the trace flag.
293*5235Sksadhukh 	 */
294*5235Sksadhukh 	if ((rp->r_ps & PS_T) || (lwp->lwp_pcb.pcb_flags & REQUEST_STEP)) {
295*5235Sksadhukh 		/*
296*5235Sksadhukh 		 * Clear PS_T so that saved user context won't have trace
297*5235Sksadhukh 		 * flag set.
298*5235Sksadhukh 		 */
299*5235Sksadhukh 		rp->r_ps &= ~PS_T;
300*5235Sksadhukh 
301*5235Sksadhukh 		if (!(lwp->lwp_pcb.pcb_flags & REQUEST_NOSTEP)) {
302*5235Sksadhukh 			lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
303*5235Sksadhukh 			/*
304*5235Sksadhukh 			 * See comments in savecontext().
305*5235Sksadhukh 			 */
306*5235Sksadhukh 			aston(curthread);
307*5235Sksadhukh 		}
308*5235Sksadhukh 	}
309*5235Sksadhukh 
3100Sstevel@tonic-gate 	getgregs32(lwp, ucp->uc_mcontext.gregs);
3110Sstevel@tonic-gate 	if (lwp->lwp_pcb.pcb_fpu.fpu_flags & FPU_EN)
3120Sstevel@tonic-gate 		getfpregs32(lwp, &ucp->uc_mcontext.fpregs);
3130Sstevel@tonic-gate 	else
3140Sstevel@tonic-gate 		ucp->uc_flags &= ~UC_FPU;
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	sigktou(&mask, &ucp->uc_sigmask);
3170Sstevel@tonic-gate }
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate int
3200Sstevel@tonic-gate getsetcontext32(int flag, void *arg)
3210Sstevel@tonic-gate {
3220Sstevel@tonic-gate 	ucontext32_t uc;
3230Sstevel@tonic-gate 	ucontext_t ucnat;
3240Sstevel@tonic-gate 	ucontext32_t *ucp;
3250Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
3260Sstevel@tonic-gate 	caddr32_t ustack32;
3270Sstevel@tonic-gate 	stack32_t dummy_stk32;
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 	switch (flag) {
3300Sstevel@tonic-gate 	default:
3310Sstevel@tonic-gate 		return (set_errno(EINVAL));
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	case GETCONTEXT:
3340Sstevel@tonic-gate 		if (schedctl_sigblock(curthread)) {
3350Sstevel@tonic-gate 			proc_t *p = ttoproc(curthread);
3360Sstevel@tonic-gate 			mutex_enter(&p->p_lock);
3370Sstevel@tonic-gate 			schedctl_finish_sigblock(curthread);
3380Sstevel@tonic-gate 			mutex_exit(&p->p_lock);
3390Sstevel@tonic-gate 		}
3400Sstevel@tonic-gate 		savecontext32(&uc, curthread->t_hold);
3410Sstevel@tonic-gate 		if (copyout(&uc, arg, sizeof (uc)))
3420Sstevel@tonic-gate 			return (set_errno(EFAULT));
3430Sstevel@tonic-gate 		return (0);
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 	case SETCONTEXT:
3460Sstevel@tonic-gate 		ucp = arg;
3470Sstevel@tonic-gate 		if (ucp == NULL)
3480Sstevel@tonic-gate 			exit(CLD_EXITED, 0);
3490Sstevel@tonic-gate 		if (copyin(ucp, &uc, sizeof (uc) -
3500Sstevel@tonic-gate 		    sizeof (uc.uc_filler) -
3510Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
3520Sstevel@tonic-gate 			return (set_errno(EFAULT));
3530Sstevel@tonic-gate 		}
3540Sstevel@tonic-gate 		if ((uc.uc_flags & UC_FPU) &&
3550Sstevel@tonic-gate 		    copyin(&ucp->uc_mcontext.fpregs, &uc.uc_mcontext.fpregs,
3560Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
3570Sstevel@tonic-gate 			return (set_errno(EFAULT));
3580Sstevel@tonic-gate 		}
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 		ucontext_32ton(&uc, &ucnat);
3610Sstevel@tonic-gate 		restorecontext(&ucnat);
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 		if ((uc.uc_flags & UC_STACK) && (lwp->lwp_ustack != 0))
3640Sstevel@tonic-gate 			(void) copyout(&uc.uc_stack,
3650Sstevel@tonic-gate 			    (stack32_t *)lwp->lwp_ustack, sizeof (uc.uc_stack));
3660Sstevel@tonic-gate 		return (0);
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	case GETUSTACK:
3690Sstevel@tonic-gate 		ustack32 = (caddr32_t)lwp->lwp_ustack;
3700Sstevel@tonic-gate 		if (copyout(&ustack32, arg, sizeof (ustack32)))
3710Sstevel@tonic-gate 			return (set_errno(EFAULT));
3720Sstevel@tonic-gate 		return (0);
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	case SETUSTACK:
3750Sstevel@tonic-gate 		if (copyin(arg, &dummy_stk32, sizeof (dummy_stk32)))
3760Sstevel@tonic-gate 			return (set_errno(EFAULT));
3770Sstevel@tonic-gate 		lwp->lwp_ustack = (uintptr_t)arg;
3780Sstevel@tonic-gate 		return (0);
3790Sstevel@tonic-gate 	}
3800Sstevel@tonic-gate }
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
383