From: Andrei Tatar Date: Wed, 10 May 2023 12:48:22 +0000 (+0300) Subject: patches: Re-add `UnwindRegistersSave.S` RIP patch X-Git-Tag: RELEASE-0.14.0 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b55be718bf54d776563811e24331770e4a31f302;p=unikraft%2Flibs%2Flibunwind.git patches: Re-add `UnwindRegistersSave.S` RIP patch The previous patch (removed in 7b56f9b17de72d0e237e4af2bf72635c48389f3c) was erroneous in its implementation but its intent was valid: when saving registers in unikraft libunwind should take the return address of the previous stack frame as the IP of the throwing function. This patch implements this functionality correctly. Signed-off-by: Andrei Tatar Reviewed-by: Stefan Jumarea Reviewed-by: Maria Sfiraiala Reviewed-by: Razvan Deaconescu Approved-by: Eduard Vintilă Tested-by: Unikraft CI GitHub-Closes: #7 --- diff --git a/patches/0001-Save-RIP-from-previous-stack-frame.patch b/patches/0001-Save-RIP-from-previous-stack-frame.patch new file mode 100644 index 0000000..2011e3f --- /dev/null +++ b/patches/0001-Save-RIP-from-previous-stack-frame.patch @@ -0,0 +1,32 @@ +From 6d79ff97d634cf5317492f7e80ede5b8e07bf51a Mon Sep 17 00:00:00 2001 +From: Andrei Tatar +Date: Wed, 10 May 2023 15:21:30 +0300 +Subject: [PATCH] Save RIP from previous stack frame + +__unw_getcontext assumes the throwing function's return address is at +the top of the stack; however, this does not hold in unikraft, instead +we must go one stack frame earlier to get the right address. + +Co-authored-by: Vlad-Andrei Badoiu +Signed-off-by: Vlad-Andrei Badoiu +Signed-off-by: Andrei Tatar +--- + libunwind/src/UnwindRegistersSave.S | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S +index b39489235..49067c021 100644 +--- a/src/UnwindRegistersSave.S ++++ b/src/UnwindRegistersSave.S +@@ -90,7 +90,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext) + movq %r13,104(PTR) + movq %r14,112(PTR) + movq %r15,120(PTR) +- movq (%rsp),TMP ++ movq 8(%rbp),TMP + movq TMP,128(PTR) # store return address as rip + # skip rflags + # skip cs +-- +2.40.1 +