From 14321c71b80507181f05b9b6c33e81ee3505c45b Mon Sep 17 00:00:00 2001 From: James Bulman Date: Sat, 4 Oct 2025 00:56:55 +0100 Subject: [PATCH] Added virtual memory on Linux --- code/core/platform.h | 2 ++ code/os/core.c | 2 ++ code/os/impl/linux/core.c | 31 +++++++++++++++++++++++++++++++ linux | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 code/os/impl/linux/core.c diff --git a/code/core/platform.h b/code/core/platform.h index a6cbda1..5047a9f 100644 --- a/code/core/platform.h +++ b/code/core/platform.h @@ -71,6 +71,8 @@ #pragma warning(disable : 4201) #elif OS_LINUX #include + #include + #include #endif #endif // LD_CORE_PLATFORM_H_ diff --git a/code/os/core.c b/code/os/core.c index e442952..0ebb8a9 100644 --- a/code/os/core.c +++ b/code/os/core.c @@ -1,3 +1,5 @@ #if OS_WINDOWS #include "impl/windows/core.c" +#elif OS_LINUX + #include "impl/linux/core.c" #endif diff --git a/code/os/impl/linux/core.c b/code/os/impl/linux/core.c new file mode 100644 index 0000000..1dd1cd9 --- /dev/null +++ b/code/os/impl/linux/core.c @@ -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); +} + + diff --git a/linux b/linux index b44be73..2930c89 100755 --- a/linux +++ b/linux @@ -37,7 +37,7 @@ fi 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" if [[ $release == 1 ]]