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
56812Sraf * Common Development and Distribution License (the "License").
66812Sraf * 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*12061SRoger.Faulkner@Oracle.COM * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
296812Sraf #pragma weak _siglongjmp = siglongjmp
300Sstevel@tonic-gate
316812Sraf #include "lint.h"
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/stack.h>
340Sstevel@tonic-gate #include <sys/frame.h>
350Sstevel@tonic-gate #include <memory.h>
360Sstevel@tonic-gate #include <ucontext.h>
370Sstevel@tonic-gate #include <setjmp.h>
380Sstevel@tonic-gate #include "sigjmp_struct.h"
390Sstevel@tonic-gate #include "libc.h"
400Sstevel@tonic-gate
410Sstevel@tonic-gate void
siglongjmp(sigjmp_buf env,int val)421219Sraf siglongjmp(sigjmp_buf env, int val)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate extern void _fetch_globals(greg_t *);
450Sstevel@tonic-gate ucontext_t uc;
460Sstevel@tonic-gate greg_t *reg = uc.uc_mcontext.gregs;
470Sstevel@tonic-gate volatile sigjmp_struct_t *bp = (sigjmp_struct_t *)env;
480Sstevel@tonic-gate greg_t fp = bp->sjs_fp;
490Sstevel@tonic-gate greg_t i7 = bp->sjs_i7;
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * Create a ucontext_t structure from scratch.
530Sstevel@tonic-gate * We only need to fetch the globals.
540Sstevel@tonic-gate * The outs are assumed to be trashed on return from sigsetjmp().
550Sstevel@tonic-gate * The ins and locals are restored from the resumed register window.
560Sstevel@tonic-gate * The floating point state is unmodified.
570Sstevel@tonic-gate * Everything else is in the sigjmp_struct_t buffer.
580Sstevel@tonic-gate */
590Sstevel@tonic-gate (void) memset(&uc, 0, sizeof (uc));
600Sstevel@tonic-gate uc.uc_flags = UC_STACK | UC_CPU;
610Sstevel@tonic-gate _fetch_globals(®[REG_G1]);
620Sstevel@tonic-gate uc.uc_stack = bp->sjs_stack;
630Sstevel@tonic-gate uc.uc_link = bp->sjs_uclink;
640Sstevel@tonic-gate reg[REG_PC] = bp->sjs_pc;
650Sstevel@tonic-gate reg[REG_nPC] = reg[REG_PC] + 0x4;
660Sstevel@tonic-gate reg[REG_SP] = bp->sjs_sp;
67*12061SRoger.Faulkner@Oracle.COM reg[REG_ASI] = bp->sjs_asi;
68*12061SRoger.Faulkner@Oracle.COM reg[REG_FPRS] = bp->sjs_fprs;
690Sstevel@tonic-gate
700Sstevel@tonic-gate if (bp->sjs_flags & JB_SAVEMASK) {
710Sstevel@tonic-gate uc.uc_flags |= UC_SIGMASK;
720Sstevel@tonic-gate uc.uc_sigmask = bp->sjs_sigmask;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate if (val)
760Sstevel@tonic-gate reg[REG_O0] = (greg_t)val;
770Sstevel@tonic-gate else
780Sstevel@tonic-gate reg[REG_O0] = (greg_t)1;
790Sstevel@tonic-gate
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate * Copy the fp and i7 values into the register window save area.
820Sstevel@tonic-gate * These may have been clobbered between calls to sigsetjmp
830Sstevel@tonic-gate * and siglongjmp. For example, the save area could have been
840Sstevel@tonic-gate * relocated to lower addresses and the original save area
850Sstevel@tonic-gate * given to an alloca() call. Notice that all reads from
860Sstevel@tonic-gate * the sigjmp_struct_t buffer should take place before the
870Sstevel@tonic-gate * following two writes. It is possible that user code may
880Sstevel@tonic-gate * move/copy the sigjmpbuf around, and overlap the original
890Sstevel@tonic-gate * register window save area.
900Sstevel@tonic-gate */
910Sstevel@tonic-gate if (bp->sjs_sp != 0 && (bp->sjs_flags & JB_FRAMEPTR)) {
920Sstevel@tonic-gate struct frame *sp = (struct frame *)(bp->sjs_sp + STACK_BIAS);
930Sstevel@tonic-gate sp->fr_savfp = (struct frame *)fp;
940Sstevel@tonic-gate sp->fr_savpc = i7;
950Sstevel@tonic-gate }
960Sstevel@tonic-gate
970Sstevel@tonic-gate (void) setcontext(&uc);
980Sstevel@tonic-gate }
99