xref: /onnv-gate/usr/src/lib/libc/sparc/gen/siglongjmp.c (revision 1219:f89f56c2d9ac)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*1219Sraf 
230Sstevel@tonic-gate /*
24*1219Sraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
310Sstevel@tonic-gate /*	  All Rights Reserved  	*/
320Sstevel@tonic-gate 
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #pragma weak siglongjmp = _siglongjmp
350Sstevel@tonic-gate 
36*1219Sraf #include "synonyms.h"
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate #include <sys/stack.h>
390Sstevel@tonic-gate #include <sys/frame.h>
400Sstevel@tonic-gate #include <memory.h>
410Sstevel@tonic-gate #include <ucontext.h>
420Sstevel@tonic-gate #include <setjmp.h>
430Sstevel@tonic-gate #include "sigjmp_struct.h"
440Sstevel@tonic-gate #include "libc.h"
450Sstevel@tonic-gate 
460Sstevel@tonic-gate void
47*1219Sraf siglongjmp(sigjmp_buf env, int val)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate 	extern void _fetch_globals(greg_t *);
500Sstevel@tonic-gate 	ucontext_t uc;
510Sstevel@tonic-gate 	greg_t *reg = uc.uc_mcontext.gregs;
520Sstevel@tonic-gate 	volatile sigjmp_struct_t *bp = (sigjmp_struct_t *)env;
530Sstevel@tonic-gate 	greg_t fp = bp->sjs_fp;
540Sstevel@tonic-gate 	greg_t i7 = bp->sjs_i7;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	/*
570Sstevel@tonic-gate 	 * Create a ucontext_t structure from scratch.
580Sstevel@tonic-gate 	 * We only need to fetch the globals.
590Sstevel@tonic-gate 	 * The outs are assumed to be trashed on return from sigsetjmp().
600Sstevel@tonic-gate 	 * The ins and locals are restored from the resumed register window.
610Sstevel@tonic-gate 	 * The floating point state is unmodified.
620Sstevel@tonic-gate 	 * Everything else is in the sigjmp_struct_t buffer.
630Sstevel@tonic-gate 	 */
640Sstevel@tonic-gate 	(void) memset(&uc, 0, sizeof (uc));
650Sstevel@tonic-gate 	uc.uc_flags = UC_STACK | UC_CPU;
660Sstevel@tonic-gate 	_fetch_globals(&reg[REG_G1]);
670Sstevel@tonic-gate 	uc.uc_stack = bp->sjs_stack;
680Sstevel@tonic-gate 	uc.uc_link = bp->sjs_uclink;
690Sstevel@tonic-gate 	reg[REG_PC] = bp->sjs_pc;
700Sstevel@tonic-gate 	reg[REG_nPC] = reg[REG_PC] + 0x4;
710Sstevel@tonic-gate 	reg[REG_SP] = bp->sjs_sp;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	if (bp->sjs_flags & JB_SAVEMASK) {
740Sstevel@tonic-gate 		uc.uc_flags |= UC_SIGMASK;
750Sstevel@tonic-gate 		uc.uc_sigmask = bp->sjs_sigmask;
760Sstevel@tonic-gate 	}
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	if (val)
790Sstevel@tonic-gate 		reg[REG_O0] = (greg_t)val;
800Sstevel@tonic-gate 	else
810Sstevel@tonic-gate 		reg[REG_O0] = (greg_t)1;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	/*
840Sstevel@tonic-gate 	 * Copy the fp and i7 values into the register window save area.
850Sstevel@tonic-gate 	 * These may have been clobbered between calls to sigsetjmp
860Sstevel@tonic-gate 	 * and siglongjmp.  For example, the save area could have been
870Sstevel@tonic-gate 	 * relocated to lower addresses and the original save area
880Sstevel@tonic-gate 	 * given to an alloca() call.  Notice that all reads from
890Sstevel@tonic-gate 	 * the sigjmp_struct_t buffer should take place before the
900Sstevel@tonic-gate 	 * following two writes.  It is possible that user code may
910Sstevel@tonic-gate 	 * move/copy the sigjmpbuf around, and overlap the original
920Sstevel@tonic-gate 	 * register window save area.
930Sstevel@tonic-gate 	 */
940Sstevel@tonic-gate 	if (bp->sjs_sp != 0 && (bp->sjs_flags & JB_FRAMEPTR)) {
950Sstevel@tonic-gate 		struct frame *sp = (struct frame *)(bp->sjs_sp + STACK_BIAS);
960Sstevel@tonic-gate 		sp->fr_savfp = (struct frame *)fp;
970Sstevel@tonic-gate 		sp->fr_savpc = i7;
980Sstevel@tonic-gate 	}
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	(void) setcontext(&uc);
1010Sstevel@tonic-gate }
102