From 48096b18c23ceebbbfe9d3915343ebbf01a045ac Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 29 Sep 2023 10:38:08 +0300 Subject: [PATCH] LibC: mmap returns MAP_FAILED instead of NULL --- libc/malloc.cpp | 6 ++++-- libc/sys/mman.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libc/malloc.cpp b/libc/malloc.cpp index c1ac4eb636..80c9254fdf 100644 --- a/libc/malloc.cpp +++ b/libc/malloc.cpp @@ -54,10 +54,12 @@ static bool allocate_pool(size_t pool_index) assert(pool.start == nullptr); // allocate memory for pool - pool.start = (uint8_t*)mmap(nullptr, pool.size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (pool.start == nullptr) + void* new_pool = mmap(nullptr, pool.size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (new_pool == MAP_FAILED) return false; + pool.start = (uint8_t*)new_pool; + // initialize pool to single unallocated node auto* node = (malloc_node_t*)pool.start; node->allocated = false; diff --git a/libc/sys/mman.cpp b/libc/sys/mman.cpp index c34e65f2cd..73ad1d72ab 100644 --- a/libc/sys/mman.cpp +++ b/libc/sys/mman.cpp @@ -13,7 +13,7 @@ void* mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off) }; long ret = syscall(SYS_MMAP, &args); if (ret == -1) - return nullptr; + return MAP_FAILED; return (void*)ret; }