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 4b0e963872)
This commit is contained in:
Dimitry Ivanov 2016-03-15 13:51:26 -07:00
parent 371e7ea170
commit d1fdb98830
4 changed files with 74 additions and 30 deletions

View File

@ -26,7 +26,7 @@
namespace android {
__attribute__((visibility("default")))
void PreloadPublicNativeLibraries();
void InitializeNativeLoader();
__attribute__((visibility("default")))
jstring CreateClassLoaderNamespace(JNIEnv* env,

View File

@ -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
}

View File

@ -0,0 +1,19 @@
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

View File

@ -0,0 +1,18 @@
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
libz.so