summaryrefslogtreecommitdiff
path: root/libnativeloader/library_namespaces.cpp
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2022-11-16 15:28:12 +0000
committer Treehugger Robot <treehugger-gerrit@google.com> 2022-11-18 18:24:30 +0000
commite5f1d635677b297ca422fb981124fffa9386872c (patch)
tree183f163351ea11537b9da953584d8921e8e9985c /libnativeloader/library_namespaces.cpp
parent51d5e87df717dcb846ff3ee589189d6f0d5a955d (diff)
Make classloader namespace names unique, for debugging.
Also take the opportunity to switch to shorter names, when they are changing anyway. These namespaces aren't visible, so renaming them shouldn't be a compat issue. Test: atest libnativeloader_test libnativeloader_e2e_tests Test: adb shell "setprop debug.ld.all dlopen,dlerror && setprop log.tag.nativeloader :v && stop && start" Then check logcat that the classloader namespaces get the expected unique names (per process). Bug: 258340826 Change-Id: Ic5d6ba850d8cd9cdfb3a66e175dfc87046c0ba31
Diffstat (limited to 'libnativeloader/library_namespaces.cpp')
-rw-r--r--libnativeloader/library_namespaces.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index aaf724153f..2a6febdd80 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -30,6 +30,7 @@
#include <android-base/macros.h>
#include <android-base/result.h>
#include <android-base/strings.h>
+#include <android-base/stringprintf.h>
#include <nativehelper/scoped_utf_chars.h>
#include "nativeloader/dlext_namespaces.h"
@@ -55,19 +56,20 @@ constexpr const char* kVndkNamespaceName = "vndk";
// vndk_product namespace for unbundled product apps
constexpr const char* kVndkProductNamespaceName = "vndk_product";
-// classloader-namespace is a linker namespace that is created for the loaded
-// app. To be specific, it is created for the app classloader. When
-// System.load() is called from a Java class that is loaded from the
-// classloader, the classloader-namespace namespace associated with that
-// classloader is selected for dlopen. The namespace is configured so that its
-// search path is set to the app-local JNI directory and it is linked to the
-// system namespace with the names of libs listed in the public.libraries.txt.
-// This way an app can only load its own JNI libraries along with the public libs.
-constexpr const char* kClassloaderNamespaceName = "classloader-namespace";
-// Same thing for unbundled vendor APKs.
-constexpr const char* kVendorClassloaderNamespaceName = "vendor-classloader-namespace";
-// Same thing for unbundled product APKs.
-constexpr const char* kProductClassloaderNamespaceName = "product-classloader-namespace";
+// clns-XX is a linker namespace that is created for normal apps installed in
+// the data partition. To be specific, it is created for the app classloader.
+// When System.load() is called from a Java class that is loaded from the
+// classloader, the clns namespace associated with that classloader is selected
+// for dlopen. The namespace is configured so that its search path is set to the
+// app-local JNI directory and it is linked to the system namespace with the
+// names of libs listed in the public.libraries.txt and other public libraries.
+// This way an app can only load its own JNI libraries along with the public
+// libs.
+constexpr const char* kClassloaderNamespaceName = "clns";
+// Same thing for unbundled APKs in the vendor partition.
+constexpr const char* kVendorClassloaderNamespaceName = "vendor-clns";
+// Same thing for unbundled APKs in the product partition.
+constexpr const char* kProductClassloaderNamespaceName = "product-clns";
// If the namespace is shared then add this suffix to help identify it in debug
// messages. A shared namespace (cf. ANDROID_NAMESPACE_TYPE_SHARED) has
// inherited all the libraries of the parent classloader namespace, or the
@@ -294,6 +296,11 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
namespace_name = namespace_name + kSharedNamespaceSuffix;
}
+ // Append a unique number to the namespace name, to tell them apart when
+ // debugging linker issues, e.g. with debug.ld.all set to "dlopen,dlerror".
+ static int clns_count = 0;
+ namespace_name = android::base::StringPrintf("%s-%d", namespace_name.c_str(), ++clns_count);
+
ALOGD(
"Configuring %s for %s %s. target_sdk_version=%u, uses_libraries=%s, library_path=%s, "
"permitted_path=%s",