Skip to content

Commit 6214dcc

Browse files
authored
[Unwind][AArch64] Match sigreturn instructions in big endian (#167139)
Since insns are always stored LE, on a BE system the opcodes will be loaded byte-reversed. Therefore, define two sets of opcodes, one for LE and one for BE.
1 parent 9036e23 commit 6214dcc

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

libunwind/src/UnwindCursor.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,21 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
28652865

28662866
#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) && \
28672867
defined(_LIBUNWIND_TARGET_AARCH64)
2868+
2869+
/*
2870+
* The linux sigreturn restorer stub will always have the form:
2871+
*
2872+
* d2801168 movz x8, #0x8b
2873+
* d4000001 svc #0x0
2874+
*/
2875+
#if defined(__AARCH64EB__)
2876+
#define MOVZ_X8_8B 0x681180d2
2877+
#define SVC_0 0x010000d4
2878+
#else
2879+
#define MOVZ_X8_8B 0xd2801168
2880+
#define SVC_0 0xd4000001
2881+
#endif
2882+
28682883
template <typename A, typename R>
28692884
bool UnwindCursor<A, R>::setInfoForSigReturn(Registers_arm64 &) {
28702885
// Look for the sigreturn trampoline. The trampoline's body is two
@@ -2889,7 +2904,7 @@ bool UnwindCursor<A, R>::setInfoForSigReturn(Registers_arm64 &) {
28892904
return false;
28902905
auto *instructions = reinterpret_cast<const uint32_t *>(pc);
28912906
// Look for instructions: mov x8, #0x8b; svc #0x0
2892-
if (instructions[0] != 0xd2801168 || instructions[1] != 0xd4000001)
2907+
if (instructions[0] != MOVZ_X8_8B || instructions[1] != SVC_0)
28932908
return false;
28942909

28952910
_info = {};

0 commit comments

Comments
 (0)