Don't fail if default namespace isn't found
This fixes a regression caused by 8f4afc8298ebae34e8f944a0807943997908c67d
that libnativeloader can't no longer handle the case that it has failed
to find the default namespace. Previously before the change,
libnativeloader continued to use nullptr as the parent namespace which
is reconized as the default namespace inside the linker.
This change recovers the previous behavior. When the default namespace
is not found, NativeLoaderNamespace object is constructed from nullptr.
Bug: 138607234
Test: run app-compat/app-startup-gce on cf_x86_phone using forrest
Change-Id: If518fbc055399b73e7d3a6b45ace0f71e9c25dae
(cherry picked from commit db825ceba694eb6abe4ecff45fc4e1121646385f)
Merged-In: If518fbc055399b73e7d3a6b45ace0f71e9c25dae
diff --git a/libnativeloader/native_loader_namespace.cpp b/libnativeloader/native_loader_namespace.cpp
index 4b02116..4add6e6 100644
--- a/libnativeloader/native_loader_namespace.cpp
+++ b/libnativeloader/native_loader_namespace.cpp
@@ -69,10 +69,18 @@
// "default" always exists.
Result<NativeLoaderNamespace> NativeLoaderNamespace::GetPlatformNamespace(bool is_bridged) {
auto ns = GetExportedNamespace(kPlatformNamespaceName, is_bridged);
- if (!ns) {
- ns = GetExportedNamespace(kDefaultNamespaceName, is_bridged);
+ if (ns) return ns;
+ ns = GetExportedNamespace(kDefaultNamespaceName, is_bridged);
+ if (ns) return ns;
+
+ // If nothing is found, return NativeLoaderNamespace constructed from nullptr.
+ // nullptr also means default namespace to the linker.
+ if (!is_bridged) {
+ return NativeLoaderNamespace(kDefaultNamespaceName, static_cast<android_namespace_t*>(nullptr));
+ } else {
+ return NativeLoaderNamespace(kDefaultNamespaceName,
+ static_cast<native_bridge_namespace_t*>(nullptr));
}
- return ns;
}
Result<NativeLoaderNamespace> NativeLoaderNamespace::Create(