aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Napolitano <anton@polit.no>2023-12-30 19:11:32 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-01-31 18:19:31 +0000
commit5c42f57e88681be521e3d59f9e527d3bcd4d5732 (patch)
treef4f07d9618a77a9326e01342c3a0779842adf97a
parente52edaf1ba9c31491d7fe7e650dd5668bb313695 (diff)
masm: Don't crash on failed MADV_DONTNEED on Linux
The application could call mlockall(MCL_CURRENT|MCL_FUTURE) to lock all its memory for performance reasons, causing the madvise call to fail. There's no need to crash. Instead, manually zero-out the memory when decommitting. Fixes: QTBUG-120450 Pick-to: 6.2 5.15 Change-Id: I6f1a8968853cc5e61561371bd2a435a686eaf0e4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 524d260c5c135d193e06350e48357444ddb13ddb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 1ead022dfea5a6b3bed8ca80de85c20cea6c809f) (cherry picked from commit a2e0061317954fdab6f9af1ab0490944bca33873)
-rw-r--r--src/3rdparty/masm/wtf/OSAllocatorPosix.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
index a8990a92b4..e183d434bd 100644
--- a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
+++ b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
@@ -114,10 +114,7 @@ void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable,
if (result == MAP_FAILED)
CRASH();
- while (madvise(result, bytes, MADV_DONTNEED)) {
- if (errno != EAGAIN)
- CRASH();
- }
+ while (madvise(result, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
if (fd != -1)
close(fd);
@@ -250,8 +247,10 @@ void OSAllocator::decommit(void* address, size_t bytes)
mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
#elif OS(LINUX)
while (madvise(address, bytes, MADV_DONTNEED)) {
- if (errno != EAGAIN)
- CRASH();
+ if (errno != EAGAIN) {
+ memset(address, 0, bytes); // We rely on madvise to zero-out the memory
+ break;
+ }
}
if (mprotect(address, bytes, PROT_NONE))
CRASH();