From 163ed5b5f744f49a6b2f678c8b3fa0d29d077e55 Mon Sep 17 00:00:00 2001 From: Andrew Church Date: Sat, 19 Dec 2020 19:45:42 +0900 Subject: [PATCH] Linux: Properly avoid committing address space for large mmap(). A shared or writable mapping is charged to the process's memory commitment regardless of MAP_NORESERVE, so the mmap() call to find a 4G base can still fail depending on memory usage and overcommit settings. --- Common/MemArenaPosix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/MemArenaPosix.cpp b/Common/MemArenaPosix.cpp index 65a812001b..a33cb333bd 100644 --- a/Common/MemArenaPosix.cpp +++ b/Common/MemArenaPosix.cpp @@ -108,7 +108,7 @@ u8* MemArena::Find4GBBase() { // aligned to 4GB for the movk trick. We can ensure that we get an aligned 4GB // address by grabbing 8GB and aligning the pointer. const uint64_t EIGHT_GIGS = 0x200000000ULL; - void *base = mmap(0, EIGHT_GIGS, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED | MAP_NORESERVE, -1, 0); + void *base = mmap(0, EIGHT_GIGS, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_NORESERVE, -1, 0); if (base && base != MAP_FAILED) { INFO_LOG(MEMMAP, "base: %p", base); uint64_t aligned_base = ((uint64_t)base + 0xFFFFFFFF) & ~0xFFFFFFFFULL;