This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 67c7ae63ab78bee0e08344d6f822a22d2ea577da Author: chenxiaoyi <[email protected]> AuthorDate: Mon Nov 10 15:29:34 2025 +0800 libc/machine/sim: Return 1 from setjmp() when longjmp() is called with 0. The C standard requires setjmp() to return 1 when longjmp() is called with a value of 0. The x86 and x86_64 simulator implementations returned the value unchanged, so setjmp() returned 0 and the caller mistook the longjmp() for the initial call. Replace a 0 value with 1. Signed-off-by: chenxiaoyi <[email protected]> Signed-off-by: ganjing <[email protected]> --- libs/libc/machine/sim/arch_setjmp_x86.asm | 4 ++++ libs/libc/machine/sim/arch_setjmp_x86_64.asm | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/libs/libc/machine/sim/arch_setjmp_x86.asm b/libs/libc/machine/sim/arch_setjmp_x86.asm index 70c2730833d..bfa6343565f 100644 --- a/libs/libc/machine/sim/arch_setjmp_x86.asm +++ b/libs/libc/machine/sim/arch_setjmp_x86.asm @@ -58,9 +58,13 @@ setjmp: longjmp: mov ecx, dword ptr [esp+4] ; jmpbuf in ecx. mov eax, dword ptr [esp+8] ; Second argument is return value + test eax, eax + jnz @F + inc eax ; Save the return address now +@@: mov edx, dword ptr [ecx+14h] ; Restore registers diff --git a/libs/libc/machine/sim/arch_setjmp_x86_64.asm b/libs/libc/machine/sim/arch_setjmp_x86_64.asm index 2ef7f529fd4..4bd1fa54d10 100644 --- a/libs/libc/machine/sim/arch_setjmp_x86_64.asm +++ b/libs/libc/machine/sim/arch_setjmp_x86_64.asm @@ -66,9 +66,13 @@ longjmp: ; Setup return value mov rax, rdx + test rax, rax + jnz @F + inc rax ; Restore registers +@@: mov rbx, [rcx] mov rsp, [rcx+8] mov rbp, [rcx+10h]
