libucontext: Add patch fixing return values of get/set/swapcontext

The arm ABI defines that the value in register r0 is used as the return
value of a function. To indicate success for get/set/swapcontext (return
value of 0) the register r0 must contain zero at the end of the function
call. Thus set r0 to zero and store it in the context. This context
is restored later and indicate successful execution, because r0 is 0.

The order registers are stored has changed so that only one additional
instruction (mov r0, #0) needs to be added to fix the return value
bug for get/set/swapcontext.

Signed-off-by: Volker Christian <me@vchrist.at>
master
Volker Christian 2023-08-30 22:31:58 +02:00 committed by Ariadne Conill
parent 076e69c9c1
commit 9e5de65076
1 changed files with 8 additions and 6 deletions

View File

@ -16,12 +16,6 @@ ALIAS(swapcontext, libucontext_swapcontext)
ALIAS(__swapcontext, libucontext_swapcontext) ALIAS(__swapcontext, libucontext_swapcontext)
FUNC(libucontext_swapcontext) FUNC(libucontext_swapcontext)
/* copy all of the current registers into the ucontext structure */
add r2, r0, #REG_OFFSET(0)
stmia r2, {r0-r12}
str r13, [r0,#REG_OFFSET(13)]
str r14, [r0,#REG_OFFSET(15)]
#ifndef FORCE_SOFT_FLOAT #ifndef FORCE_SOFT_FLOAT
#ifndef FORCE_HARD_FLOAT #ifndef FORCE_HARD_FLOAT
/* test for vfp magic number, copy to other ucontext */ /* test for vfp magic number, copy to other ucontext */
@ -42,6 +36,14 @@ FUNC(libucontext_swapcontext)
1: 1:
#endif #endif
/* copy all of the current registers into the ucontext structure */
str r13, [r0,#REG_OFFSET(13)]
str r14, [r0,#REG_OFFSET(15)]
add r2, r0, #REG_OFFSET(0)
/* copy r0 with value 0 to indicate success (return value 0) */
mov r0, #0
stmia r2, {r0-r12}
/* load new registers from the second ucontext structure */ /* load new registers from the second ucontext structure */
add r14, r1, #REG_OFFSET(0) add r14, r1, #REG_OFFSET(0)
ldmia r14, {r0-r12} ldmia r14, {r0-r12}