summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2021-04-28 14:52:01 +0100
committer Martin Stjernholm <mast@google.com> 2021-05-05 12:07:48 +0000
commit2207b7e7db463dfa96d071654c49268e22e8745f (patch)
treee01f687e8761a63d83b9858a02d529ddacc1b60f
parent107d22b9c7a97275e62bb5a97eb871713cfa0616 (diff)
Extend Link() to allow linking to the default namespace.
The code path through native bridge and NDK translation should propagate nullptr as well. This to support a later change that changes the way native test libraries are loaded in ART run tests. Test: art/test/testrunner/testrunner.py --target --64 --optimizing Bug: 130340935 Change-Id: I934d11942e41ccc6d140a7044faa160b006166f1
-rw-r--r--libnativeloader/library_namespaces.cpp12
-rw-r--r--libnativeloader/native_loader_namespace.cpp10
-rw-r--r--libnativeloader/native_loader_namespace.h6
3 files changed, 17 insertions, 11 deletions
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index dcd2f657b1..79fee060cf 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -305,7 +305,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
return system_ns.error();
}
- auto linked = app_ns->Link(*system_ns, system_exposed_libraries);
+ auto linked = app_ns->Link(&system_ns.value(), system_exposed_libraries);
if (!linked.ok()) {
return linked.error();
}
@@ -314,7 +314,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
auto ns = NativeLoaderNamespace::GetExportedNamespace(apex_ns_name, is_bridged);
// Even if APEX namespace is visible, it may not be available to bridged.
if (ns.ok()) {
- linked = app_ns->Link(*ns, public_libs);
+ linked = app_ns->Link(&ns.value(), public_libs);
if (!linked.ok()) {
return linked.error();
}
@@ -325,7 +325,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
if (unbundled_app_origin == APK_ORIGIN_VENDOR && !vndksp_libraries_vendor().empty()) {
auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkNamespaceName, is_bridged);
if (vndk_ns.ok()) {
- linked = app_ns->Link(*vndk_ns, vndksp_libraries_vendor());
+ linked = app_ns->Link(&vndk_ns.value(), vndksp_libraries_vendor());
if (!linked.ok()) {
return linked.error();
}
@@ -336,7 +336,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
if (unbundled_app_origin == APK_ORIGIN_PRODUCT && !vndksp_libraries_product().empty()) {
auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkProductNamespaceName, is_bridged);
if (vndk_ns.ok()) {
- linked = app_ns->Link(*vndk_ns, vndksp_libraries_product());
+ linked = app_ns->Link(&vndk_ns.value(), vndksp_libraries_product());
if (!linked.ok()) {
return linked.error();
}
@@ -349,7 +349,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
if (jni_libs != "") {
auto apex_ns = NativeLoaderNamespace::GetExportedNamespace(*apex_ns_name, is_bridged);
if (apex_ns.ok()) {
- linked = app_ns->Link(*apex_ns, jni_libs);
+ linked = app_ns->Link(&apex_ns.value(), jni_libs);
if (!linked.ok()) {
return linked.error();
}
@@ -364,7 +364,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
// when vendor_ns is not configured, link to the system namespace
auto target_ns = vendor_ns.ok() ? vendor_ns : system_ns;
if (target_ns.ok()) {
- linked = app_ns->Link(*target_ns, vendor_libs);
+ linked = app_ns->Link(&target_ns.value(), vendor_libs);
if (!linked.ok()) {
return linked.error();
}
diff --git a/libnativeloader/native_loader_namespace.cpp b/libnativeloader/native_loader_namespace.cpp
index fe15c70ac8..669fa74dc2 100644
--- a/libnativeloader/native_loader_namespace.cpp
+++ b/libnativeloader/native_loader_namespace.cpp
@@ -139,18 +139,20 @@ Result<NativeLoaderNamespace> NativeLoaderNamespace::Create(
is_bridged ? "bridged" : "native", name, search_paths, permitted_paths);
}
-Result<void> NativeLoaderNamespace::Link(const NativeLoaderNamespace& target,
+Result<void> NativeLoaderNamespace::Link(const NativeLoaderNamespace* target,
const std::string& shared_libs) const {
LOG_ALWAYS_FATAL_IF(shared_libs.empty(), "empty share lib when linking %s to %s",
- this->name().c_str(), target.name().c_str());
+ this->name().c_str(), target == nullptr ? "default" : target->name().c_str());
if (!IsBridged()) {
- if (android_link_namespaces(this->ToRawAndroidNamespace(), target.ToRawAndroidNamespace(),
+ if (android_link_namespaces(this->ToRawAndroidNamespace(),
+ target == nullptr ? nullptr : target->ToRawAndroidNamespace(),
shared_libs.c_str())) {
return {};
}
} else {
if (NativeBridgeLinkNamespaces(this->ToRawNativeBridgeNamespace(),
- target.ToRawNativeBridgeNamespace(), shared_libs.c_str())) {
+ target == nullptr ? nullptr : target->ToRawNativeBridgeNamespace(),
+ shared_libs.c_str())) {
return {};
}
}
diff --git a/libnativeloader/native_loader_namespace.h b/libnativeloader/native_loader_namespace.h
index f6a324be56..9a5aeac203 100644
--- a/libnativeloader/native_loader_namespace.h
+++ b/libnativeloader/native_loader_namespace.h
@@ -55,7 +55,11 @@ struct NativeLoaderNamespace {
std::string name() const { return name_; }
bool IsBridged() const { return raw_.index() == 1; }
- Result<void> Link(const NativeLoaderNamespace& target, const std::string& shared_libs) const;
+ // Creates a link from this namespace to target for the ":"-separated list of
+ // libraries in shared_libs. If target is nullptr it creates a link to the
+ // default namespace.
+ Result<void> Link(const NativeLoaderNamespace* target, const std::string& shared_libs) const;
+
Result<void*> Load(const char* lib_name) const;
static Result<NativeLoaderNamespace> GetExportedNamespace(const std::string& name,