From 2b49c3e4643e68d23ee667f0fe18b9691cb90e44 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 13 Sep 2020 00:36:20 -0700 Subject: [PATCH] MemMap: Check for MAP_FAILED in mmap call. --- Common/MemArenaAndroid.cpp | 2 +- Common/MemArenaPosix.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/MemArenaAndroid.cpp b/Common/MemArenaAndroid.cpp index b43a0815b2..462d1a3a94 100644 --- a/Common/MemArenaAndroid.cpp +++ b/Common/MemArenaAndroid.cpp @@ -140,7 +140,7 @@ u8* MemArena::Find4GBBase() { // 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, -1, 0); - if (base) { + if (base && base != MAP_FAILED) { INFO_LOG(SYSTEM, "base: %p", base); uint64_t aligned_base = ((uint64_t)base + 0xFFFFFFFF) & ~0xFFFFFFFFULL; INFO_LOG(SYSTEM, "aligned_base: %p", (void *)aligned_base); diff --git a/Common/MemArenaPosix.cpp b/Common/MemArenaPosix.cpp index 15647b147a..87e18c9fff 100644 --- a/Common/MemArenaPosix.cpp +++ b/Common/MemArenaPosix.cpp @@ -109,7 +109,7 @@ u8* MemArena::Find4GBBase() { // 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, -1, 0); - if (base) { + if (base && base != MAP_FAILED) { INFO_LOG(MEMMAP, "base: %p", base); uint64_t aligned_base = ((uint64_t)base + 0xFFFFFFFF) & ~0xFFFFFFFFULL; INFO_LOG(MEMMAP, "aligned_base: %p", (void *)aligned_base);