diff options
author | 2025-01-21 15:07:40 +0000 | |
---|---|---|
committer | 2025-01-28 00:46:55 -0800 | |
commit | 162e2634caca054659a829df1040ee052b900c34 (patch) | |
tree | 864878bda454be5069a1f417597bf8ccfde2a43b /dalvikvm/dalvikvm.cc | |
parent | daacc31423f8bcece99953d23661f0bffc91011f (diff) |
Allow ART internal libs to load libs in NATIVELOADER_DEFAULT_NAMESPACE_LIBS.
This complements the treatment of NATIVELOADER_DEFAULT_NAMESPACE_LIBS,
so that ART internal libs can load the libraries listed in that
variable, as well as the other way around.
This makes it possible to load libartagent(d).so without absolute paths
in run tests on target, so use that to re-enable 900-hello-plugin.
Test: art/test/testrunner/testrunner.py --target --64 900
in armv8 target chroot
Test: art/test/testrunner/testrunner.py --host 900
Bug: 186654484
Change-Id: Ic418b26b2b77af8839af7b65ad44ea8b5121169c
Diffstat (limited to 'dalvikvm/dalvikvm.cc')
-rw-r--r-- | dalvikvm/dalvikvm.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/dalvikvm/dalvikvm.cc b/dalvikvm/dalvikvm.cc index 27709fda4a..ebdcef1775 100644 --- a/dalvikvm/dalvikvm.cc +++ b/dalvikvm/dalvikvm.cc @@ -14,10 +14,12 @@ * limitations under the License. */ +#include <dlfcn.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> + #include <algorithm> #include <memory> @@ -27,8 +29,42 @@ #include "nativehelper/ScopedLocalRef.h" #include "nativehelper/toStringArray.h" +#ifdef ART_TARGET_ANDROID +#include "nativeloader/dlext_namespaces.h" +#endif + namespace art { +// This complements the treatment of NATIVELOADER_DEFAULT_NAMESPACE_LIBS in +// art/libnativeloader/native_loader.cpp: The libraries listed in that variable +// are added to the default namespace, which for dalvikvm runs means they can +// access all internal libs in com_android_art. However, to allow the opposite +// direction we need links for them from com_android_art back to default, and +// that's done here. See comments in native_loader.cpp for full discussion. +static bool initNativeloaderExtraLibsLinks() { +#ifdef ART_TARGET_ANDROID + const char* links = getenv("NATIVELOADER_DEFAULT_NAMESPACE_LIBS"); + if (links == nullptr || *links == 0) { + return true; + } + struct android_namespace_t* art_ns = android_get_exported_namespace("com_android_art"); + if (art_ns == nullptr) { + fprintf(stderr, + "Warning: com_android_art namespace not found - " + "NATIVELOADER_DEFAULT_NAMESPACE_LIBS ignored\n"); + return true; + } + if (!android_link_namespaces(art_ns, nullptr, links)) { + fprintf(stderr, + "Error adding linker namespace links from com_android_art to default for %s: %s", + links, + dlerror()); + return false; + } +#endif // ART_TARGET_ANDROID + return true; +} + // Determine whether or not the specified method is public. static bool IsMethodPublic(JNIEnv* env, jclass c, jmethodID method_id) { ScopedLocalRef<jobject> reflected(env, env->ToReflectedMethod(c, method_id, JNI_FALSE)); @@ -148,6 +184,10 @@ static int dalvikvm(int argc, char** argv) { } } + if (!initNativeloaderExtraLibsLinks()) { + return EXIT_FAILURE; + } + if (need_extra) { fprintf(stderr, "%s must be followed by an additional argument giving a value\n", what); return EXIT_FAILURE; |