diff options
author | simonb <simonb@chromium.org> | 2015-11-25 04:37:42 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-25 12:38:54 +0000 |
commit | ae60ba7f8a0e7d2cc3dd208219f8b9fa4f66ef1c (patch) | |
tree | 18a84f76442ab6a1274d80d362d317d57f73d72a /base/android | |
parent | 6471a3d1de25ca888c69466bced28676eeb359a7 (diff) | |
download | chromium_src-ae60ba7f8a0e7d2cc3dd208219f8b9fa4f66ef1c.zip chromium_src-ae60ba7f8a0e7d2cc3dd208219f8b9fa4f66ef1c.tar.gz chromium_src-ae60ba7f8a0e7d2cc3dd208219f8b9fa4f66ef1c.tar.bz2 |
Linker: Do not require JNI_OnLoad in ModernLinker loads.
LegacyLinker uses the android_crazy_linker to load libraries.
The crazy linker calls JNI_OnLoad if present, but does not
fail the load if it is not present.
Current ModernLinker will fail if the loaded library does not
contain JNI_OnLoad. Change ModernLinker to match the crazy
linker behaviour here.
Ref:
https://code.google.com/p/chromium/codesearch#chromium/src/third_party/android_crazy_linker/src/src/crazy_linker_shared_library.cpp&l=444
Additionally, fix nearby comment cut-and-paste error.
Review URL: https://codereview.chromium.org/1471023002
Cr-Commit-Position: refs/heads/master@{#361633}
Diffstat (limited to 'base/android')
-rw-r--r-- | base/android/linker/modern_linker_jni.cc | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/base/android/linker/modern_linker_jni.cc b/base/android/linker/modern_linker_jni.cc index 3270643..65aaa4f 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. |