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 #pragma weak _siglongjmp = siglongjmp 31 32 #include "lint.h" 33 #include <sys/types.h> 34 #include <sys/stack.h> 35 #include <sys/frame.h> 36 #include <sys/regset.h> 37 #include <memory.h> 38 #include <ucontext.h> 39 #include <setjmp.h> 40 #include "sigjmp_struct.h" 41 #include "libc.h" 42 43 void 44 siglongjmp(sigjmp_buf env, int val) 45 { 46 extern void _fetch_globals(greg_t *); 47 ucontext_t uc; 48 greg_t *reg = uc.uc_mcontext.gregs; 49 volatile sigjmp_struct_t *bp = (sigjmp_struct_t *)env; 50 greg_t fp = bp->sjs_fp; 51 greg_t i7 = bp->sjs_i7; 52 53 /* 54 * Create a ucontext_t structure from scratch. 55 * We only need to fetch the globals. 56 * The outs are assumed to be trashed on return from sigsetjmp(). 57 * The ins and locals are restored from the resumed register window. 58 * The floating point state is unmodified. 59 * Everything else is in the sigjmp_struct_t buffer. 60 */ 61 (void) memset(&uc, 0, sizeof (uc)); 62 uc.uc_flags = UC_STACK | UC_CPU; 63 _fetch_globals(®[REG_G1]); 64 uc.uc_stack = bp->sjs_stack; 65 uc.uc_link = bp->sjs_uclink; 66 reg[REG_PC] = bp->sjs_pc; 67 reg[REG_nPC] = reg[REG_PC] + 0x4; 68 reg[REG_SP] = bp->sjs_sp; 69 70 if (bp->sjs_flags & JB_SAVEMASK) { 71 uc.uc_flags |= UC_SIGMASK; 72 uc.uc_sigmask = bp->sjs_sigmask; 73 } 74 75 if (val) 76 reg[REG_O0] = (greg_t)val; 77 else 78 reg[REG_O0] = (greg_t)1; 79 80 /* 81 * Copy the fp and i7 values into the register window save area. 82 * These may have been clobbered between calls to sigsetjmp 83 * and siglongjmp. For example, the save area could have been 84 * relocated to lower addresses and the original save area 85 * given to an alloca() call. Notice that all reads from 86 * the sigjmp_struct_t buffer should take place before the 87 * following two writes. It is possible that user code may 88 * move/copy the sigjmpbuf around, and overlap the original 89 * register window save area. 90 */ 91 if (bp->sjs_sp != 0 && (bp->sjs_flags & JB_FRAMEPTR)) { 92 struct frame *sp = (struct frame *)(bp->sjs_sp + STACK_BIAS); 93 sp->fr_savfp = (struct frame *)fp; 94 sp->fr_savpc = i7; 95 } 96 97 (void) setcontext(&uc); 98 } 99