xref: /titanic_41/usr/src/lib/libc/sparcv9/gen/siglongjmp.c (revision 602ca9ea8f9ce0933f0944601cc5d230e91a950d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 /*	Copyright (c) 1988 AT&T	*/
31 /*	  All Rights Reserved  	*/
32 
33 
34 #pragma weak siglongjmp = _siglongjmp
35 
36 #include "synonyms.h"
37 #include <sys/types.h>
38 #include <sys/stack.h>
39 #include <sys/frame.h>
40 #include <memory.h>
41 #include <ucontext.h>
42 #include <setjmp.h>
43 #include "sigjmp_struct.h"
44 #include "libc.h"
45 
46 void
47 siglongjmp(sigjmp_buf env, int val)
48 {
49 	extern void _fetch_globals(greg_t *);
50 	ucontext_t uc;
51 	greg_t *reg = uc.uc_mcontext.gregs;
52 	volatile sigjmp_struct_t *bp = (sigjmp_struct_t *)env;
53 	greg_t fp = bp->sjs_fp;
54 	greg_t i7 = bp->sjs_i7;
55 
56 	/*
57 	 * Create a ucontext_t structure from scratch.
58 	 * We only need to fetch the globals.
59 	 * The outs are assumed to be trashed on return from sigsetjmp().
60 	 * The ins and locals are restored from the resumed register window.
61 	 * The floating point state is unmodified.
62 	 * Everything else is in the sigjmp_struct_t buffer.
63 	 */
64 	(void) memset(&uc, 0, sizeof (uc));
65 	uc.uc_flags = UC_STACK | UC_CPU;
66 	_fetch_globals(&reg[REG_G1]);
67 	uc.uc_stack = bp->sjs_stack;
68 	uc.uc_link = bp->sjs_uclink;
69 	reg[REG_PC] = bp->sjs_pc;
70 	reg[REG_nPC] = reg[REG_PC] + 0x4;
71 	reg[REG_SP] = bp->sjs_sp;
72 
73 	if (bp->sjs_flags & JB_SAVEMASK) {
74 		uc.uc_flags |= UC_SIGMASK;
75 		uc.uc_sigmask = bp->sjs_sigmask;
76 	}
77 
78 	if (val)
79 		reg[REG_O0] = (greg_t)val;
80 	else
81 		reg[REG_O0] = (greg_t)1;
82 
83 	/*
84 	 * Copy the fp and i7 values into the register window save area.
85 	 * These may have been clobbered between calls to sigsetjmp
86 	 * and siglongjmp.  For example, the save area could have been
87 	 * relocated to lower addresses and the original save area
88 	 * given to an alloca() call.  Notice that all reads from
89 	 * the sigjmp_struct_t buffer should take place before the
90 	 * following two writes.  It is possible that user code may
91 	 * move/copy the sigjmpbuf around, and overlap the original
92 	 * register window save area.
93 	 */
94 	if (bp->sjs_sp != 0 && (bp->sjs_flags & JB_FRAMEPTR)) {
95 		struct frame *sp = (struct frame *)(bp->sjs_sp + STACK_BIAS);
96 		sp->fr_savfp = (struct frame *)fp;
97 		sp->fr_savpc = i7;
98 	}
99 
100 	(void) setcontext(&uc);
101 }
102