From e139054b741d2b6b2e46fe33a9351a971707fe05 Mon Sep 17 00:00:00 2001 From: hstk30 Date: Sat, 8 Nov 2025 21:21:09 +0800 Subject: [PATCH 1/2] [Unwind][AArch64] Match sigreturn instructions in big endian --- libunwind/src/UnwindCursor.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index 7ec5f9e91578a..9414fd8a81525 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -58,6 +58,14 @@ #include "RWMutex.hpp" #include "Unwind-EHABI.h" +#if defined(__AARCH64EB__) +#define MOVZ_X8_8B 0x681180d2 +#define SVC_0 0x010000d4 +#else +#define MOVZ_X8_8B 0xd2801168 +#define SVC_0 0xd4000001 +#endif + #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) // Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and // earlier) SDKs. @@ -2827,7 +2835,7 @@ bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) { return false; auto *instructions = reinterpret_cast(pc); // Look for instructions: mov x8, #0x8b; svc #0x0 - if (instructions[0] != 0xd2801168 || instructions[1] != 0xd4000001) + if (instructions[0] != MOVZ_X8_8B || instructions[1] != SVC_0) return false; _info = {}; From b6fed5b7407dca8ef6ef7e959c120f68c9ab6169 Mon Sep 17 00:00:00 2001 From: hstk30 Date: Mon, 10 Nov 2025 23:43:40 +0800 Subject: [PATCH 2/2] Add comment about instruction sequence --- libunwind/src/UnwindCursor.hpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index 9414fd8a81525..35a12d28e8f37 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -58,14 +58,6 @@ #include "RWMutex.hpp" #include "Unwind-EHABI.h" -#if defined(__AARCH64EB__) -#define MOVZ_X8_8B 0x681180d2 -#define SVC_0 0x010000d4 -#else -#define MOVZ_X8_8B 0xd2801168 -#define SVC_0 0xd4000001 -#endif - #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) // Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and // earlier) SDKs. @@ -2811,6 +2803,21 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) { #if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) && \ defined(_LIBUNWIND_TARGET_AARCH64) + +/* + * The linux sigreturn restorer stub will always have the form: + * + * d2801168 movz x8, #0x8b + * d4000001 svc #0x0 + */ +#if defined(__AARCH64EB__) +#define MOVZ_X8_8B 0x681180d2 +#define SVC_0 0x010000d4 +#else +#define MOVZ_X8_8B 0xd2801168 +#define SVC_0 0xd4000001 +#endif + template bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) { // Look for the sigreturn trampoline. The trampoline's body is two