summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-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 b67c3b6439..2c5940f8f2 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -254,16 +254,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.