Added virtual memory on Linux

This commit is contained in:
2025-10-04 00:56:55 +01:00
parent d99da864da
commit 14321c71b8
4 changed files with 36 additions and 1 deletions

31
code/os/impl/linux/core.c Normal file
View File

@@ -0,0 +1,31 @@
U64 VM_PageSize() {
U64 result = getpagesize();
return result;
}
U64 VM_AllocationGranularity() {
U64 result = getpagesize();
return result;
}
void *VM_Reserve(U64 size) {
void *addr = mmap(0, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
void *result = (addr == MAP_FAILED) ? 0 : addr;
return result;
}
B32 VM_Commit(void *base, U64 size) {
B32 result = mprotect(base, size, PROT_READ | PROT_WRITE) == 0;
return result;
}
void VM_Decommit(void *base, U64 size) {
mprotect(base, size, PROT_NONE);
}
void VM_Release(void *base, U64 size) {
munmap(base, size);
}