LibC: mmap returns MAP_FAILED instead of NULL

This commit is contained in:
Bananymous 2023-09-29 10:38:08 +03:00
parent 7e9e4c47ae
commit 376b9f7272
2 changed files with 5 additions and 3 deletions

View File

@ -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;

View File

@ -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;
}