xref: /onnv-gate/usr/src/lib/libc/sparc/gen/siglongjmp.c (revision 6812:febeba71273d)
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
5*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * 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  */
211219Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 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) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
30*6812Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
32*6812Sraf #pragma weak _siglongjmp = siglongjmp
330Sstevel@tonic-gate 
34*6812Sraf #include "lint.h"
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate #include <sys/stack.h>
370Sstevel@tonic-gate #include <sys/frame.h>
380Sstevel@tonic-gate #include <memory.h>
390Sstevel@tonic-gate #include <ucontext.h>
400Sstevel@tonic-gate #include <setjmp.h>
410Sstevel@tonic-gate #include "sigjmp_struct.h"
420Sstevel@tonic-gate #include "libc.h"
430Sstevel@tonic-gate 
440Sstevel@tonic-gate void
siglongjmp(sigjmp_buf env,int val)451219Sraf siglongjmp(sigjmp_buf env, int val)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate 	extern void _fetch_globals(greg_t *);
480Sstevel@tonic-gate 	ucontext_t uc;
490Sstevel@tonic-gate 	greg_t *reg = uc.uc_mcontext.gregs;
500Sstevel@tonic-gate 	volatile sigjmp_struct_t *bp = (sigjmp_struct_t *)env;
510Sstevel@tonic-gate 	greg_t fp = bp->sjs_fp;
520Sstevel@tonic-gate 	greg_t i7 = bp->sjs_i7;
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	/*
550Sstevel@tonic-gate 	 * Create a ucontext_t structure from scratch.
560Sstevel@tonic-gate 	 * We only need to fetch the globals.
570Sstevel@tonic-gate 	 * The outs are assumed to be trashed on return from sigsetjmp().
580Sstevel@tonic-gate 	 * The ins and locals are restored from the resumed register window.
590Sstevel@tonic-gate 	 * The floating point state is unmodified.
600Sstevel@tonic-gate 	 * Everything else is in the sigjmp_struct_t buffer.
610Sstevel@tonic-gate 	 */
620Sstevel@tonic-gate 	(void) memset(&uc, 0, sizeof (uc));
630Sstevel@tonic-gate 	uc.uc_flags = UC_STACK | UC_CPU;
640Sstevel@tonic-gate 	_fetch_globals(&reg[REG_G1]);
650Sstevel@tonic-gate 	uc.uc_stack = bp->sjs_stack;
660Sstevel@tonic-gate 	uc.uc_link = bp->sjs_uclink;
670Sstevel@tonic-gate 	reg[REG_PC] = bp->sjs_pc;
680Sstevel@tonic-gate 	reg[REG_nPC] = reg[REG_PC] + 0x4;
690Sstevel@tonic-gate 	reg[REG_SP] = bp->sjs_sp;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	if (bp->sjs_flags & JB_SAVEMASK) {
720Sstevel@tonic-gate 		uc.uc_flags |= UC_SIGMASK;
730Sstevel@tonic-gate 		uc.uc_sigmask = bp->sjs_sigmask;
740Sstevel@tonic-gate 	}
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	if (val)
770Sstevel@tonic-gate 		reg[REG_O0] = (greg_t)val;
780Sstevel@tonic-gate 	else
790Sstevel@tonic-gate 		reg[REG_O0] = (greg_t)1;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	/*
820Sstevel@tonic-gate 	 * Copy the fp and i7 values into the register window save area.
830Sstevel@tonic-gate 	 * These may have been clobbered between calls to sigsetjmp
840Sstevel@tonic-gate 	 * and siglongjmp.  For example, the save area could have been
850Sstevel@tonic-gate 	 * relocated to lower addresses and the original save area
860Sstevel@tonic-gate 	 * given to an alloca() call.  Notice that all reads from
870Sstevel@tonic-gate 	 * the sigjmp_struct_t buffer should take place before the
880Sstevel@tonic-gate 	 * following two writes.  It is possible that user code may
890Sstevel@tonic-gate 	 * move/copy the sigjmpbuf around, and overlap the original
900Sstevel@tonic-gate 	 * register window save area.
910Sstevel@tonic-gate 	 */
920Sstevel@tonic-gate 	if (bp->sjs_sp != 0 && (bp->sjs_flags & JB_FRAMEPTR)) {
930Sstevel@tonic-gate 		struct frame *sp = (struct frame *)(bp->sjs_sp + STACK_BIAS);
940Sstevel@tonic-gate 		sp->fr_savfp = (struct frame *)fp;
950Sstevel@tonic-gate 		sp->fr_savpc = i7;
960Sstevel@tonic-gate 	}
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	(void) setcontext(&uc);
990Sstevel@tonic-gate }
100