Merge "Nativeloader: Add minimal effort for host library path"

This commit is contained in:
Treehugger Robot 2018-01-08 09:40:50 +00:00 committed by Gerrit Code Review
commit 01ccde321f

View file

@ -662,22 +662,51 @@ void* OpenNativeLibrary(JNIEnv* env,
return handle; return handle;
} }
#else #else
UNUSED(env, target_sdk_version, class_loader, library_path); UNUSED(env, target_sdk_version, class_loader);
*needs_native_bridge = false;
void* handle = dlopen(path, RTLD_NOW); // Do some best effort to emulate library-path support. It will not
if (handle == nullptr) { // work for dependencies.
if (NativeBridgeIsSupported(path)) { //
*needs_native_bridge = true; // Note: null has a special meaning and must be preserved.
handle = NativeBridgeLoadLibrary(path, RTLD_NOW); std::string c_library_path; // Empty string by default.
if (handle == nullptr) { if (library_path != nullptr && path != nullptr && path[0] != '/') {
*error_msg = NativeBridgeGetError(); 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_arg, RTLD_NOW);
if (handle != nullptr) {
return handle;
}
*error_msg = NativeBridgeGetError();
} else { } else {
*needs_native_bridge = false;
*error_msg = dlerror(); *error_msg = dlerror();
} }
} }
return handle; return nullptr;
#endif #endif
} }