diff options
Diffstat (limited to 'runtime/jni/java_vm_ext.cc')
| -rw-r--r-- | runtime/jni/java_vm_ext.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/runtime/jni/java_vm_ext.cc b/runtime/jni/java_vm_ext.cc index e7b244b830..e54b807ca6 100644 --- a/runtime/jni/java_vm_ext.cc +++ b/runtime/jni/java_vm_ext.cc @@ -857,6 +857,7 @@ void JavaVMExt::UnloadNativeLibraries() { bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject class_loader, + jclass caller_class, std::string* error_msg) { error_msg->clear(); @@ -872,6 +873,7 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, library = libraries_->Get(path); } void* class_loader_allocator = nullptr; + std::string caller_location; { ScopedObjectAccess soa(env); // As the incoming class loader is reachable/alive during the call of this function, @@ -882,6 +884,13 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, if (class_linker->IsBootClassLoader(soa, loader.Ptr())) { loader = nullptr; class_loader = nullptr; + if (caller_class != nullptr) { + ObjPtr<mirror::Class> caller = soa.Decode<mirror::Class>(caller_class); + ObjPtr<mirror::DexCache> dex_cache = caller->GetDexCache(); + if (dex_cache != nullptr) { + caller_location = dex_cache->GetLocation()->ToModifiedUtf8(); + } + } } class_loader_allocator = class_linker->GetAllocatorForClassLoader(loader.Ptr()); @@ -964,13 +973,15 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const char* path_str = path.empty() ? nullptr : path.c_str(); bool needs_native_bridge = false; char* nativeloader_error_msg = nullptr; - void* handle = android::OpenNativeLibrary(env, - runtime_->GetTargetSdkVersion(), - path_str, - class_loader, - library_path.get(), - &needs_native_bridge, - &nativeloader_error_msg); + void* handle = android::OpenNativeLibrary( + env, + runtime_->GetTargetSdkVersion(), + path_str, + class_loader, + (caller_location.empty() ? nullptr : caller_location.c_str()), + library_path.get(), + &needs_native_bridge, + &nativeloader_error_msg); VLOG(jni) << "[Call to dlopen(\"" << path << "\", RTLD_NOW) returned " << handle << "]"; if (handle == nullptr) { |