diff --git a/module_manager/native_module_manager.cpp b/module_manager/native_module_manager.cpp index 46d648338f6632c92646a8085a3bf481cb48f390..52d6ffeb7384ef38d24dceb0d2a6e3443dde0836 100755 --- a/module_manager/native_module_manager.cpp +++ b/module_manager/native_module_manager.cpp @@ -25,6 +25,9 @@ #include "securec.h" #include "utils/log.h" +#define NDK "ndk" +#define ALLOW_ALL_SHARED_LIBS "allow_all_shared_libs" + namespace { constexpr static int32_t NATIVE_PATH_NUMBER = 2; } // namespace @@ -194,7 +197,6 @@ void NativeModuleManager::CreateSharedLibsSonames() "libEGL.so", "libGLESv3.so", "libhiappevent_ndk.z.so", - "libhilog_ndk.z.so", "libhuks_ndk.z.so", "libhukssdk.z.so", "libnative_drawing.so", @@ -237,7 +239,7 @@ void NativeModuleManager::CreateSharedLibsSonames() } #endif -void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const char* lib_ld_path) +void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const char* lib_ld_path, const bool &isSystemApp) { #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(__BIONIC__) && !defined(IOS_PLATFORM) && \ !defined(LINUX_PLATFORM) @@ -247,16 +249,34 @@ void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const dlns_init(&ns, nsName.c_str()); dlns_get(nullptr, ¤t_ns); dlns_create2(&ns, lib_ld_path, 0); - if (!sharedLibsSonames_) { - CreateSharedLibsSonames(); + Dl_namespace ndk_ns; + dlns_get(NDK, &ndk_ns); + + if (isSystemApp) { + if (strlen(ndk_ns.name) > 0) { + dlns_inherit(&ns, &ndk_ns, ALLOW_ALL_SHARED_LIBS); + dlns_inherit(&ndk_ns, ¤t_ns, ALLOW_ALL_SHARED_LIBS); + dlns_inherit(&ns, ¤t_ns, ALLOW_ALL_SHARED_LIBS); + } + } else { + if (!sharedLibsSonames_) { + CreateSharedLibsSonames(); + } + dlns_inherit(&ns, ¤t_ns, sharedLibsSonames_); + if (strlen(ndk_ns.name) > 0) { + dlns_inherit(&ns, &ndk_ns, ALLOW_ALL_SHARED_LIBS); + dlns_inherit(&ndk_ns, ¤t_ns, ALLOW_ALL_SHARED_LIBS); + } } - dlns_inherit(&ns, ¤t_ns, sharedLibsSonames_); + 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; @@ -289,7 +309,7 @@ void NativeModuleManager::SetAppLibPath(const std::string& moduleName, const std } appLibPathMap_[moduleName] = tmp; - CreateLdNamespace(moduleName, tmp); + CreateLdNamespace(moduleName, tmp, isSystemApp); 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 b7e6ca9244ec58cdd7c9c905d9f116852ff805c3..b91a04e372d3977a06737530da4fd40d066c1163 100644 --- a/module_manager/native_module_manager.h +++ b/module_manager/native_module_manager.h @@ -71,7 +71,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); @@ -108,7 +109,7 @@ private: const bool isAppModule); NativeModule* FindNativeModuleByCache(const char* moduleName); LIBHANDLE LoadModuleLibrary(const char* path, const char* pathKey, const bool isAppModule); - void CreateLdNamespace(const std::string moduleName, const char* lib_ld_path); + void CreateLdNamespace(const std::string moduleName, const char* lib_ld_path, const bool &isSystemApp); bool IsExistedPath(const char* pathKey) const; #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(__BIONIC__) && !defined(IOS_PLATFORM) && \ !defined(LINUX_PLATFORM)