Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3025)

Unified Diff: base/android/linker/modern_linker_jni.cc

Issue 1471023002: Linker: Do not require JNI_OnLoad in ModernLinker loads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/linker/modern_linker_jni.cc
diff --git a/base/android/linker/modern_linker_jni.cc b/base/android/linker/modern_linker_jni.cc
index 32706430746fe655dbda619b9a3e31089880400d..65aaa4fa3f4e9ab842f98547b59078ef274ae6a5 100644
--- a/base/android/linker/modern_linker_jni.cc
+++ b/base/android/linker/modern_linker_jni.cc
@@ -353,11 +353,6 @@ bool ResizeReservedAddressSpace(void* addr,
// shall register its methods. Note that lazy native method resolution
// will _not_ work after this, because Dalvik uses the system's dlsym()
// which won't see the new library, so explicit registration is mandatory.
-// Load a library with the chromium linker. This will also call its
-// JNI_OnLoad() method, which shall register its methods. Note that
-// lazy native method resolution will _not_ work after this, because
-// Dalvik uses the system's dlsym() which won't see the new library,
-// so explicit registration is mandatory.
//
// |env| is the current JNI environment handle.
// |clazz| is the static class handle for org.chromium.base.Linker,
@@ -436,20 +431,17 @@ jboolean LoadLibrary(JNIEnv* env,
return false;
}
- // Locate and then call the loaded library's JNI_OnLoad() function. Check
- // that it returns a usable JNI version.
+ // Locate and if found then call the loaded library's JNI_OnLoad() function.
using JNI_OnLoadFunctionPtr = int (*)(void* vm, void* reserved);
auto jni_onload =
reinterpret_cast<JNI_OnLoadFunctionPtr>(dlsym(handle, "JNI_OnLoad"));
- if (jni_onload == nullptr) {
- LOG_ERROR("dlsym: JNI_OnLoad: %s", dlerror());
- return false;
- }
-
- int jni_version = (*jni_onload)(s_java_vm, nullptr);
- if (jni_version < JNI_VERSION_1_4) {
- LOG_ERROR("JNI version is invalid: %d", jni_version);
- return false;
+ if (jni_onload != nullptr) {
+ // Check that JNI_OnLoad returns a usable JNI version.
+ int jni_version = (*jni_onload)(s_java_vm, nullptr);
+ if (jni_version < JNI_VERSION_1_4) {
+ LOG_ERROR("JNI version is invalid: %d", jni_version);
+ return false;
+ }
}
// Release mapping before returning so that we do not unmap reserved space.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698