diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-04-10 13:35:25 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-04-16 04:23:05 +0200 |
commit | 359df32300f5472f2fddbc83c3fe0851b5547ff6 (patch) | |
tree | 905e52db97d7dcc74b8a6d61fd8f9c8554563cde | |
parent | 8ba043cbaf38f9cddaa9d557c503ef4e3f5cbac3 (diff) |
Android: don't call JNI_OnLoad for libraries opened with QLibrary
JNI_OnLoad gets called automatically by the JVM when it loads a shared
library. A native library that is loaded by native code shouldn't have
it's JNI_OnLoad entry point function called, as that would indicate
that the plugin is loaded by the JVM, which it is not.
If framework or application code requires that function to be called
(and wants to perform error handling, such as closing the library again
if the function returns JNI_ERR), then that can and should be done
explicitly.
[ChangeLog][Android][QLibrary] Loading a shared library with QLibrary
no longer implicily calls a JNI_OnLoad implementation.
Fixes: QTBUG-92007
Pick-to: 6.7
Change-Id: I9aa71ec73b950029e0ae1be7d54e1c8576f356ab
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r-- | src/corelib/plugin/qlibrary_unix.cpp | 8 |
1 files changed, 0 insertions, 8 deletions
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 4bbfd89cd6..a6fb5403cd 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -207,14 +207,6 @@ bool QLibraryPrivate::load_sys() auto attemptFromBundle = attempt; hnd = dlopen(QFile::encodeName(attemptFromBundle.replace(u'/', u'_')), dlFlags); } - if (hnd) { - using JniOnLoadPtr = jint (*)(JavaVM *vm, void *reserved); - JniOnLoadPtr jniOnLoad = reinterpret_cast<JniOnLoadPtr>(dlsym(hnd, "JNI_OnLoad")); - if (jniOnLoad && jniOnLoad(QJniEnvironment::javaVM(), nullptr) == JNI_ERR) { - dlclose(hnd); - hnd = nullptr; - } - } #endif if (!hnd && fileName.startsWith(u'/') && QFile::exists(attempt)) { |