diff options
author | Jiyong Park <jiyong@google.com> | 2019-05-04 00:30:23 +0900 |
---|---|---|
committer | Jiyong Park <jiyong@google.com> | 2019-05-16 08:55:04 +0900 |
commit | 8537781cc7bf7e866a1c0d1aed904c578ce7391c (patch) | |
tree | 7de7a032e8be1585e1b149790b4de7f2fe89f4b6 /libnativeloader/native_loader.cpp | |
parent | 3afe5f22b34f8f65af98ca2d8c1e6b2aa2ed0f36 (diff) |
Hide non-bridged/bridged namespaces behind NativeLoaderNamespace class
NativeLoaderNamespace fully abstracts the non-bridged (so called
android-) and bridged namespaces.
Bug: 130388701
Test: build & pass presubmit tests
Change-Id: I3d5ca7515711e7638f4a5ab4d3a150185c3d17ac
Diffstat (limited to 'libnativeloader/native_loader.cpp')
-rw-r--r-- | libnativeloader/native_loader.cpp | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index eeee077df..d6304a916 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -220,25 +220,12 @@ void NativeLoaderFreeErrorMessage(char* msg) { #if defined(__ANDROID__) void* OpenNativeLibraryInNamespace(NativeLoaderNamespace* ns, const char* path, bool* needs_native_bridge, char** error_msg) { - if (ns->is_android_namespace()) { - android_dlextinfo extinfo; - extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE; - extinfo.library_namespace = ns->get_android_ns(); - - void* handle = android_dlopen_ext(path, RTLD_NOW, &extinfo); - if (handle == nullptr) { - *error_msg = strdup(dlerror()); - } - *needs_native_bridge = false; - return handle; - } else { - void* handle = NativeBridgeLoadLibraryExt(path, RTLD_NOW, ns->get_native_bridge_ns()); - if (handle == nullptr) { - *error_msg = strdup(NativeBridgeGetError()); - } - *needs_native_bridge = true; - return handle; + void* handle = ns->Load(path); + if (handle == nullptr) { + *error_msg = ns->GetError(); } + *needs_native_bridge = ns->IsBridged(); + return handle; } // native_bridge_namespaces are not supported for callers of this function. @@ -247,10 +234,9 @@ void* OpenNativeLibraryInNamespace(NativeLoaderNamespace* ns, const char* path, android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) { std::lock_guard<std::mutex> guard(g_namespaces_mutex); NativeLoaderNamespace* ns = g_namespaces->FindNamespaceByClassLoader(env, class_loader); - if (ns != nullptr) { - return ns->is_android_namespace() ? ns->get_android_ns() : nullptr; + if (ns != nullptr && !ns->IsBridged()) { + return ns->ToRawAndroidNamespace(); } - return nullptr; } |