diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-09-13 20:29:48 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-09-24 11:40:44 -0700 |
commit | 0be5bf3e64cee329249c1174590d6a0c1a7a543f (patch) | |
tree | 5648896f19e57322f604fede098892efd2d6aa9f /src/corelib/plugin/qlibrary.cpp | |
parent | 60b0b0dedd87ab4f8a842e7f1650d5c96e731c38 (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.
Pick-to: 6.2
Change-Id: I42eb903a916645db9900fffd16a492a1ac25903f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/plugin/qlibrary.cpp')
-rw-r--r-- | src/corelib/plugin/qlibrary.cpp | 17 |
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. |