Merge changes from topic \'fix-nativeloader-todo\' into nyc-dev am: c8bc211
am: 0583bc6
* commit '0583bc610b56dfba646d16e5ee88131b6b918cdd':
Move list of public libraries to a config file
Revert "libnativeloader: Make webviewchromium so file optional"
This commit is contained in:
commit
8239061a22
|
@ -14,9 +14,6 @@ LOCAL_SHARED_LIBRARIES := libnativehelper liblog libcutils
|
|||
LOCAL_STATIC_LIBRARIES := libbase
|
||||
LOCAL_CLANG := true
|
||||
LOCAL_CFLAGS += -Werror -Wall
|
||||
ifeq ($(TARGET_IGNORE_WEBVIEW_CHROMIUM), true)
|
||||
LOCAL_CFLAGS += -DIGNORE_WEBVIEW_CHROMIUM
|
||||
endif
|
||||
LOCAL_CPPFLAGS := -std=gnu++14 -fvisibility=hidden
|
||||
LOCAL_LDFLAGS := -ldl
|
||||
LOCAL_MULTILIB := both
|
||||
|
@ -35,9 +32,6 @@ LOCAL_SHARED_LIBRARIES := libnativehelper liblog libcutils
|
|||
LOCAL_STATIC_LIBRARIES := libbase
|
||||
LOCAL_CLANG := true
|
||||
LOCAL_CFLAGS += -Werror -Wall
|
||||
ifeq ($(TARGET_IGNORE_WEBVIEW_CHROMIUM), true)
|
||||
LOCAL_CFLAGS += -DIGNORE_WEBVIEW_CHROMIUM
|
||||
endif
|
||||
LOCAL_CPPFLAGS := -std=gnu++14 -fvisibility=hidden
|
||||
LOCAL_LDFLAGS := -ldl
|
||||
LOCAL_MULTILIB := both
|
||||
|
@ -55,9 +49,6 @@ LOCAL_SRC_FILES:= $(NATIVE_LOADER_COMMON_SRC_FILES)
|
|||
LOCAL_STATIC_LIBRARIES := libnativehelper libcutils liblog libbase
|
||||
LOCAL_CLANG := true
|
||||
LOCAL_CFLAGS += -Werror -Wall
|
||||
ifeq ($(TARGET_IGNORE_WEBVIEW_CHROMIUM), true)
|
||||
LOCAL_CFLAGS += -DIGNORE_WEBVIEW_CHROMIUM
|
||||
endif
|
||||
LOCAL_CPPFLAGS := -std=gnu++14 -fvisibility=hidden
|
||||
LOCAL_LDFLAGS := -ldl
|
||||
LOCAL_MULTILIB := both
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace android {
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
void PreloadPublicNativeLibraries();
|
||||
void InitializeNativeLoader();
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
jstring CreateClassLoaderNamespace(JNIEnv* env,
|
||||
|
|
|
@ -29,36 +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:"
|
||||
"libcamera2ndk.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:"
|
||||
"libvulkan.so:"
|
||||
#if !defined(IGNORE_WEBVIEW_CHROMIUM)
|
||||
"libwebviewchromium_plat_support.so:"
|
||||
#endif
|
||||
"libz.so";
|
||||
#if defined(__ANDROID__)
|
||||
static constexpr const char* kPublicNativeLibrariesConfig = "/system/etc/public.libraries.txt";
|
||||
|
||||
class LibraryNamespaces {
|
||||
public:
|
||||
|
@ -84,7 +62,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) {
|
||||
|
@ -114,10 +93,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);
|
||||
}
|
||||
|
@ -125,9 +124,7 @@ class LibraryNamespaces {
|
|||
|
||||
private:
|
||||
bool InitPublicNamespace(const char* library_path, int32_t target_sdk_version) {
|
||||
// Some apps call dlopen from generated code unknown to linker in which
|
||||
// case linker uses anonymous namespace. See b/25844435 for details.
|
||||
std::string publicNativeLibraries = kPublicNativeLibraries;
|
||||
std::string publicNativeLibraries = public_libraries_;
|
||||
|
||||
// TODO (dimitry): This is a workaround for http://b/26436837
|
||||
// will be removed before the release.
|
||||
|
@ -141,6 +138,10 @@ class LibraryNamespaces {
|
|||
}
|
||||
// END OF WORKAROUND
|
||||
|
||||
// (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(publicNativeLibraries.c_str(), library_path);
|
||||
|
||||
return initialized_;
|
||||
|
@ -148,6 +149,8 @@ class LibraryNamespaces {
|
|||
|
||||
bool initialized_;
|
||||
std::vector<std::pair<jweak, android_namespace_t*>> namespaces_;
|
||||
std::string public_libraries_;
|
||||
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LibraryNamespaces);
|
||||
};
|
||||
|
@ -160,10 +163,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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue