From 3311c88baf7e73d135844065e3166aae5f11d602 Mon Sep 17 00:00:00 2001 From: yanmengzhao1 Date: Tue, 3 Dec 2024 11:53:48 +0800 Subject: [PATCH] fix: update pac mask function for some other boards. Signed-off-by: yanmengzhao1 --- .../plugins/native_daemon/include/utilities.h | 1 + .../native_daemon/src/stack_preprocess.cpp | 21 +++---------------- .../plugins/native_daemon/src/utilities.cpp | 20 ++++++++++++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/device/plugins/native_daemon/include/utilities.h b/device/plugins/native_daemon/include/utilities.h index e5bd4b4ae..ac309af0a 100644 --- a/device/plugins/native_daemon/include/utilities.h +++ b/device/plugins/native_daemon/include/utilities.h @@ -316,6 +316,7 @@ bool PowerOfTwo(int n); #endif int32_t GetProcessPid(const std::string& processName); bool IsArkJsFile(const std::string& filepath); +uintptr_t StripPac(uintptr_t inAddr, uintptr_t pacMask); } // namespace NativeDaemon } // namespace Developtools } // namespace OHOS diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index 1ff686758..4151f7aae 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -745,12 +745,7 @@ void StackPreprocess::SetEventFrame(const RawStackPtr& rawStack, std::vector& callFrames, uint64_t napiIndex) { - #if defined(__aarch64__) - uintptr_t pacMask = 0xFFFFFF8000000000; -#else - uintptr_t pacMask = 0; -#endif - CallFrame& jsCallFrame = callFrames_.emplace_back(0 & (~pacMask)); + CallFrame& jsCallFrame = callFrames_.emplace_back(0); jsCallFrame.symbolName_ = tagName; jsCallFrame.isJsFrame_ = true; jsCallFrame.needReport_ |= CALL_FRAME_REPORT; @@ -1533,17 +1528,12 @@ void StackPreprocess::FinishReport() void StackPreprocess::FillFpNativeIp(RawStackPtr& rawData) { -#if defined(__aarch64__) - uintptr_t pacMask = 0xFFFFFF8000000000; -#else - uintptr_t pacMask = 0; -#endif uint64_t* fpIp = reinterpret_cast(rawData->data); for (uint8_t idx = 0; idx < rawData->fpDepth ; ++idx) { if (fpIp[idx] == 0) { break; } - callFrames_.emplace_back(fpIp[idx] & (~pacMask)); + callFrames_.emplace_back(StripPac(fpIp[idx], 0)); } } @@ -1607,12 +1597,7 @@ void StackPreprocess::FillFpJsData(RawStackPtr& rawData) void StackPreprocess::FillDwarfErrorStack() { -#if defined(__aarch64__) - uintptr_t pacMask = 0xFFFFFF8000000000; -#else - uintptr_t pacMask = 0; -#endif - CallFrame& jsCallFrame = callFrames_.emplace_back(0 & (~pacMask)); + CallFrame& jsCallFrame = callFrames_.emplace_back(0); jsCallFrame.symbolName_ = "UnwindErrorDwarf"; jsCallFrame.isJsFrame_ = true; jsCallFrame.needReport_ |= CALL_FRAME_REPORT; diff --git a/device/plugins/native_daemon/src/utilities.cpp b/device/plugins/native_daemon/src/utilities.cpp index c89e26dbc..8cf865545 100644 --- a/device/plugins/native_daemon/src/utilities.cpp +++ b/device/plugins/native_daemon/src/utilities.cpp @@ -514,6 +514,26 @@ bool IsArkJsFile(const std::string& filepath) StringStartsWith(filepath, "[anon:ArkTS Code") || StringEndsWith(filepath, ".abc") || StringEndsWith(filepath, ".hqf")); } + +uintptr_t StripPac(uintptr_t inAddr, uintptr_t pacMask) +{ + uintptr_t outAddr = inAddr; +#if defined(__aarch64__) + if (outAddr != 0) { + if (pacMask != 0) { + outAddr &= ~pacMask; + } else { + register uint64_t x30 __asm("x30") = inAddr; + asm("hint 0x7" : "+r"(x30)); + outAddr = x30; + } + if (outAddr != inAddr) { + HLOGM("Strip pac in addr: %lx, out addr: %lx", (uint64_t)inAddr, (uint64_t)outAddr); + } + } +#endif + return outAddr; +} } // namespace NativeDaemon } // namespace Developtools } // namespace OHOS -- Gitee