xref: /onnv-gate/usr/src/uts/intel/ia32/syscall/getcontext.c (revision 11970:9c3f3660b754)
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 
220Sstevel@tonic-gate /*
2311913SRoger.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 
2710341SRoger.Faulkner@Sun.COM /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2810341SRoger.Faulkner@Sun.COM /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/vmparam.h>
330Sstevel@tonic-gate #include <sys/systm.h>
340Sstevel@tonic-gate #include <sys/signal.h>
350Sstevel@tonic-gate #include <sys/stack.h>
360Sstevel@tonic-gate #include <sys/regset.h>
370Sstevel@tonic-gate #include <sys/privregs.h>
380Sstevel@tonic-gate #include <sys/frame.h>
390Sstevel@tonic-gate #include <sys/proc.h>
40*11970SRoger.Faulkner@Sun.COM #include <sys/brand.h>
410Sstevel@tonic-gate #include <sys/psw.h>
420Sstevel@tonic-gate #include <sys/ucontext.h>
430Sstevel@tonic-gate #include <sys/asm_linkage.h>
440Sstevel@tonic-gate #include <sys/errno.h>
450Sstevel@tonic-gate #include <sys/archsystm.h>
460Sstevel@tonic-gate #include <sys/schedctl.h>
470Sstevel@tonic-gate #include <sys/debug.h>
480Sstevel@tonic-gate #include <sys/sysmacros.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * Save user context.
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate void
savecontext(ucontext_t * ucp,const k_sigset_t * mask)5411913SRoger.Faulkner@Sun.COM savecontext(ucontext_t *ucp, const k_sigset_t *mask)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
570Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
581829Ssudheer 	struct regs *rp = lwptoregs(lwp);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	/*
610Sstevel@tonic-gate 	 * We unconditionally assign to every field through the end
620Sstevel@tonic-gate 	 * of the gregs, but we need to bzero() everything -after- that
630Sstevel@tonic-gate 	 * to avoid having any kernel stack garbage escape to userland.
640Sstevel@tonic-gate 	 */
650Sstevel@tonic-gate 	bzero(&ucp->uc_mcontext.fpregs, sizeof (ucontext_t) -
660Sstevel@tonic-gate 	    offsetof(ucontext_t, uc_mcontext.fpregs));
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	ucp->uc_flags = UC_ALL;
690Sstevel@tonic-gate 	ucp->uc_link = (struct ucontext *)lwp->lwp_oldcontext;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	/*
720Sstevel@tonic-gate 	 * Try to copyin() the ustack if one is registered. If the stack
730Sstevel@tonic-gate 	 * has zero size, this indicates that stack bounds checking has
740Sstevel@tonic-gate 	 * been disabled for this LWP. If stack bounds checking is disabled
750Sstevel@tonic-gate 	 * or the copyin() fails, we fall back to the legacy behavior.
760Sstevel@tonic-gate 	 */
770Sstevel@tonic-gate 	if (lwp->lwp_ustack == NULL ||
780Sstevel@tonic-gate 	    copyin((void *)lwp->lwp_ustack, &ucp->uc_stack,
790Sstevel@tonic-gate 	    sizeof (ucp->uc_stack)) != 0 ||
800Sstevel@tonic-gate 	    ucp->uc_stack.ss_size == 0) {
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 		if (lwp->lwp_sigaltstack.ss_flags == SS_ONSTACK) {
830Sstevel@tonic-gate 			ucp->uc_stack = lwp->lwp_sigaltstack;
840Sstevel@tonic-gate 		} else {
850Sstevel@tonic-gate 			ucp->uc_stack.ss_sp = p->p_usrstack - p->p_stksize;
860Sstevel@tonic-gate 			ucp->uc_stack.ss_size = p->p_stksize;
870Sstevel@tonic-gate 			ucp->uc_stack.ss_flags = 0;
880Sstevel@tonic-gate 		}
890Sstevel@tonic-gate 	}
900Sstevel@tonic-gate 
915235Sksadhukh 	/*
925235Sksadhukh 	 * If either the trace flag or REQUEST_STEP is set,
935235Sksadhukh 	 * arrange for single-stepping and turn off the trace flag.
945235Sksadhukh 	 */
955235Sksadhukh 	if ((rp->r_ps & PS_T) || (lwp->lwp_pcb.pcb_flags & REQUEST_STEP)) {
965235Sksadhukh 		/*
975235Sksadhukh 		 * Clear PS_T so that saved user context won't have trace
985235Sksadhukh 		 * flag set.
995235Sksadhukh 		 */
1005235Sksadhukh 		rp->r_ps &= ~PS_T;
1015235Sksadhukh 
1025235Sksadhukh 		if (!(lwp->lwp_pcb.pcb_flags & REQUEST_NOSTEP)) {
1035235Sksadhukh 			lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
1045235Sksadhukh 			/*
1055235Sksadhukh 			 * trap() always checks DEBUG_PENDING before
1065235Sksadhukh 			 * checking for any pending signal. This at times
1075235Sksadhukh 			 * can potentially lead to DEBUG_PENDING not being
1085235Sksadhukh 			 * honoured. (for eg: the lwp is stopped by
1095235Sksadhukh 			 * stop_on_fault() called from trap(), after being
1105235Sksadhukh 			 * awakened it might see a pending signal and call
1115235Sksadhukh 			 * savecontext(), however on the way back to userland
1125235Sksadhukh 			 * there is no place it can be detected). Hence in
1135235Sksadhukh 			 * anticipation of such occassions, set AST flag for
1145235Sksadhukh 			 * the thread which will make the thread take an
1155235Sksadhukh 			 * excursion through trap() where it will be handled
1165235Sksadhukh 			 * appropriately.
1175235Sksadhukh 			 */
1185235Sksadhukh 			aston(curthread);
1195235Sksadhukh 		}
1205235Sksadhukh 	}
1215235Sksadhukh 
1220Sstevel@tonic-gate 	getgregs(lwp, ucp->uc_mcontext.gregs);
1230Sstevel@tonic-gate 	if (lwp->lwp_pcb.pcb_fpu.fpu_flags & FPU_EN)
1240Sstevel@tonic-gate 		getfpregs(lwp, &ucp->uc_mcontext.fpregs);
1250Sstevel@tonic-gate 	else
1260Sstevel@tonic-gate 		ucp->uc_flags &= ~UC_FPU;
1270Sstevel@tonic-gate 
12811913SRoger.Faulkner@Sun.COM 	sigktou(mask, &ucp->uc_sigmask);
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * Restore user context.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate void
restorecontext(ucontext_t * ucp)1350Sstevel@tonic-gate restorecontext(ucontext_t *ucp)
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate 	kthread_t *t = curthread;
1380Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(t);
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	lwp->lwp_oldcontext = (uintptr_t)ucp->uc_link;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	if (ucp->uc_flags & UC_STACK) {
1430Sstevel@tonic-gate 		if (ucp->uc_stack.ss_flags == SS_ONSTACK)
1440Sstevel@tonic-gate 			lwp->lwp_sigaltstack = ucp->uc_stack;
1450Sstevel@tonic-gate 		else
1460Sstevel@tonic-gate 			lwp->lwp_sigaltstack.ss_flags &= ~SS_ONSTACK;
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	if (ucp->uc_flags & UC_CPU) {
1501829Ssudheer 		/*
1511829Ssudheer 		 * If the trace flag is set, mark the lwp to take a
1521829Ssudheer 		 * single-step trap on return to user level (below).
1531829Ssudheer 		 * The x86 lcall interface and sysenter has already done this,
1541829Ssudheer 		 * and turned off the flag, but amd64 syscall interface has not.
1551829Ssudheer 		 */
1561829Ssudheer 		if (lwptoregs(lwp)->r_ps & PS_T)
1571829Ssudheer 			lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
1580Sstevel@tonic-gate 		setgregs(lwp, ucp->uc_mcontext.gregs);
1590Sstevel@tonic-gate 		lwp->lwp_eosys = JUSTRETURN;
1600Sstevel@tonic-gate 		t->t_post_sys = 1;
1612086Ssudheer 		aston(curthread);
1620Sstevel@tonic-gate 	}
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	if (ucp->uc_flags & UC_FPU)
1650Sstevel@tonic-gate 		setfpregs(lwp, &ucp->uc_mcontext.fpregs);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	if (ucp->uc_flags & UC_SIGMASK) {
16810341SRoger.Faulkner@Sun.COM 		/*
16910341SRoger.Faulkner@Sun.COM 		 * We don't need to acquire p->p_lock here;
17010341SRoger.Faulkner@Sun.COM 		 * we are manipulating thread-private data.
17110341SRoger.Faulkner@Sun.COM 		 */
1720Sstevel@tonic-gate 		schedctl_finish_sigblock(t);
1730Sstevel@tonic-gate 		sigutok(&ucp->uc_sigmask, &t->t_hold);
17410341SRoger.Faulkner@Sun.COM 		if (sigcheck(ttoproc(t), t))
1750Sstevel@tonic-gate 			t->t_sig_check = 1;
1760Sstevel@tonic-gate 	}
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate int
getsetcontext(int flag,void * arg)1810Sstevel@tonic-gate getsetcontext(int flag, void *arg)
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	ucontext_t uc;
1840Sstevel@tonic-gate 	ucontext_t *ucp;
1850Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
1860Sstevel@tonic-gate 	stack_t dummy_stk;
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	/*
1890Sstevel@tonic-gate 	 * In future releases, when the ucontext structure grows,
1900Sstevel@tonic-gate 	 * getcontext should be modified to only return the fields
1910Sstevel@tonic-gate 	 * specified in the uc_flags.  That way, the structure can grow
1920Sstevel@tonic-gate 	 * and still be binary compatible will all .o's which will only
1930Sstevel@tonic-gate 	 * have old fields defined in uc_flags
1940Sstevel@tonic-gate 	 */
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 	switch (flag) {
1970Sstevel@tonic-gate 	default:
1980Sstevel@tonic-gate 		return (set_errno(EINVAL));
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate 	case GETCONTEXT:
20110341SRoger.Faulkner@Sun.COM 		schedctl_finish_sigblock(curthread);
20211913SRoger.Faulkner@Sun.COM 		savecontext(&uc, &curthread->t_hold);
203*11970SRoger.Faulkner@Sun.COM 		if (uc.uc_flags & UC_SIGMASK)
204*11970SRoger.Faulkner@Sun.COM 			SIGSET_NATIVE_TO_BRAND(&uc.uc_sigmask);
2050Sstevel@tonic-gate 		if (copyout(&uc, arg, sizeof (uc)))
2060Sstevel@tonic-gate 			return (set_errno(EFAULT));
2070Sstevel@tonic-gate 		return (0);
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 	case SETCONTEXT:
2100Sstevel@tonic-gate 		ucp = arg;
2110Sstevel@tonic-gate 		if (ucp == NULL)
2120Sstevel@tonic-gate 			exit(CLD_EXITED, 0);
2130Sstevel@tonic-gate 		/*
2140Sstevel@tonic-gate 		 * Don't copyin filler or floating state unless we need it.
2150Sstevel@tonic-gate 		 * The ucontext_t struct and fields are specified in the ABI.
2160Sstevel@tonic-gate 		 */
2170Sstevel@tonic-gate 		if (copyin(ucp, &uc, sizeof (ucontext_t) -
2180Sstevel@tonic-gate 		    sizeof (uc.uc_filler) -
2190Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
2200Sstevel@tonic-gate 			return (set_errno(EFAULT));
2210Sstevel@tonic-gate 		}
222*11970SRoger.Faulkner@Sun.COM 		if (uc.uc_flags & UC_SIGMASK)
223*11970SRoger.Faulkner@Sun.COM 			SIGSET_BRAND_TO_NATIVE(&uc.uc_sigmask);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 		if ((uc.uc_flags & UC_FPU) &&
2260Sstevel@tonic-gate 		    copyin(&ucp->uc_mcontext.fpregs, &uc.uc_mcontext.fpregs,
2270Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
2280Sstevel@tonic-gate 			return (set_errno(EFAULT));
2290Sstevel@tonic-gate 		}
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 		restorecontext(&uc);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 		if ((uc.uc_flags & UC_STACK) && (lwp->lwp_ustack != 0))
2340Sstevel@tonic-gate 			(void) copyout(&uc.uc_stack, (stack_t *)lwp->lwp_ustack,
2350Sstevel@tonic-gate 			    sizeof (uc.uc_stack));
2360Sstevel@tonic-gate 		return (0);
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 	case GETUSTACK:
2390Sstevel@tonic-gate 		if (copyout(&lwp->lwp_ustack, arg, sizeof (caddr_t)))
2400Sstevel@tonic-gate 			return (set_errno(EFAULT));
2410Sstevel@tonic-gate 		return (0);
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	case SETUSTACK:
2440Sstevel@tonic-gate 		if (copyin(arg, &dummy_stk, sizeof (dummy_stk)))
2450Sstevel@tonic-gate 			return (set_errno(EFAULT));
2460Sstevel@tonic-gate 		lwp->lwp_ustack = (uintptr_t)arg;
2470Sstevel@tonic-gate 		return (0);
2480Sstevel@tonic-gate 	}
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate /*
2540Sstevel@tonic-gate  * Save user context for 32-bit processes.
2550Sstevel@tonic-gate  */
2560Sstevel@tonic-gate void
savecontext32(ucontext32_t * ucp,const k_sigset_t * mask)25711913SRoger.Faulkner@Sun.COM savecontext32(ucontext32_t *ucp, const k_sigset_t *mask)
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
2600Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
2611829Ssudheer 	struct regs *rp = lwptoregs(lwp);
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	bzero(&ucp->uc_mcontext.fpregs, sizeof (ucontext32_t) -
2640Sstevel@tonic-gate 	    offsetof(ucontext32_t, uc_mcontext.fpregs));
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate 	ucp->uc_flags = UC_ALL;
2670Sstevel@tonic-gate 	ucp->uc_link = (caddr32_t)lwp->lwp_oldcontext;
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	if (lwp->lwp_ustack == NULL ||
2700Sstevel@tonic-gate 	    copyin((void *)lwp->lwp_ustack, &ucp->uc_stack,
2710Sstevel@tonic-gate 	    sizeof (ucp->uc_stack)) != 0 ||
2720Sstevel@tonic-gate 	    ucp->uc_stack.ss_size == 0) {
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate 		if (lwp->lwp_sigaltstack.ss_flags == SS_ONSTACK) {
2750Sstevel@tonic-gate 			ucp->uc_stack.ss_sp =
2760Sstevel@tonic-gate 			    (caddr32_t)(uintptr_t)lwp->lwp_sigaltstack.ss_sp;
2770Sstevel@tonic-gate 			ucp->uc_stack.ss_size =
2780Sstevel@tonic-gate 			    (size32_t)lwp->lwp_sigaltstack.ss_size;
2790Sstevel@tonic-gate 			ucp->uc_stack.ss_flags = SS_ONSTACK;
2800Sstevel@tonic-gate 		} else {
2810Sstevel@tonic-gate 			ucp->uc_stack.ss_sp = (caddr32_t)(uintptr_t)
2820Sstevel@tonic-gate 			    (p->p_usrstack - p->p_stksize);
2830Sstevel@tonic-gate 			ucp->uc_stack.ss_size = (size32_t)p->p_stksize;
2840Sstevel@tonic-gate 			ucp->uc_stack.ss_flags = 0;
2850Sstevel@tonic-gate 		}
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 
2885235Sksadhukh 	/*
2895235Sksadhukh 	 * If either the trace flag or REQUEST_STEP is set, arrange
2905235Sksadhukh 	 * for single-stepping and turn off the trace flag.
2915235Sksadhukh 	 */
2925235Sksadhukh 	if ((rp->r_ps & PS_T) || (lwp->lwp_pcb.pcb_flags & REQUEST_STEP)) {
2935235Sksadhukh 		/*
2945235Sksadhukh 		 * Clear PS_T so that saved user context won't have trace
2955235Sksadhukh 		 * flag set.
2965235Sksadhukh 		 */
2975235Sksadhukh 		rp->r_ps &= ~PS_T;
2985235Sksadhukh 
2995235Sksadhukh 		if (!(lwp->lwp_pcb.pcb_flags & REQUEST_NOSTEP)) {
3005235Sksadhukh 			lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
3015235Sksadhukh 			/*
3025235Sksadhukh 			 * See comments in savecontext().
3035235Sksadhukh 			 */
3045235Sksadhukh 			aston(curthread);
3055235Sksadhukh 		}
3065235Sksadhukh 	}
3075235Sksadhukh 
3080Sstevel@tonic-gate 	getgregs32(lwp, ucp->uc_mcontext.gregs);
3090Sstevel@tonic-gate 	if (lwp->lwp_pcb.pcb_fpu.fpu_flags & FPU_EN)
3100Sstevel@tonic-gate 		getfpregs32(lwp, &ucp->uc_mcontext.fpregs);
3110Sstevel@tonic-gate 	else
3120Sstevel@tonic-gate 		ucp->uc_flags &= ~UC_FPU;
3130Sstevel@tonic-gate 
31411913SRoger.Faulkner@Sun.COM 	sigktou(mask, &ucp->uc_sigmask);
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate int
getsetcontext32(int flag,void * arg)3180Sstevel@tonic-gate getsetcontext32(int flag, void *arg)
3190Sstevel@tonic-gate {
3200Sstevel@tonic-gate 	ucontext32_t uc;
3210Sstevel@tonic-gate 	ucontext_t ucnat;
3220Sstevel@tonic-gate 	ucontext32_t *ucp;
3230Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
3240Sstevel@tonic-gate 	caddr32_t ustack32;
3250Sstevel@tonic-gate 	stack32_t dummy_stk32;
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 	switch (flag) {
3280Sstevel@tonic-gate 	default:
3290Sstevel@tonic-gate 		return (set_errno(EINVAL));
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	case GETCONTEXT:
33210341SRoger.Faulkner@Sun.COM 		schedctl_finish_sigblock(curthread);
33311913SRoger.Faulkner@Sun.COM 		savecontext32(&uc, &curthread->t_hold);
334*11970SRoger.Faulkner@Sun.COM 		if (uc.uc_flags & UC_SIGMASK)
335*11970SRoger.Faulkner@Sun.COM 			SIGSET_NATIVE_TO_BRAND(&uc.uc_sigmask);
3360Sstevel@tonic-gate 		if (copyout(&uc, arg, sizeof (uc)))
3370Sstevel@tonic-gate 			return (set_errno(EFAULT));
3380Sstevel@tonic-gate 		return (0);
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	case SETCONTEXT:
3410Sstevel@tonic-gate 		ucp = arg;
3420Sstevel@tonic-gate 		if (ucp == NULL)
3430Sstevel@tonic-gate 			exit(CLD_EXITED, 0);
3440Sstevel@tonic-gate 		if (copyin(ucp, &uc, sizeof (uc) -
3450Sstevel@tonic-gate 		    sizeof (uc.uc_filler) -
3460Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
3470Sstevel@tonic-gate 			return (set_errno(EFAULT));
3480Sstevel@tonic-gate 		}
349*11970SRoger.Faulkner@Sun.COM 		if (uc.uc_flags & UC_SIGMASK)
350*11970SRoger.Faulkner@Sun.COM 			SIGSET_BRAND_TO_NATIVE(&uc.uc_sigmask);
3510Sstevel@tonic-gate 		if ((uc.uc_flags & UC_FPU) &&
3520Sstevel@tonic-gate 		    copyin(&ucp->uc_mcontext.fpregs, &uc.uc_mcontext.fpregs,
3530Sstevel@tonic-gate 		    sizeof (uc.uc_mcontext.fpregs))) {
3540Sstevel@tonic-gate 			return (set_errno(EFAULT));
3550Sstevel@tonic-gate 		}
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 		ucontext_32ton(&uc, &ucnat);
3580Sstevel@tonic-gate 		restorecontext(&ucnat);
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 		if ((uc.uc_flags & UC_STACK) && (lwp->lwp_ustack != 0))
3610Sstevel@tonic-gate 			(void) copyout(&uc.uc_stack,
3620Sstevel@tonic-gate 			    (stack32_t *)lwp->lwp_ustack, sizeof (uc.uc_stack));
3630Sstevel@tonic-gate 		return (0);
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate 	case GETUSTACK:
3660Sstevel@tonic-gate 		ustack32 = (caddr32_t)lwp->lwp_ustack;
3670Sstevel@tonic-gate 		if (copyout(&ustack32, arg, sizeof (ustack32)))
3680Sstevel@tonic-gate 			return (set_errno(EFAULT));
3690Sstevel@tonic-gate 		return (0);
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	case SETUSTACK:
3720Sstevel@tonic-gate 		if (copyin(arg, &dummy_stk32, sizeof (dummy_stk32)))
3730Sstevel@tonic-gate 			return (set_errno(EFAULT));
3740Sstevel@tonic-gate 		lwp->lwp_ustack = (uintptr_t)arg;
3750Sstevel@tonic-gate 		return (0);
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
380