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