Added virtual memory on Linux

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

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
#if OS_WINDOWS
#include "impl/windows/core.c"
#elif OS_LINUX
#include "impl/linux/core.c"
#endif
+31
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);
}