Skip to content

Commit

Permalink
QML: Protect against EAGAIN when calling madvise on linux
Browse files Browse the repository at this point in the history
Apparently it can fail with EAGAIN. We rely on madvise to zero out the
memory. Therefore loop until it succeeds like we do on other OS.

Fixes: QTBUG-100431
Change-Id: I9819f8d82a251e222b0b500991584d40e641b672
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 6aef29a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
Ulf Hermann authored and Qt Cherry-pick Bot committed Mar 26, 2022
1 parent d76efbe commit f4a55f7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable,
(fd == -1 ? MAP_ANON : 0), fd, 0);
if (result == MAP_FAILED)
CRASH();
madvise(result, bytes, MADV_DONTNEED);

while (madvise(result, bytes, MADV_DONTNEED)) {
if (errno != EAGAIN)
CRASH();
}

if (fd != -1)
close(fd);
Expand Down Expand Up @@ -218,7 +222,12 @@ void OSAllocator::commit(void* address, size_t bytes, bool writable, bool execut
protection |= PROT_EXEC;
if (mprotect(address, bytes, protection))
CRASH();
madvise(address, bytes, MADV_WILLNEED);

while (madvise(address, bytes, MADV_WILLNEED)) {
if (errno != EAGAIN)
CRASH();
}

#elif HAVE(MADV_FREE_REUSE)
UNUSED_PARAM(writable);
UNUSED_PARAM(executable);
Expand All @@ -238,7 +247,10 @@ void OSAllocator::decommit(void* address, size_t bytes)
// Use PROT_NONE and MAP_LAZY to decommit the pages.
mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
#elif OS(LINUX)
madvise(address, bytes, MADV_DONTNEED);
while (madvise(address, bytes, MADV_DONTNEED)) {
if (errno != EAGAIN)
CRASH();
}
if (mprotect(address, bytes, PROT_NONE))
CRASH();
#elif HAVE(MADV_FREE_REUSE)
Expand Down

0 comments on commit f4a55f7

Please sign in to comment.