summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-09-13 20:29:48 -0700
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-24 19:47:06 +0000
commit9acf8cadc98e7dc4802089d25f9149b6b03f67a0 (patch)
tree58e9ca8c4c92819e59851f8020f34ae22dfebbd3
parent4d93d2e0f2fb4929b1c7886b0d8f2bdce01ea32b (diff)
QPlugin: don't use QFile::read() if map() fails on Unix
If we can't mmap(), then libdl won't be able to either. Change-Id: I42eb903a916645db9900fffd16a492a1ac25903f Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 0be5bf3e64cee329249c1174590d6a0c1a7a543f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/plugin/qlibrary.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index a10b3db1a2..2ec32bc43b 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -252,16 +252,29 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
constexpr qint64 MaxMemoryMapSize =
Q_INT64_C(1) << (sizeof(qsizetype) > 4 ? 40 : 29);
- QByteArray data;
qsizetype fdlen = qMin(file.size(), MaxMemoryMapSize);
const char *filedata = reinterpret_cast<char *>(file.map(0, fdlen));
+#ifdef Q_OS_UNIX
if (filedata == nullptr) {
- // Try reading the data into memory instead (up to 64 MB).
+ // If we can't mmap(), then the dynamic loader won't be able to either.
+ // This can't be used as a plugin.
+ if (qt_debug_component())
+ qWarning("%s: failed to map to memory: %ls", QFile::encodeName(library).constData(),
+ qUtf16Printable(file.errorString()));
+ return false;
+ }
+#else
+ QByteArray data;
+ if (filedata == nullptr) {
+ // It's unknown at this point whether Windows supports LoadLibrary() on
+ // files that fail to CreateFileMapping / MapViewOfFile, so we err on
+ // the side of doing a regular read into memory (up to 64 MB).
data = file.read(64 * 1024 * 1024);
filedata = data.constData();
fdlen = data.size();
}
+#endif
/*
ELF and Mach-O binaries with GCC have .qplugin sections.