From ad029d38695596f5fc39fe9dd9d5d8a55ebe73d4 Mon Sep 17 00:00:00 2001 From: zhuhan Date: Wed, 22 Mar 2023 17:53:13 +0800 Subject: [PATCH] ndk namaspace Signed-off-by: zhuhan Change-Id: Ib62a8c8c361f9f0ceba18c314971f0e442cec181 --- module_manager/native_module_manager.cpp | 19 +++++++++++++++++-- module_manager/native_module_manager.h | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/module_manager/native_module_manager.cpp b/module_manager/native_module_manager.cpp index cef6799ba..7d9323994 100755 --- a/module_manager/native_module_manager.cpp +++ b/module_manager/native_module_manager.cpp @@ -15,6 +15,7 @@ #include "native_module_manager.h" +#include #include #include @@ -25,6 +26,8 @@ #include "securec.h" #include "utils/log.h" +#define NDK "ndk" + namespace { constexpr static int32_t NATIVE_PATH_NUMBER = 2; } // namespace @@ -240,20 +243,30 @@ void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const !defined(LINUX_PLATFORM) Dl_namespace current_ns; Dl_namespace ns; + Dl_namespace ndk_ns; + std::string nsName = "arkUI_" + moduleName; dlns_init(&ns, nsName.c_str()); dlns_get(nullptr, ¤t_ns); + dlns_get(NDK, &ndk_ns); dlns_create2(&ns, lib_ld_path, 0); if (!sharedLibsSonames_) { CreateSharedLibsSonames(); } dlns_inherit(&ns, ¤t_ns, sharedLibsSonames_); + + // valid ndk_ns + if (strlen(ndk_ns.name) > 0) { + dlns_inherit(&ns, &ndk_ns, nullptr); + } nsMap_[moduleName] = ns; + nsMap_[NDK] = ndk_ns; HILOG_INFO("CreateLdNamespace success, path: %{private}s", lib_ld_path); #endif } -void NativeModuleManager::SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath) +void NativeModuleManager::SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath, + const bool &isSystemApp) { char* tmp = new char[NAPI_PATH_MAX]; errno_t err = EOK; @@ -286,7 +299,9 @@ void NativeModuleManager::SetAppLibPath(const std::string& moduleName, const std } appLibPathMap_[moduleName] = tmp; - CreateLdNamespace(moduleName, tmp); + if (isSystemApp) { + CreateLdNamespace(moduleName, tmp); + } HILOG_INFO("create ld namespace, path: %{private}s", appLibPathMap_[moduleName]); } diff --git a/module_manager/native_module_manager.h b/module_manager/native_module_manager.h index fbd004e9f..819c003f0 100644 --- a/module_manager/native_module_manager.h +++ b/module_manager/native_module_manager.h @@ -67,7 +67,8 @@ public: static uint64_t Release(); void Register(NativeModule* nativeModule); - void SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath); + void SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath, + const bool &isSystemApp = false); NativeModule* LoadNativeModule(const char* moduleName, const char* path, bool isAppModule, bool internal = false); void SetNativeEngine(std::string moduleName, NativeEngine* nativeEngine); -- Gitee