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 023b2045765c20f52a7a786428f13817d068284c..633329186e83f24de64f66cbd4ab4cedd3bf2f2e 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();