This commit is contained in:
Nils O. Selåsdal
2026-06-09 11:36:27 +02:00
parent a092599a1a
commit b06b78aeef
6 changed files with 40 additions and 29 deletions
+9 -4
View File
@@ -13,7 +13,6 @@ U32 platform_page_size(void)
return getpagesize();
}
void *platform_malloc(size_t size)
{
return malloc(size);
@@ -24,16 +23,22 @@ void platform_free(void *mem)
free(mem);
}
void *memory_allocate(size_t size)
void *memory_allocate_and_commit(size_t size)
{
Assert(IsPow2(size));
Assert(IsPageAligned(size));
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
TRACEF("memory_allocate size=%7zu mem=%p\n", size, mem);
if (mem == MAP_FAILED) {
mem = NULL;
} else {
int rc = madvise(mem, size, MADV_POPULATE_WRITE);
if (rc != 0) {
munmap(mem, size);
mem = NULL;
}
}
return mem;
}