Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/arch/sparc/gen Use setcontext() instead of sigretur...



details:   https://anonhg.NetBSD.org/src/rev/31b103b4c5ba
branches:  trunk
changeset: 559699:31b103b4c5ba
user:      pk <pk%NetBSD.org@localhost>
date:      Mon Mar 22 12:35:04 2004 +0000

description:
Use setcontext() instead of sigreturn() to implement longjmp().

diffstat:

 lib/libc/arch/sparc/gen/Makefile.inc  |    4 +-
 lib/libc/arch/sparc/gen/__longjmp14.c |  100 ++++++++++++++++++++++++++++++++++
 lib/libc/arch/sparc/gen/__setjmp14.S  |   31 +---------
 3 files changed, 104 insertions(+), 31 deletions(-)

diffs (171 lines):

diff -r 576db7f07d9a -r 31b103b4c5ba lib/libc/arch/sparc/gen/Makefile.inc
--- a/lib/libc/arch/sparc/gen/Makefile.inc      Mon Mar 22 12:28:02 2004 +0000
+++ b/lib/libc/arch/sparc/gen/Makefile.inc      Mon Mar 22 12:35:04 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.17 2004/03/04 23:42:38 kleink Exp $
+#      $NetBSD: Makefile.inc,v 1.18 2004/03/22 12:35:04 pk Exp $
 
 SRCS+= fabs.S modf.S
 SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
@@ -16,7 +16,7 @@
 SRCS+= signbitf_ieee754.c signbitd_ieee754.c
 
 
-SRCS+= setjmp.S __setjmp14.S
+SRCS+= setjmp.S __setjmp14.S __longjmp14.c
 SRCS+= _setjmp.S
 SRCS+= sigsetjmp.S __sigsetjmp14.S
 
diff -r 576db7f07d9a -r 31b103b4c5ba lib/libc/arch/sparc/gen/__longjmp14.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/sparc/gen/__longjmp14.c     Mon Mar 22 12:35:04 2004 +0000
@@ -0,0 +1,100 @@
+/*     $NetBSD: __longjmp14.c,v 1.1 2004/03/22 12:35:04 pk 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>
+
+/*
+ * Use setcontext to reload the stack pointer, program counter <pc,npc>, and
+ * set the return value in %o0.  The %i and %l registers will be reloaded
+ * from the place to which %sp points.
+ */
+void
+__longjmp14(jmp_buf env, int val)
+{
+       struct sigcontext *sc = (void *)env;
+       ucontext_t uc;
+
+       /* Ensure non-zero SP */
+       if (sc->sc_sp == 0)
+               goto err;
+
+       /* Initialise the fields we're going to use */
+       uc.uc_link = 0;
+
+       /*
+        * Set _UC_SIGMASK, _UC_CPU. No FPU data saved, so we can't restore
+        * that. Set _UC_{SET,CLR}STACK according to SS_ONSTACK
+        */
+       uc.uc_flags = _UC_CPU | (sc->sc_onstack ? _UC_SETSTACK : _UC_CLRSTACK);
+
+       /*
+        * Set the signal mask - this is a weak symbol, so don't use
+        * _UC_SIGMASK in the mcontext, libpthread might override sigprocmask.
+        */
+       sigprocmask(SIG_SETMASK, &sc->sc_mask, NULL);
+
+       /* Fill other registers */
+       uc.uc_mcontext.__gregs[_REG_PSR] = sc->sc_psr;
+       uc.uc_mcontext.__gregs[_REG_PC] = sc->sc_pc;
+       uc.uc_mcontext.__gregs[_REG_nPC] = sc->sc_npc;
+       uc.uc_mcontext.__gregs[_REG_G1] = sc->sc_g1;
+       uc.uc_mcontext.__gregs[_REG_G2] = sc->sc_o0;
+       uc.uc_mcontext.__gregs[_REG_O6] = sc->sc_sp;
+
+       /* Make return value non-zero */
+       if (val == 0)
+               val = 1;
+
+       /* Save return value in context */
+       uc.uc_mcontext.__gregs[_REG_O0] = val;
+
+       setcontext(&uc);
+
+err:
+       longjmperror();
+       abort();
+       /* NOTREACHED */
+}
diff -r 576db7f07d9a -r 31b103b4c5ba lib/libc/arch/sparc/gen/__setjmp14.S
--- a/lib/libc/arch/sparc/gen/__setjmp14.S      Mon Mar 22 12:28:02 2004 +0000
+++ b/lib/libc/arch/sparc/gen/__setjmp14.S      Mon Mar 22 12:35:04 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: __setjmp14.S,v 1.2 2003/08/07 16:42:23 agc Exp $       */
+/*     $NetBSD: __setjmp14.S,v 1.3 2004/03/22 12:35:04 pk Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
 #if 0
        .asciz "@(#)setjmp.s    8.1 (Berkeley) 6/4/93"
 #else
-       RCSID("$NetBSD: __setjmp14.S,v 1.2 2003/08/07 16:42:23 agc Exp $")
+       RCSID("$NetBSD: __setjmp14.S,v 1.3 2004/03/22 12:35:04 pk Exp $")
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -87,30 +87,3 @@
        retl                    /* return 0 */
         clr    %o0
 
-/*
- * All we need to do here is force sigreturn to load a new stack pointer,
- * new <pc,npc>, and appropriate %o0 return value from the sigcontext built
- * in setjmp.  The %i and %l registers will be reloaded from the place to
- * which %sp points, due to sigreturn() semantics (sigreturn does not modify
- * the window pointer in the psr, hence it must force all windows to reload).
- */
-ENTRY(__longjmp14)
-       save    %sp, -96, %sp
-       ld      [%i0 + 8], %o2  /* make sure sc->sc_sp, sc->sc_fp nonzero */
-       ld      [%i0 + 24], %o3
-       orcc    %o2, %o3, %g0
-       bz      Lbotch
-        tst    %i1             /* if (v == 0) v = 1; */
-       bz,a    1f
-        mov    1, %i1
-1:
-       st      %i1, [%i0 + 28] /* sc.sc_o0 = v; */
-       mov     SYS___sigreturn14, %g1
-       mov     %i0, %o0
-       t       ST_SYSCALL      /* sigreturn(scp); */
-
-Lbotch:
-       /* oops, caller botched it */
-       call    _C_LABEL(longjmperror)
-        nop
-       unimp   0



Home | Main Index | Thread Index | Old Index