split __longjmp14() into a separate file and make it use setcontext()
instead of __sigreturn14(). translated from MIPS.
This commit is contained in:
parent
61b506f0a2
commit
1e1499c776
124
lib/libc/arch/hppa/gen/__longjmp14.c
Normal file
124
lib/libc/arch/hppa/gen/__longjmp14.c
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/* $NetBSD: __longjmp14.c,v 1.1 2004/07/18 22:38:33 chs Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Christian Limpach.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the NetBSD
|
||||||
|
* Foundation, Inc. and its contributors.
|
||||||
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <ucontext.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define __LIBC12_SOURCE__
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
ssize_t _sys_write(int, void *, size_t);
|
||||||
|
|
||||||
|
void
|
||||||
|
__longjmp14(jmp_buf env, int val)
|
||||||
|
{
|
||||||
|
ucontext_t uc;
|
||||||
|
struct sigcontext *sc = (void *)env;
|
||||||
|
register_t *regs = (void *)(sc + 1);
|
||||||
|
register register_t dp __asm__("r27");
|
||||||
|
|
||||||
|
/* Ensure non-zero SP */
|
||||||
|
if (sc->sc_sp == 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Make return value non-zero */
|
||||||
|
if (val == 0)
|
||||||
|
val = 1;
|
||||||
|
|
||||||
|
/* Copy callee-saved regs */
|
||||||
|
regs -= 3;
|
||||||
|
uc.uc_mcontext.__gregs[3] = regs[3];
|
||||||
|
uc.uc_mcontext.__gregs[4] = regs[4];
|
||||||
|
uc.uc_mcontext.__gregs[5] = regs[5];
|
||||||
|
uc.uc_mcontext.__gregs[6] = regs[6];
|
||||||
|
uc.uc_mcontext.__gregs[7] = regs[7];
|
||||||
|
uc.uc_mcontext.__gregs[8] = regs[8];
|
||||||
|
uc.uc_mcontext.__gregs[9] = regs[9];
|
||||||
|
uc.uc_mcontext.__gregs[10] = regs[10];
|
||||||
|
uc.uc_mcontext.__gregs[11] = regs[11];
|
||||||
|
uc.uc_mcontext.__gregs[12] = regs[12];
|
||||||
|
uc.uc_mcontext.__gregs[13] = regs[13];
|
||||||
|
uc.uc_mcontext.__gregs[14] = regs[14];
|
||||||
|
uc.uc_mcontext.__gregs[15] = regs[15];
|
||||||
|
uc.uc_mcontext.__gregs[16] = regs[16];
|
||||||
|
uc.uc_mcontext.__gregs[17] = regs[17];
|
||||||
|
uc.uc_mcontext.__gregs[18] = regs[18];
|
||||||
|
|
||||||
|
/* Preserve the current value of DP */
|
||||||
|
uc.uc_mcontext.__gregs[27] = dp;
|
||||||
|
|
||||||
|
/* Set the desired return value. */
|
||||||
|
uc.uc_mcontext.__gregs[_REG_RET0] = val;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set _UC_{SET,CLR}STACK according to SS_ONSTACK.
|
||||||
|
*
|
||||||
|
* Restore the signal mask with sigprocmask() instead of _UC_SIGMASK,
|
||||||
|
* since libpthread may want to interpose on signal handling.
|
||||||
|
*/
|
||||||
|
uc.uc_flags = _UC_CPU | (sc->sc_onstack ? _UC_SETSTACK : _UC_CLRSTACK);
|
||||||
|
|
||||||
|
sigprocmask(SIG_SETMASK, &sc->sc_mask, NULL);
|
||||||
|
|
||||||
|
/* Clear uc_link */
|
||||||
|
uc.uc_link = 0;
|
||||||
|
|
||||||
|
/* Copy signal mask */
|
||||||
|
uc.uc_sigmask = sc->sc_mask;
|
||||||
|
|
||||||
|
/* Copy special regs */
|
||||||
|
uc.uc_mcontext.__gregs[_REG_PSW] = sc->sc_ps;
|
||||||
|
uc.uc_mcontext.__gregs[_REG_SP] = sc->sc_sp;
|
||||||
|
uc.uc_mcontext.__gregs[_REG_PCSQH] = sc->sc_pcsqh;
|
||||||
|
uc.uc_mcontext.__gregs[_REG_PCOQH] = sc->sc_pcoqh;
|
||||||
|
uc.uc_mcontext.__gregs[_REG_PCSQT] = sc->sc_pcsqt;
|
||||||
|
uc.uc_mcontext.__gregs[_REG_PCOQT] = sc->sc_pcoqt;
|
||||||
|
|
||||||
|
setcontext(&uc);
|
||||||
|
err:
|
||||||
|
longjmperror();
|
||||||
|
abort();
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: __setjmp14.S,v 1.3 2003/10/06 05:30:21 matt Exp $ */
|
/* $NetBSD: __setjmp14.S,v 1.4 2004/07/18 22:38:33 chs Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||||
@ -44,7 +44,7 @@
|
|||||||
#include <machine/psl.h>
|
#include <machine/psl.h>
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
RCSID("$NetBSD: __setjmp14.S,v 1.3 2003/10/06 05:30:21 matt Exp $")
|
RCSID("$NetBSD: __setjmp14.S,v 1.4 2004/07/18 22:38:33 chs Exp $")
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -135,41 +135,4 @@ ENTRY(__setjmp14,0)
|
|||||||
copy %r0, %ret0
|
copy %r0, %ret0
|
||||||
EXIT(__setjmp14)
|
EXIT(__setjmp14)
|
||||||
|
|
||||||
ENTRY(__longjmp14,0)
|
|
||||||
/* Finish our stack frame. */
|
|
||||||
stw %rp, HPPA_FRAME_CRP(%sp)
|
|
||||||
stw %arg0, HPPA_FRAME_ARG(0)(%sp)
|
|
||||||
|
|
||||||
ldw 8(%arg0), %r1 ; ensure non-zero SP
|
|
||||||
combt,=,n %r0, %r1, botch ; oops!
|
|
||||||
add,<> %r0, %arg1, %ret0 ; ensure return value non-zero
|
|
||||||
ldi 1, %ret0
|
|
||||||
|
|
||||||
/* restore callee-saved registers */
|
|
||||||
ldo 56(%arg0), %r1
|
|
||||||
ldwm 4(%r1), %r3
|
|
||||||
ldwm 4(%r1), %r4
|
|
||||||
ldwm 4(%r1), %r5
|
|
||||||
ldwm 4(%r1), %r6
|
|
||||||
ldwm 4(%r1), %r7
|
|
||||||
ldwm 4(%r1), %r8
|
|
||||||
ldwm 4(%r1), %r9
|
|
||||||
ldwm 4(%r1), %r10
|
|
||||||
ldwm 4(%r1), %r11
|
|
||||||
ldwm 4(%r1), %r12
|
|
||||||
ldwm 4(%r1), %r13
|
|
||||||
ldwm 4(%r1), %r14
|
|
||||||
ldwm 4(%r1), %r15
|
|
||||||
ldwm 4(%r1), %r16
|
|
||||||
ldwm 4(%r1), %r17
|
|
||||||
ldwm 4(%r1), %r18
|
|
||||||
|
|
||||||
/* let sigreturn finish for us */
|
|
||||||
bl __sigreturn14, %rp
|
|
||||||
nop
|
|
||||||
botch:
|
|
||||||
bl longjmperror, %rp
|
|
||||||
nop
|
|
||||||
EXIT(__longjmp14)
|
|
||||||
|
|
||||||
.end
|
.end
|
||||||
|
Loading…
Reference in New Issue
Block a user