Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jan 2023 01:47:13 GMT
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a82b1ca60381 - stable/13 - libc: Fix longjmp/_longjmp(buf, 0) for MIPS
Message-ID:  <202301310147.30V1lDEX058688@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=a82b1ca6038152eb5740552507534842acebede2

commit a82b1ca6038152eb5740552507534842acebede2
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2023-01-30 23:55:03 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-01-31 01:46:18 +0000

    libc: Fix longjmp/_longjmp(buf, 0) for MIPS
    
    Like AArch64 and RISC-V in the past, MIPS fails to handle this special
    case, and will cause the corresponding setjmp/_setjmp to return 0 rather
    than 1. Fix this so the newly-added regression tests pass.
    
    This is a direct commit to stable/13 as mips no longer exists in main.
    
    Reviewed by:    arichardson, jhb
    Differential Revision:  https://reviews.freebsd.org/D29363
---
 lib/libc/mips/gen/_setjmp.S | 3 +++
 lib/libc/mips/gen/setjmp.S  | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/libc/mips/gen/_setjmp.S b/lib/libc/mips/gen/_setjmp.S
index 10c4cda5e0c1..ba9b89f208c4 100644
--- a/lib/libc/mips/gen/_setjmp.S
+++ b/lib/libc/mips/gen/_setjmp.S
@@ -183,7 +183,10 @@ LEAF(_longjmp)
 #endif	/* ! __mips_soft_float */
 
 	REG_EPILOGUE
+	bne	a1, zero, 1f
 	move	v0, a1			# get return value in 1st arg
+	REG_LI	v0, 1			# return 1 if arg is 0
+1:
 	j	ra
 	nop
 
diff --git a/lib/libc/mips/gen/setjmp.S b/lib/libc/mips/gen/setjmp.S
index 3ef6878bb608..6b8f196735c4 100644
--- a/lib/libc/mips/gen/setjmp.S
+++ b/lib/libc/mips/gen/setjmp.S
@@ -220,7 +220,10 @@ NESTED(longjmp, LONGJMP_FRAME_SIZE, ra)
 #endif
 #endif	/* ! __mips_soft_float */
 
-	move	v0, a1
+	move	v0, a1			# get return value in 1st arg
+	bne	a1, zero, 1f		# NB: no .set noreorder
+	REG_LI	v0, 1			# return 1 if arg is 0
+1:
 	j	ra
 	nop
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202301310147.30V1lDEX058688>