Use save instruction to set up a local stack frame.

This fixes a segmentation fault caused by bash 4.3 on sparc64
kernels with 32-bit userland, bash uses _setjmp/_longjmp heavyly
via sigsetjmp/siglongjmp since 4.3.

For 32-bit compat library which is compiled with -mcpu=ultrasparc
option (and define __sparc_v9__), use a similar code to 64-bit
library.
This commit is contained in:
nakayama 2014-07-12 19:11:57 +00:00
parent ea84cea2f2
commit 847b247653
1 changed files with 33 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: _setjmp.S,v 1.9 2011/04/30 23:41:12 martin Exp $ */
/* $NetBSD: _setjmp.S,v 1.10 2014/07/12 19:11:57 nakayama Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#include <machine/trap.h>
#if defined(LIBC_SCCS) && !defined(lint)
RCSID("$NetBSD: _setjmp.S,v 1.9 2011/04/30 23:41:12 martin Exp $")
RCSID("$NetBSD: _setjmp.S,v 1.10 2014/07/12 19:11:57 nakayama Exp $")
#endif /* LIBC_SCCS and not lint */
/*
@ -59,26 +59,46 @@ ENTRY(_setjmp)
clr %o0 ! return 0
ENTRY(_longjmp)
sub %sp, 64, %sp ! set up a local stack frame
tst %o1 ! compute v ? v : 1
#ifdef __sparc_v9__
save %sp, -CCFSZ, %sp
flushw
/*
* We restore the saved stack pointer to %fp, then issue
* a `restore' instruction which will reload the register
* window from the stack.
*/
ld [%i0 + 16], %g3
ld [%i0 + 24], %g2
ld [%i0 + 48], %g4
ld [%i0 + 52], %g7
ld [%i0 + 4], %i7 /* restore return pc */
ld [%i0 + 0], %fp /* and stack pointer */
mov 1, %i0
movrnz %i1, %i1, %i0 ! compute v ? v : 1
ret
restore
#else
save %sp, -64, %sp ! set up a local stack frame
tst %i1 ! compute v ? v : 1
be,a 0f
mov 1, %o1
mov 1, %i1
0:
t ST_FLUSHWIN ! flush register windows out to the stack
/* restore globals */
ld [%o0 + 16], %g3
ld [%o0 + 24], %g2
ld [%o0 + 48], %g4
ld [%o0 + 52], %g7
ld [%i0 + 16], %g3
ld [%i0 + 24], %g2
ld [%i0 + 48], %g4
ld [%i0 + 52], %g7
/*
* We restore the saved stack pointer to %fp, then issue
* a `restore' instruction which will reload the register
* window from the stack.
*/
ld [%o0+4], %o7 /* restore return pc */
ld [%o0+0], %fp /* and stack pointer */
ld [%i0+4], %i7 /* restore return pc */
ld [%i0+0], %fp /* and stack pointer */
retl ! success, return %o1
restore %o1, 0, %o0
ret ! success, return %i1
restore %i1, 0, %o0
#endif