Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/arch/sparc64/gen Avoid using the depreceated __sigr...



details:   https://anonhg.NetBSD.org/src/rev/417d7ccef027
branches:  trunk
changeset: 557767:417d7ccef027
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Jan 17 22:01:15 2004 +0000

description:
Avoid using the depreceated __sigreturn14 for longjmp by adapting
Christian Limpachs arch/m68k implementation using setcontext().

diffstat:

 lib/libc/arch/sparc64/gen/Makefile.inc  |    4 +-
 lib/libc/arch/sparc64/gen/__longjmp14.c |  107 ++++++++++++++++++++++++++++++++
 lib/libc/arch/sparc64/gen/__setjmp14.S  |   49 +++++---------
 3 files changed, 127 insertions(+), 33 deletions(-)

diffs (205 lines):

diff -r 88cefe571090 -r 417d7ccef027 lib/libc/arch/sparc64/gen/Makefile.inc
--- a/lib/libc/arch/sparc64/gen/Makefile.inc    Sat Jan 17 21:52:02 2004 +0000
+++ b/lib/libc/arch/sparc64/gen/Makefile.inc    Sat Jan 17 22:01:15 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.12 2004/01/15 19:43:45 kleink Exp $
+#      $NetBSD: Makefile.inc,v 1.13 2004/01/17 22:01:15 martin Exp $
 
 SRCS+= fabs.S modf.S
 SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
@@ -20,7 +20,7 @@
 SRCS+= bswap16.c bswap32.c bswap64.c
 SRCS+= setjmp.S __setjmp14.S
 SRCS+= _setjmp.S
-SRCS+= sigsetjmp.S __sigsetjmp14.S
+SRCS+= sigsetjmp.S __sigsetjmp14.S __longjmp14.c
 
 SRCS+= makecontext.c resumecontext.c _lwp.c swapcontext.S
 
diff -r 88cefe571090 -r 417d7ccef027 lib/libc/arch/sparc64/gen/__longjmp14.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/sparc64/gen/__longjmp14.c   Sat Jan 17 22:01:15 2004 +0000
@@ -0,0 +1,107 @@
+/*     $NetBSD: __longjmp14.c,v 1.1 2004/01/17 22:01:15 martin 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>
+#include <stdio.h>
+
+#define __LIBC12_SOURCE__
+#include <setjmp.h>
+
+typedef struct {
+       __greg_t        __glob[5];
+} __jmp_buf_regs_t;
+
+void
+__longjmp14(jmp_buf env, int val)
+{
+       struct sigcontext *sc = (void *)env;
+       __jmp_buf_regs_t *r = (void *)&sc[1];
+       ucontext_t uc;
+
+       /* Ensure non-zero SP and FP (sc_g1 misused) */
+       if (sc->sc_sp == 0 || sc->sc_g1 == 0) {
+               printf("oops: longjmp jmp_buf bad, sp = 0x%lx, fp = 0x%lx\n", 
+                    sc->sc_sp, sc->sc_g1);
+               goto err;
+       }
+
+       /* Initialize context with current values */
+       getcontext(&uc);
+
+       /*
+        * 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_SIGMASK | _UC_CPU |
+               (sc->sc_onstack ? _UC_SETSTACK : _UC_CLRSTACK);
+
+       /* Copy signal mask */
+       uc.uc_sigmask = sc->sc_mask;
+
+       /* Fill other registers */
+       uc.uc_mcontext.__gregs[_REG_CCR] = sc->sc_tstate;
+       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_G3] = r->__glob[0];
+       uc.uc_mcontext.__gregs[_REG_G4] = r->__glob[1];
+       uc.uc_mcontext.__gregs[_REG_G5] = r->__glob[2];
+       uc.uc_mcontext.__gregs[_REG_G6] = r->__glob[3];
+       uc.uc_mcontext.__gregs[_REG_G7] = r->__glob[4];
+       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 88cefe571090 -r 417d7ccef027 lib/libc/arch/sparc64/gen/__setjmp14.S
--- a/lib/libc/arch/sparc64/gen/__setjmp14.S    Sat Jan 17 21:52:02 2004 +0000
+++ b/lib/libc/arch/sparc64/gen/__setjmp14.S    Sat Jan 17 22:01:15 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: __setjmp14.S,v 1.4 2003/08/07 16:42:27 agc Exp $       */
+/*     $NetBSD: __setjmp14.S,v 1.5 2004/01/17 22:01:15 martin Exp $    */
 
 /*
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
 #if 0
        .asciz "@(#)setjmp.s    8.1 (Berkeley) 6/4/93"
 #else
-       RCSID("$NetBSD: __setjmp14.S,v 1.4 2003/08/07 16:42:27 agc Exp $")
+       RCSID("$NetBSD: __setjmp14.S,v 1.5 2004/01/17 22:01:15 martin Exp $")
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -59,7 +59,10 @@
 
 #include "SYS.h"
 
-#define STACK_T_SZ
+       .register %g2,#ignore
+       .register %g3,#ignore
+       .register %g6,#ignore
+
 ENTRY(__setjmp14)
        /*
         * We use the part of the sigcontext structure, the sp, pc, and npc fields,
@@ -86,33 +89,17 @@
        stx     %o0, [%o3 + 0x10]       /* sc.sc_pc = return_pc */
        add     %o7, 12, %o0
        stx     %o0, [%o3 + 0x18]       /* sc.sc_npc = return_pc + 4 */
-       stx     %g0, [%o3 + 0x20]       /* sc.sc_psr = (clean psr) */
-       stx     %fp, [%o3 + 0x28]       /* sc.sc_g1 = %fp (misuse, but what the heck) */
-                                       /* sc.sc_o0 = random(), set in __longjmp14 */
+       stx     %g0, [%o3 + 0x20]       /* sc.sc_tstate = (clean ccr) */
+       stx     %g1, [%o3 + 0x28]       /* sc.sc_g1 */
+       stx     %g2, [%o3 + 0x30]       /* sc.sc_o0, set in longjmp, use as %o1 */
+       /* 0x38 */                      /* sc.sc_mask set above already */
+
+       /* save additional registers needed to fill a complete mcontext */
+       stx     %g3, [%o3 + 0x40]
+       stx     %g4, [%o3 + 0x48]
+       stx     %g5, [%o3 + 0x50]
+       stx     %g6, [%o3 + 0x58]
+       stx     %g7, [%o3 + 0x60]
+
        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 __setjmp14.  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, -CC64FSZ, %sp
-       ldx     [%i0 + 0x08], %o2       /* make sure sc->sc_sp, sc->sc_fp nonzero */
-       ldx     [%i0 + 0x28], %o3
-       orcc    %o2, %o3, %g0
-       bz,pn   %xcc, Lbotch
-        movrz  %i1, 1, %i1             /* if (v == 0) v = 1; */
-       stx     %i1, [%i0 + 0x30]       /* 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