Skip to content

Commit

Permalink
Extend Link() to allow linking to the default namespace.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marstj committed May 5, 2021
1 parent 107d22b commit 2207b7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 6 additions & 6 deletions libnativeloader/library_namespaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
10 changes: 6 additions & 4 deletions libnativeloader/native_loader_namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
}
Expand Down
6 changes: 5 additions & 1 deletion libnativeloader/native_loader_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2207b7e

Please sign in to comment.