Skip to content

Commit 5c42f57

Browse files
napaalmQt Cherry-pick Bot
authored andcommitted
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 524d260) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 1ead022) (cherry picked from commit a2e0061)
1 parent e52edaf commit 5c42f57

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/3rdparty/masm/wtf/OSAllocatorPosix.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable,
114114
if (result == MAP_FAILED)
115115
CRASH();
116116

117-
while (madvise(result, bytes, MADV_DONTNEED)) {
118-
if (errno != EAGAIN)
119-
CRASH();
120-
}
117+
while (madvise(result, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
121118

122119
if (fd != -1)
123120
close(fd);
@@ -250,8 +247,10 @@ void OSAllocator::decommit(void* address, size_t bytes)
250247
mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
251248
#elif OS(LINUX)
252249
while (madvise(address, bytes, MADV_DONTNEED)) {
253-
if (errno != EAGAIN)
254-
CRASH();
250+
if (errno != EAGAIN) {
251+
memset(address, 0, bytes); // We rely on madvise to zero-out the memory
252+
break;
253+
}
255254
}
256255
if (mprotect(address, bytes, PROT_NONE))
257256
CRASH();

0 commit comments

Comments
 (0)