diff options
author | Jooyung Han <jooyung@google.com> | 2020-03-03 00:46:50 +0900 |
---|---|---|
committer | Treehugger Robot <treehugger-gerrit@google.com> | 2020-03-04 05:56:39 +0000 |
commit | 538f99ab285c1440969b9b3331fc0ce750c0d316 (patch) | |
tree | 018e9cbfc08ba39b3f35e457a8658fcc4cc8db75 /libnativeloader/native_loader.cpp | |
parent | 6fc471e510d6a4e9c31fcab6c0542e2efdf50099 (diff) |
Loading JNI libraries in an APEX
To load JNI libraries in an APEX, libnativeloader relies on
jni.config.txt file which contains available JNI libraries for
APEX namespaces:
com_android_foo libfoo_jni.so:...
com_android_bar libbar_jni.so:...
This file is generated by linkerconfig.
Bug: 143733063
Test: cuttlestone boots
(For now, no behavioral changes because jni.config.txt is empty)
Change-Id: I066de90a73875118be53972e50d076061922d762
Diffstat (limited to 'libnativeloader/native_loader.cpp')
-rw-r--r-- | libnativeloader/native_loader.cpp | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index 988e8a841c..2a28a05c01 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -45,27 +45,15 @@ namespace { #if defined(__ANDROID__) using android::nativeloader::LibraryNamespaces; -constexpr const char* kApexPath = "/apex/"; - std::mutex g_namespaces_mutex; LibraryNamespaces* g_namespaces = new LibraryNamespaces; android_namespace_t* FindExportedNamespace(const char* caller_location) { - std::string location = caller_location; - // Lots of implicit assumptions here: we expect `caller_location` to be of the form: - // /apex/modulename/... - // - // And we extract from it 'modulename', which is the name of the linker namespace. - if (android::base::StartsWith(location, kApexPath)) { - size_t start_index = strlen(kApexPath); - size_t slash_index = location.find_first_of('/', start_index); - LOG_ALWAYS_FATAL_IF((slash_index == std::string::npos), - "Error finding namespace of apex: no slash in path %s", caller_location); - std::string name = location.substr(start_index, slash_index - start_index); - std::replace(name.begin(), name.end(), '.', '_'); - android_namespace_t* boot_namespace = android_get_exported_namespace(name.c_str()); + auto name = nativeloader::FindApexNamespaceName(caller_location); + if (name.ok()) { + android_namespace_t* boot_namespace = android_get_exported_namespace(name->c_str()); LOG_ALWAYS_FATAL_IF((boot_namespace == nullptr), - "Error finding namespace of apex: no namespace called %s", name.c_str()); + "Error finding namespace of apex: no namespace called %s", name->c_str()); return boot_namespace; } return nullptr; |