aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-11-23 09:22:19 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-11-25 02:26:24 +0000
commit760a37d60a79c8b4fcf91009d92e8fdfb7bdba6f (patch)
tree964f504c6d9e8a6572429da48310ea325dba2a81
parentcf8ff9df89fec1df805ddd85bd1d27c36bfece55 (diff)
Revert "masm: Treat Android as generic Posix regarding mmap and friends"
This reverts commit ffecc122d785de9c4c5defd8724526b8dd4982dc. It turns out that madvise() only fails when given MADV_WILLNEED as argument on the affected devices. MADV_WILLNEED is indeed optional. Since commit 2034e10c9378364ecc7aa1af27505562d86688de we do not crash on a failed MADV_WILLNEED anymore. Therefore, we can re-enable the linux code path for android. Task-number: QTBUG-107774 Task-number: QTBUG-106864 Task-number: QTBUG-106269 Change-Id: If67a38e4fc206bd5d5ed0ef8bf66ededd09d8f59 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit ac4fea75379467dde9065825d3f15da3b86e9ad8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/3rdparty/masm/wtf/OSAllocatorPosix.cpp23
-rw-r--r--src/qml/memory/qv4mm.cpp2
2 files changed, 8 insertions, 17 deletions
diff --git a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
index 5b5c0b23bb..b5c5f6a2b0 100644
--- a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
+++ b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
@@ -37,16 +37,7 @@
#include <wtf/Assertions.h>
#include <wtf/UnusedParam.h>
-// Android does not really behave like linux here.
-// For example, madvise() randomly fails if we pass MADV_WILLNEED or MADV_DONTNEED.
-// Treat it as generic Posix.
-#if OS(LINUX) && !defined(__ANDROID__)
-#define NON_ANDROID_LINUX 1
-#else
-#define NON_ANDROID_LINUX 0
-#endif
-
-#if NON_ANDROID_LINUX
+#if OS(LINUX)
#include <sys/syscall.h>
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
@@ -95,7 +86,7 @@ static int memfdForUsage(size_t bytes, OSAllocator::Usage usage)
close(fd);
return -1;
}
-#elif NON_ANDROID_LINUX
+#elif OS(LINUX)
static int memfdForUsage(size_t bytes, OSAllocator::Usage usage)
{
UNUSED_PARAM(bytes);
@@ -111,7 +102,7 @@ void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable,
void* result = mmap(0, bytes, PROT_NONE, MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
if (result == MAP_FAILED)
CRASH();
-#elif NON_ANDROID_LINUX
+#elif OS(LINUX)
UNUSED_PARAM(writable);
UNUSED_PARAM(executable);
int fd = memfdForUsage(bytes, usage);
@@ -157,7 +148,7 @@ void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bo
#if OS(DARWIN)
int fd = usage;
-#elif NON_ANDROID_LINUX
+#elif OS(LINUX)
int fd = memfdForUsage(bytes, usage);
if (fd != -1)
flags &= ~MAP_ANON;
@@ -205,7 +196,7 @@ void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bo
mmap(static_cast<char*>(result) + bytes - pageSize(), pageSize(), PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, fd, 0);
}
-#if NON_ANDROID_LINUX
+#if OS(LINUX)
if (fd != -1)
close(fd);
#endif
@@ -223,7 +214,7 @@ void OSAllocator::commit(void* address, size_t bytes, bool writable, bool execut
protection |= PROT_EXEC;
if (MAP_FAILED == mmap(address, bytes, protection, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0))
CRASH();
-#elif NON_ANDROID_LINUX
+#elif OS(LINUX)
int protection = PROT_READ;
if (writable)
protection |= PROT_WRITE;
@@ -255,7 +246,7 @@ void OSAllocator::decommit(void* address, size_t bytes)
#if OS(QNX)
// 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 NON_ANDROID_LINUX
+#elif OS(LINUX)
while (madvise(address, bytes, MADV_DONTNEED)) {
if (errno != EAGAIN)
CRASH();
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index 9caedccbe7..216a82718b 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -177,7 +177,7 @@ struct MemorySegment {
size_t pageSize = WTF::pageSize();
size = (size + pageSize - 1) & ~(pageSize - 1);
-#if (!defined(Q_OS_LINUX) && !defined(Q_OS_WIN)) || defined(Q_OS_ANDROID)
+#if !defined(Q_OS_LINUX) && !defined(Q_OS_WIN)
// Linux and Windows zero out pages that have been decommitted and get committed again.
// unfortunately that's not true on other OSes (e.g. BSD based ones), so zero out the
// memory before decommit, so that we can be sure that all chunks we allocate will be