From 511a5a36ec97a2ed0bf1c3af30a8a1ad198d532c Mon Sep 17 00:00:00 2001 From: TaowerfulMAX Date: Thu, 11 Sep 2025 17:22:34 +0800 Subject: [PATCH] samode allow to unwind js stack. Signed-off-by: TaowerfulMAX --- .../native_daemon/src/hook_manager.cpp | 4 ++++ .../common/native/hook_manager_test.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/device/plugins/native_daemon/src/hook_manager.cpp b/device/plugins/native_daemon/src/hook_manager.cpp index 55501f7ca..30bbdce54 100644 --- a/device/plugins/native_daemon/src/hook_manager.cpp +++ b/device/plugins/native_daemon/src/hook_manager.cpp @@ -342,6 +342,10 @@ bool HookManager::HandleHookContext(const std::shared_ptr& ctx) void HookManager::CheckHapEncryped() { + if (saMode_ && hookConfig_.fp_unwind()) { + PROFILER_LOG_DEBUG(LOG_CORE, "sa Mode, the encrypted app is allowed to use fp unwind to catch js stack."); + return; + } for (const auto& pid : hookConfig_.expand_pids()) { if (pid > 0 && COMMON::CheckApplicationEncryped(pid, "")) { hookConfig_.set_js_stack_report(0); diff --git a/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp b/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp index 7bba58cc4..e6df58157 100644 --- a/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp +++ b/device/plugins/native_daemon/test/unittest/common/native/hook_manager_test.cpp @@ -26,6 +26,7 @@ using namespace OHOS::Developtools::NativeDaemon; namespace { const std::string OUTPUT_PATH = "/data/local/tmp/hiprofiler_data.htrace"; const int SMB_PAGES = 16384; +const int TEST_MAX_JS_STACK_DEPTH = 10; class HookManagerTest : public ::testing::Test { public: static void SetUpTestCase() @@ -241,4 +242,22 @@ HWTEST_F(HookManagerTest, CheckNmdInfo002, TestSize.Level1) std::string filePath = "/data/local/tmp/test_profiler.txt"; EXPECT_EQ(access(filePath.c_str(), F_OK), -1); } + +/* + * @tc.name: CheckHapEncryped + * @tc.desc: test CheckHapEncryped when saMode_ and fp_unwind are both true. + * @tc.type: FUNC + */ +HWTEST_F(HookManagerTest, CheckHapEncryped, TestSize.Level0) +{ + std::shared_ptr hookManager = std::make_shared(); + ASSERT_TRUE(hookManager != nullptr); + hookManager->saMode_ = true; + hookManager->hookConfig_.set_fp_unwind(true); + hookManager->hookConfig_.set_js_stack_report(1); + hookManager->hookConfig_.set_max_js_stack_depth(TEST_MAX_JS_STACK_DEPTH); + hookManager->CheckHapEncryped(); + EXPECT_EQ(hookManager->hookConfig_.js_stack_report(), 1); + EXPECT_EQ(hookManager->hookConfig_.max_js_stack_depth(), TEST_MAX_JS_STACK_DEPTH); +} } // namespace \ No newline at end of file -- Gitee