summaryrefslogtreecommitdiffstats
path: root/libnativeloader
diff options
context:
space:
mode:
authorDimitry Ivanov <dimitry@google.com>2016-03-15 13:51:26 -0700
committerDimitry Ivanov <dimitry@google.com>2016-03-17 10:54:19 -0700
commitd1fdb9883011f57ab7a3fdcde4d835ef6918b14c (patch)
tree66fc8c184162c859a1237577aa65943b3d32a0bf /libnativeloader
parent371e7ea170d749489a0eb7085347f58b7be63734 (diff)
downloadsystem_core-d1fdb9883011f57ab7a3fdcde4d835ef6918b14c.tar.gz
system_core-d1fdb9883011f57ab7a3fdcde4d835ef6918b14c.tar.bz2
system_core-d1fdb9883011f57ab7a3fdcde4d835ef6918b14c.zip
Move list of public libraries to a config file
This list contains libraries that should directly or indirectly be accessible to apps for the platform. Note that this list is not device specific but rather device class specific. For now we have 2 separate lists; one for Android Phones and Tablets, and another one for Android Wear devices. Bug: http://b/27546414 Bug: http://b/22548808 Change-Id: I83de5e3cf67392d0e9af66f70123898bd5997146 (cherry picked from commit 4b0e963872715775a63f36b385150cba4801b1d0)
Diffstat (limited to 'libnativeloader')
-rw-r--r--libnativeloader/include/nativeloader/native_loader.h2
-rw-r--r--libnativeloader/native_loader.cpp65
2 files changed, 37 insertions, 30 deletions
diff --git a/libnativeloader/include/nativeloader/native_loader.h b/libnativeloader/include/nativeloader/native_loader.h
index b16c0e66e..1bd3b8f07 100644
--- a/libnativeloader/include/nativeloader/native_loader.h
+++ b/libnativeloader/include/nativeloader/native_loader.h
@@ -26,7 +26,7 @@
namespace android {
__attribute__((visibility("default")))
-void PreloadPublicNativeLibraries();
+void InitializeNativeLoader();
__attribute__((visibility("default")))
jstring CreateClassLoaderNamespace(JNIEnv* env,
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 86d9d77f7..899c98c55 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -29,32 +29,14 @@
#include <string>
#include <mutex>
+#include "android-base/file.h"
#include "android-base/macros.h"
#include "android-base/strings.h"
namespace android {
-#ifdef __ANDROID__
-// TODO(dimitry): move this to system properties.
-static const char* kPublicNativeLibraries = "libandroid.so:"
- "libc.so:"
- "libdl.so:"
- "libEGL.so:"
- "libGLESv1_CM.so:"
- "libGLESv2.so:"
- "libGLESv3.so:"
- "libicui18n.so:"
- "libicuuc.so:"
- "libjnigraphics.so:"
- "liblog.so:"
- "libmediandk.so:"
- "libm.so:"
- "libOpenMAXAL.so:"
- "libOpenSLES.so:"
- "libRS.so:"
- "libstdc++.so:"
- "libwebviewchromium_plat_support.so:"
- "libz.so";
+#if defined(__ANDROID__)
+static constexpr const char* kPublicNativeLibrariesConfig = "/system/etc/public.libraries.txt";
class LibraryNamespaces {
public:
@@ -79,7 +61,8 @@ class LibraryNamespaces {
android_namespace_t* ns = FindNamespaceByClassLoader(env, class_loader);
- LOG_FATAL_IF(ns != nullptr, "There is already a namespace associated with this classloader");
+ LOG_ALWAYS_FATAL_IF(ns != nullptr,
+ "There is already a namespace associated with this classloader");
uint64_t namespace_type = ANDROID_NAMESPACE_TYPE_ISOLATED;
if (is_shared) {
@@ -109,10 +92,30 @@ class LibraryNamespaces {
return it != namespaces_.end() ? it->second : nullptr;
}
- void PreloadPublicLibraries() {
+ void Initialize() {
+ // Read list of public native libraries from the config file.
+ std::string file_content;
+ LOG_ALWAYS_FATAL_IF(!base::ReadFileToString(kPublicNativeLibrariesConfig, &file_content),
+ "Error reading public native library list from \"%s\": %s",
+ kPublicNativeLibrariesConfig, strerror(errno));
+
+ std::vector<std::string> lines = base::Split(file_content, "\n");
+
+ std::vector<std::string> sonames;
+
+ for (const auto& line : lines) {
+ auto trimmed_line = base::Trim(line);
+ if (trimmed_line[0] == '#' || trimmed_line.empty()) {
+ continue;
+ }
+
+ sonames.push_back(trimmed_line);
+ }
+
+ public_libraries_ = base::Join(sonames, ':');
+
// android_init_namespaces() expects all the public libraries
// to be loaded so that they can be found by soname alone.
- std::vector<std::string> sonames = android::base::Split(kPublicNativeLibraries, ":");
for (const auto& soname : sonames) {
dlopen(soname.c_str(), RTLD_NOW | RTLD_NODELETE);
}
@@ -120,15 +123,19 @@ class LibraryNamespaces {
private:
bool InitPublicNamespace(const char* library_path) {
- // Some apps call dlopen from generated code unknown to linker in which
- // case linker uses anonymous namespace. See b/25844435 for details.
- initialized_ = android_init_namespaces(kPublicNativeLibraries, library_path);
+ // (http://b/25844435) - Some apps call dlopen from generated code (mono jited
+ // code is one example) unknown to linker in which case linker uses anonymous
+ // namespace. The second argument specifies the search path for the anonymous
+ // namespace which is the library_path of the classloader.
+ initialized_ = android_init_namespaces(public_libraries_.c_str(), library_path);
return initialized_;
}
bool initialized_;
std::vector<std::pair<jweak, android_namespace_t*>> namespaces_;
+ std::string public_libraries_;
+
DISALLOW_COPY_AND_ASSIGN(LibraryNamespaces);
};
@@ -141,10 +148,10 @@ static bool namespaces_enabled(uint32_t target_sdk_version) {
}
#endif
-void PreloadPublicNativeLibraries() {
+void InitializeNativeLoader() {
#if defined(__ANDROID__)
std::lock_guard<std::mutex> guard(g_namespaces_mutex);
- g_namespaces->PreloadPublicLibraries();
+ g_namespaces->Initialize();
#endif
}