Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/arch/mips/sys For mips n32/n64 explicitly save the ...



details:   https://anonhg.NetBSD.org/src/rev/a6baa5f1a347
branches:  trunk
changeset: 951551:a6baa5f1a347
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Feb 06 06:58:59 2021 +0000

description:
For mips n32/n64 explicitly save the GP reg on the stack, and
restore it _after_ the call to __errno().  Fixes sending the
__errno() call off to nowhereland when this code is included
in another library (eg __posix_cerror() in libposix).  Failure
picked up by the ATF lib/libposix/posix1/t_rename test.

diffstat:

 lib/libc/arch/mips/sys/cerror.S |  19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r dc501d8ef091 -r a6baa5f1a347 lib/libc/arch/mips/sys/cerror.S
--- a/lib/libc/arch/mips/sys/cerror.S   Sat Feb 06 06:15:13 2021 +0000
+++ b/lib/libc/arch/mips/sys/cerror.S   Sat Feb 06 06:58:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cerror.S,v 1.19 2013/09/12 15:36:15 joerg Exp $        */
+/*     $NetBSD: cerror.S,v 1.20 2021/02/06 06:58:59 simonb Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -38,7 +38,7 @@
 #if 0
        RCSID("from: @(#)cerror.s       8.1 (Berkeley) 6/16/93")
 #else
-       RCSID("$NetBSD: cerror.S,v 1.19 2013/09/12 15:36:15 joerg Exp $")
+       RCSID("$NetBSD: cerror.S,v 1.20 2021/02/06 06:58:59 simonb Exp $")
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -50,24 +50,33 @@
        .globl  _C_LABEL(__errno)
 NESTED_NOPROFILE(__cerror, CALLFRAME_SIZ, ra)
        .mask   0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
-       PIC_PROLOGUE(__cerror)
+       PIC_PROLOGUE(__cerror)          # saves caller gp in t3 (n32/n64)
        PTR_SUBU        sp, CALLFRAME_SIZ
        PTR_S           ra, CALLFRAME_RA(sp)
        INT_S           v0, CALLFRAME_S0(sp)    # save errno value
+#if defined(__mips_n32) || defined(__mips_n64)
+       PTR_S           t3, CALLFRAME_GP(sp)    # save caller gp (in t3)
+#endif
 
        SAVE_GP(CALLFRAME_GP)
 
        PTR_LA          t9, _C_LABEL(__errno)   # locate address of errno
-       RESTORE_GP64                            # restore GP (from t3)
+
        jalr            t9                      # __errno()
 
+#if defined(__mips_n32) || defined(__mips_n64)
+       PTR_L           gp, CALLFRAME_GP(sp)    # restore caller gp
+#endif
        INT_L           t0, CALLFRAME_S0(sp)
        PTR_L           ra, CALLFRAME_RA(sp)
        INT_S           t0, 0(v0)               # update errno value
        PTR_ADDU        sp, CALLFRAME_SIZ
        li              v0, -1
        li              v1, -1
-       j               ra                      # GP has been restored.
+
+       # Note we don't use PIC_RETURN() here as the GP is stored
+       # on the stack and not in the t3 reg (for the n32/n64 case).
+       j               ra
 END(__cerror)
 #else          
        .globl  _C_LABEL(errno)



Home | Main Index | Thread Index | Old Index