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

View File

@@ -71,6 +71,8 @@
#pragma warning(disable : 4201) #pragma warning(disable : 4201)
#elif OS_LINUX #elif OS_LINUX
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/mman.h>
#include <unistd.h>
#endif #endif
#endif // LD_CORE_PLATFORM_H_ #endif // LD_CORE_PLATFORM_H_

View File

@@ -1,3 +1,5 @@
#if OS_WINDOWS #if OS_WINDOWS
#include "impl/windows/core.c" #include "impl/windows/core.c"
#elif OS_LINUX
#include "impl/linux/core.c"
#endif #endif

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

2
linux
View File

@@ -37,7 +37,7 @@ fi
echo "[Building source]" echo "[Building source]"
COMPILER_OPTS="-Wall -Wno-missing-braces -I'deps/stb'" COMPILER_OPTS="-Wall -Wno-missing-braces -Wno-unused-function -I'deps/stb'"
LINKER_OPTS="-lSDL3" LINKER_OPTS="-lSDL3"
if [[ $release == 1 ]] if [[ $release == 1 ]]