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>
This commit is contained in:
parent
4d93d2e0f2
commit
9acf8cadc9
@ -252,16 +252,29 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
|
|||||||
constexpr qint64 MaxMemoryMapSize =
|
constexpr qint64 MaxMemoryMapSize =
|
||||||
Q_INT64_C(1) << (sizeof(qsizetype) > 4 ? 40 : 29);
|
Q_INT64_C(1) << (sizeof(qsizetype) > 4 ? 40 : 29);
|
||||||
|
|
||||||
QByteArray data;
|
|
||||||
qsizetype fdlen = qMin(file.size(), MaxMemoryMapSize);
|
qsizetype fdlen = qMin(file.size(), MaxMemoryMapSize);
|
||||||
const char *filedata = reinterpret_cast<char *>(file.map(0, fdlen));
|
const char *filedata = reinterpret_cast<char *>(file.map(0, fdlen));
|
||||||
|
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
if (filedata == nullptr) {
|
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);
|
data = file.read(64 * 1024 * 1024);
|
||||||
filedata = data.constData();
|
filedata = data.constData();
|
||||||
fdlen = data.size();
|
fdlen = data.size();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ELF and Mach-O binaries with GCC have .qplugin sections.
|
ELF and Mach-O binaries with GCC have .qplugin sections.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user