setjmp: fix setjmp returns 0 when calling longjmp with 0 as the second argument

Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
This commit is contained in:
Gao Jiawei 2024-07-23 18:05:00 +08:00 committed by Xiang Xiao
parent 036a0674db
commit 89d6abf3df
3 changed files with 23 additions and 4 deletions

View File

@ -170,7 +170,21 @@ longjmp:
vmsr fpscr, r2 /* Restore the FPSCR */
#endif /* CONFIG_ARCH_FPU */
mov r0, r1 /* return val */
/* Check and substitute the given return value to 1 if it's 0 */
movs r0, r1
#ifdef CONFIG_ARCH_ARMV6M
/* ARMv6-M only supports branching with condition
* So we fall back to not use IT blocks in that case
*/
bne 1f
movs r0, #1
1:
#else
it eq
moveq r0, #1
#endif
bx lr
.size longjmp, .-longjmp

View File

@ -85,9 +85,11 @@ SYMBOL(setjmp):
SYMBOL(longjmp):
movl 4(%esp), %ecx /* jmpbuf in %ecx. */
movl 8(%esp), %eax /* Second argument is return value. */
testl %eax, %eax
jnz 1f
incl %eax
/* Save the return address now. */
1:
movl (JB_PC)(%ecx), %edx
/* Restore registers. */

View File

@ -130,9 +130,12 @@ SYMBOL(longjmp):
/* Setup return value */
movl %esi,%eax
testl %eax,%eax
jnz 1f
incl %eax
/* Restore registers */
1:
movq JB_RBX(REGS),%rbx /* Load 1: rbx */
movq JB_RSP(REGS),%rsp /* Load 2: rsp */
movq JB_RBP(REGS),%rbp /* Load 3: rdi */