diff options
| author | Andreas Gampe <agampe@google.com> | 2017-12-28 19:08:13 -0800 |
|---|---|---|
| committer | Andreas Gampe <agampe@google.com> | 2018-01-02 09:05:55 -0800 |
| commit | 5c7d582be4054eaf846a5b1cf49a41ff83f52232 (patch) | |
| tree | 5ff6b8bd0a8cc9f293aa0805034f86457f647d3a /libnativeloader | |
| parent | 93d344d98cd02d66c3aac8067718be828ea283f9 (diff) | |
| download | system_core-5c7d582be4054eaf846a5b1cf49a41ff83f52232.tar.gz system_core-5c7d582be4054eaf846a5b1cf49a41ff83f52232.tar.bz2 system_core-5c7d582be4054eaf846a5b1cf49a41ff83f52232.zip | |
Nativeloader: Add minimal effort for host library path
Attempt to (somewhat) support the given library path on a non-Android
device. Iterate through the given list and construct a complete path.
This will of course not handle dependencies correctly and is best
effort.
Required (and enough) for agent-related testing in ART.
Bug: 70901841
Test: m
Change-Id: I9ecb27d662c8a2c79a70b6c5464483c449c5d034
Diffstat (limited to 'libnativeloader')
| -rw-r--r-- | libnativeloader/native_loader.cpp | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index e9f0c0fca..6ddec4d8a 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -662,22 +662,51 @@ void* OpenNativeLibrary(JNIEnv* env, return handle; } #else - UNUSED(env, target_sdk_version, class_loader, library_path); - *needs_native_bridge = false; - void* handle = dlopen(path, RTLD_NOW); - if (handle == nullptr) { - if (NativeBridgeIsSupported(path)) { + UNUSED(env, target_sdk_version, class_loader); + + // Do some best effort to emulate library-path support. It will not + // work for dependencies. + // + // Note: null has a special meaning and must be preserved. + std::string c_library_path; // Empty string by default. + if (library_path != nullptr && path != nullptr && path[0] != '/') { + ScopedUtfChars library_path_utf_chars(env, library_path); + c_library_path = library_path_utf_chars.c_str(); + } + + std::vector<std::string> library_paths = base::Split(c_library_path, ":"); + + for (const std::string& lib_path : library_paths) { + *needs_native_bridge = false; + const char* path_arg; + std::string complete_path; + if (path == nullptr) { + // Preserve null. + path_arg = nullptr; + } else { + complete_path = lib_path; + if (!complete_path.empty()) { + complete_path.append("/"); + } + complete_path.append(path); + path_arg = complete_path.c_str(); + } + void* handle = dlopen(path_arg, RTLD_NOW); + if (handle != nullptr) { + return handle; + } + if (NativeBridgeIsSupported(path_arg)) { *needs_native_bridge = true; - handle = NativeBridgeLoadLibrary(path, RTLD_NOW); - if (handle == nullptr) { - *error_msg = NativeBridgeGetError(); + handle = NativeBridgeLoadLibrary(path_arg, RTLD_NOW); + if (handle != nullptr) { + return handle; } + *error_msg = NativeBridgeGetError(); } else { - *needs_native_bridge = false; *error_msg = dlerror(); } } - return handle; + return nullptr; #endif } |
