Skip to contentSkip to conversation

arm: adjust val to 32-bit in aarch64 longjmp()

PATCH New Vincent Stehlé 1 participant 1 message Nov 26 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: adjust val to 32-bit in aarch64 longjmp()

The second longjmp() argument, val, is declared as a 32-bit int, but the AArch64 implementation is using it as 64-bit.

The calling convention [1] does not specify the value of the most significant bits of a 64-bit register containing an int, and they should be ignored.

If a zero val argument is passed in x1 to longjmp() with non-zero high-order bits, it will be erroneously treated as non-zero, and setjmp() will effectively return zero instead of the expected one.

Convert adds operands to 32-bit to fix this, and also the operands of the following csinc for consistency.

---
I tested manually with gdb on Qemu with the lib_test_longjmp unit test.

Also, I verified on Qemu that the following still run fine:

ut lib lib_test_longjmp
ut lib lib_initjmp
ut lib uthread
ut lib uthread_mutex
setenv efi_selftest start image exit; bootefi selftest setenv efi_selftest start image return; bootefi selftest

---
 arch/arm/lib/setjmp_aarch64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/lib/setjmp_aarch64.S +2 -2
index 01193ccc426..d668cc102f1 100644
@@ -34,8 +34,8 @@ ENTRY(longjmp)
 	ldr  x2, [x0,#96]
 	mov  sp, x2
 	/* Move the return value in place, but return 1 if passed 0. */
-	adds x0, xzr, x1
-	csinc x0, x0, xzr, ne
+	adds w0, wzr, w1
+	csinc w0, w0, wzr, ne
 	ret
 ENDPROC(longjmp)
 .popsection

---
base-commit: 9d67454e920b3908529c9fc642a8c911db040896
change-id: 20261126-longjmp-db9ec62068eb

Best regards,

Signature · 1 line
Vincent Stehlé <[email protected]>