Fix locking of libnativeloader
am: 34d5a20c8b
* commit '34d5a20c8bb57adae8711c7f9d90a77fbd4043c7':
Fix locking of libnativeloader
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 837924b..ce893db 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -80,8 +80,6 @@
return nullptr;
}
- std::lock_guard<std::mutex> guard(mutex_);
-
android_namespace_t* ns = FindNamespaceByClassLoader(env, class_loader);
LOG_FATAL_IF(ns != nullptr, "There is already a namespace associated with this classloader");
@@ -142,12 +140,12 @@
}
bool initialized_;
- std::mutex mutex_;
std::vector<std::pair<jweak, android_namespace_t*>> namespaces_;
DISALLOW_COPY_AND_ASSIGN(LibraryNamespaces);
};
+static std::mutex g_namespaces_mutex;
static LibraryNamespaces* g_namespaces = new LibraryNamespaces;
static bool namespaces_enabled(uint32_t target_sdk_version) {
@@ -157,6 +155,7 @@
void PreloadPublicNativeLibraries() {
#if defined(__ANDROID__)
+ std::lock_guard<std::mutex> guard(g_namespaces_mutex);
g_namespaces->PreloadPublicLibraries();
#endif
}
@@ -173,6 +172,7 @@
return nullptr;
}
+ std::lock_guard<std::mutex> guard(g_namespaces_mutex);
android_namespace_t* ns = g_namespaces->Create(env,
class_loader,
is_shared,
@@ -199,6 +199,7 @@
return dlopen(path, RTLD_NOW);
}
+ std::lock_guard<std::mutex> guard(g_namespaces_mutex);
android_namespace_t* ns = g_namespaces->FindNamespaceByClassLoader(env, class_loader);
if (ns == nullptr) {
@@ -223,6 +224,7 @@
#if defined(__ANDROID__)
android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) {
+ std::lock_guard<std::mutex> guard(g_namespaces_mutex);
return g_namespaces->FindNamespaceByClassLoader(env, class_loader);
}
#endif