From dd165413d72ac3b1739c7cd5883757dd1bbb2a4a Mon Sep 17 00:00:00 2001 From: chenbingbing Date: Sat, 11 Jan 2025 17:08:31 +0800 Subject: [PATCH] prevent samgr rust so dlclose Signed-off-by: chenbingbing --- .../cxx/system_ability_manager_wrapper.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/interfaces/innerkits/rust/src/cxx/system_ability_manager_wrapper.cpp b/interfaces/innerkits/rust/src/cxx/system_ability_manager_wrapper.cpp index 023b2045..63332918 100644 --- a/interfaces/innerkits/rust/src/cxx/system_ability_manager_wrapper.cpp +++ b/interfaces/innerkits/rust/src/cxx/system_ability_manager_wrapper.cpp @@ -35,6 +35,36 @@ namespace SamgrRust { static constexpr size_t MAX_RUST_STR_LEN = 1024; +static void* g_selfSoHandle = nullptr; + +extern "C" __attribute__((constructor)) void InitSamgrRust() +{ + if (g_selfSoHandle != nullptr) { + return; + } + Dl_info info; + int ret = dladdr(reinterpret_cast(InitSamgrRust), &info); + if (ret == 0) { + return; + } + + char path[PATH_MAX] = {'\0'}; + if (realpath(info.dli_fname, path) == nullptr) { + return; + } + std::vector strVector; + SplitStr(path, "/", strVector); + auto vectorSize = strVector.size(); + if (vectorSize == 0) { + return; + } + auto& fileName = strVector[vectorSize - 1]; + g_selfSoHandle = dlopen(fileName.c_str(), RTLD_LAZY); + if (g_selfSoHandle == nullptr) { + return; + } +} + rust::Vec ListSystemAbilities() { auto sysm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); -- Gitee