xref: /illumos-gate/usr/src/lib/libc/sparc/gen/siglongjmp.c (revision e8031f0a8ed0e45c6d8847c5e09424e66fd34a4b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*e8031f0aSraf 
237c478bd9Sstevel@tonic-gate /*
24*e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
317c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #pragma weak siglongjmp = _siglongjmp
357c478bd9Sstevel@tonic-gate 
36*e8031f0aSraf #include "synonyms.h"
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <sys/stack.h>
397c478bd9Sstevel@tonic-gate #include <sys/frame.h>
407c478bd9Sstevel@tonic-gate #include <memory.h>
417c478bd9Sstevel@tonic-gate #include <ucontext.h>
427c478bd9Sstevel@tonic-gate #include <setjmp.h>
437c478bd9Sstevel@tonic-gate #include "sigjmp_struct.h"
447c478bd9Sstevel@tonic-gate #include "libc.h"
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate void
47*e8031f0aSraf siglongjmp(sigjmp_buf env, int val)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate 	extern void _fetch_globals(greg_t *);
507c478bd9Sstevel@tonic-gate 	ucontext_t uc;
517c478bd9Sstevel@tonic-gate 	greg_t *reg = uc.uc_mcontext.gregs;
527c478bd9Sstevel@tonic-gate 	volatile sigjmp_struct_t *bp = (sigjmp_struct_t *)env;
537c478bd9Sstevel@tonic-gate 	greg_t fp = bp->sjs_fp;
547c478bd9Sstevel@tonic-gate 	greg_t i7 = bp->sjs_i7;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 	/*
577c478bd9Sstevel@tonic-gate 	 * Create a ucontext_t structure from scratch.
587c478bd9Sstevel@tonic-gate 	 * We only need to fetch the globals.
597c478bd9Sstevel@tonic-gate 	 * The outs are assumed to be trashed on return from sigsetjmp().
607c478bd9Sstevel@tonic-gate 	 * The ins and locals are restored from the resumed register window.
617c478bd9Sstevel@tonic-gate 	 * The floating point state is unmodified.
627c478bd9Sstevel@tonic-gate 	 * Everything else is in the sigjmp_struct_t buffer.
637c478bd9Sstevel@tonic-gate 	 */
647c478bd9Sstevel@tonic-gate 	(void) memset(&uc, 0, sizeof (uc));
657c478bd9Sstevel@tonic-gate 	uc.uc_flags = UC_STACK | UC_CPU;
667c478bd9Sstevel@tonic-gate 	_fetch_globals(&reg[REG_G1]);
677c478bd9Sstevel@tonic-gate 	uc.uc_stack = bp->sjs_stack;
687c478bd9Sstevel@tonic-gate 	uc.uc_link = bp->sjs_uclink;
697c478bd9Sstevel@tonic-gate 	reg[REG_PC] = bp->sjs_pc;
707c478bd9Sstevel@tonic-gate 	reg[REG_nPC] = reg[REG_PC] + 0x4;
717c478bd9Sstevel@tonic-gate 	reg[REG_SP] = bp->sjs_sp;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	if (bp->sjs_flags & JB_SAVEMASK) {
747c478bd9Sstevel@tonic-gate 		uc.uc_flags |= UC_SIGMASK;
757c478bd9Sstevel@tonic-gate 		uc.uc_sigmask = bp->sjs_sigmask;
767c478bd9Sstevel@tonic-gate 	}
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	if (val)
797c478bd9Sstevel@tonic-gate 		reg[REG_O0] = (greg_t)val;
807c478bd9Sstevel@tonic-gate 	else
817c478bd9Sstevel@tonic-gate 		reg[REG_O0] = (greg_t)1;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	/*
847c478bd9Sstevel@tonic-gate 	 * Copy the fp and i7 values into the register window save area.
857c478bd9Sstevel@tonic-gate 	 * These may have been clobbered between calls to sigsetjmp
867c478bd9Sstevel@tonic-gate 	 * and siglongjmp.  For example, the save area could have been
877c478bd9Sstevel@tonic-gate 	 * relocated to lower addresses and the original save area
887c478bd9Sstevel@tonic-gate 	 * given to an alloca() call.  Notice that all reads from
897c478bd9Sstevel@tonic-gate 	 * the sigjmp_struct_t buffer should take place before the
907c478bd9Sstevel@tonic-gate 	 * following two writes.  It is possible that user code may
917c478bd9Sstevel@tonic-gate 	 * move/copy the sigjmpbuf around, and overlap the original
927c478bd9Sstevel@tonic-gate 	 * register window save area.
937c478bd9Sstevel@tonic-gate 	 */
947c478bd9Sstevel@tonic-gate 	if (bp->sjs_sp != 0 && (bp->sjs_flags & JB_FRAMEPTR)) {
957c478bd9Sstevel@tonic-gate 		struct frame *sp = (struct frame *)(bp->sjs_sp + STACK_BIAS);
967c478bd9Sstevel@tonic-gate 		sp->fr_savfp = (struct frame *)fp;
977c478bd9Sstevel@tonic-gate 		sp->fr_savpc = i7;
987c478bd9Sstevel@tonic-gate 	}
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	(void) setcontext(&uc);
1017c478bd9Sstevel@tonic-gate }
102