kaniini / libucontext

ucontext implementation featuring glibc-compatible ABI
Other
106 stars 41 forks source link

arm: Add patch fixing return values of get/set/swapcontext #56

Closed VolkerChristian closed 3 months ago

VolkerChristian commented 1 year ago

Finally i dived deeper into the code for ARM and refreshed my assembly knowledge and found a fix for #55 ("Aieie, swapcontext() failed ...").

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 when get/set/swapcontext return. Thus set r0 to zero and store it in the context. This context is retrieved later before get/set/swapcontext return and thus it 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.

Best regards Volker

kaniini commented 3 months ago

Merged, thanks!