Rename os memory functions

This commit is contained in:
2025-12-29 23:29:40 +00:00
parent 2372ae6675
commit 52303c81ae
5 changed files with 18 additions and 18 deletions

View File

@@ -45,8 +45,8 @@ b8 wapp_mem_arena_init_custom(Arena **arena, u64 base_capacity, MemAllocFlags fl
ARENA_MINIMUM_CAPACITY ARENA_MINIMUM_CAPACITY
); );
arena_ptr->buf = (u8 *)wapp_mem_util_alloc(NULL, arena_capacity, WAPP_MEM_ACCESS_READ_WRITE, flags, arena_ptr->buf = (u8 *)wapp_os_mem_alloc(NULL, arena_capacity, WAPP_MEM_ACCESS_READ_WRITE, flags,
zero_buffer ? WAPP_MEM_INIT_INITIALISED : WAPP_MEM_INIT_UNINITIALISED); zero_buffer ? WAPP_MEM_INIT_INITIALISED : WAPP_MEM_INIT_UNINITIALISED);
if (!(arena_ptr->buf)) { if (!(arena_ptr->buf)) {
wapp_mem_arena_destroy(arena); wapp_mem_arena_destroy(arena);
@@ -78,9 +78,9 @@ void *wapp_mem_arena_alloc_aligned(Arena *arena, u64 size, u64 alignment) {
#ifdef WAPP_PLATFORM_WINDOWS #ifdef WAPP_PLATFORM_WINDOWS
if (!(arena->committed)) { if (!(arena->committed)) {
wapp_mem_util_alloc(alloc_start, (uptr)(arena->offset) - (uptr)(alloc_start), wapp_os_mem_alloc(alloc_start, (uptr)(arena->offset) - (uptr)(alloc_start),
WAPP_MEM_ACCESS_READ_WRITE, WAPP_MEM_ALLOC_COMMIT, WAPP_MEM_ACCESS_READ_WRITE, WAPP_MEM_ALLOC_COMMIT,
WAPP_MEM_INIT_UNINITIALISED); WAPP_MEM_INIT_UNINITIALISED);
} }
#endif // ifdef WAPP_PLATFORM_WINDOWS #endif // ifdef WAPP_PLATFORM_WINDOWS
@@ -135,7 +135,7 @@ void wapp_mem_arena_destroy(Arena **arena) {
Arena *arena_ptr = *arena; Arena *arena_ptr = *arena;
if (arena_ptr->buf) { if (arena_ptr->buf) {
wapp_mem_util_free(arena_ptr->buf, arena_ptr->capacity); wapp_os_mem_free(arena_ptr->buf, arena_ptr->capacity);
} }
arena_ptr->buf = arena_ptr->offset = NULL; arena_ptr->buf = arena_ptr->offset = NULL;

View File

@@ -15,8 +15,8 @@
#error "Unrecognised platform" #error "Unrecognised platform"
#endif #endif
void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type) { void *wapp_os_mem_alloc(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type) {
void *output = mem_util_allocate(addr, size, access, flags, type); void *output = os_mem_allocate(addr, size, access, flags, type);
if (type == WAPP_MEM_INIT_INITIALISED) { if (type == WAPP_MEM_INIT_INITIALISED) {
memset(output, 0, size); memset(output, 0, size);
@@ -25,6 +25,6 @@ void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access, MemAllocFlags
return output; return output;
} }
void wapp_mem_util_free(void *ptr, u64 size) { void wapp_os_mem_free(void *ptr, u64 size) {
mem_util_free(ptr, size); os_mem_free(ptr, size);
} }

View File

@@ -20,11 +20,11 @@ BEGIN_C_LINKAGE
#error "Unrecognised platform" #error "Unrecognised platform"
#endif #endif
void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type); void *wapp_os_mem_alloc(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
void wapp_mem_util_free(void *ptr, u64 size); void wapp_os_mem_free(void *ptr, u64 size);
wapp_extern void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type); wapp_extern void *os_mem_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
wapp_extern void mem_util_free(void *ptr, u64 size); wapp_extern void os_mem_free(void *ptr, u64 size);
#ifdef WAPP_PLATFORM_CPP #ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE END_C_LINKAGE

View File

@@ -18,7 +18,7 @@ wapp_intern const i32 access_types[] = {
[WAPP_MEM_ACCESS_READ_WRITE_EXEC] = PROT_READ | PROT_WRITE | PROT_EXEC, [WAPP_MEM_ACCESS_READ_WRITE_EXEC] = PROT_READ | PROT_WRITE | PROT_EXEC,
}; };
void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type) { void *os_mem_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type) {
(void)type; (void)type;
i32 alloc_flags = flags | MAP_ANON | MAP_PRIVATE; i32 alloc_flags = flags | MAP_ANON | MAP_PRIVATE;
@@ -29,7 +29,7 @@ void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags fl
return mmap(addr, size, access_types[access], alloc_flags, -1, 0); return mmap(addr, size, access_types[access], alloc_flags, -1, 0);
} }
void mem_util_free(void *ptr, u64 size) { void os_mem_free(void *ptr, u64 size) {
munmap(ptr, size); munmap(ptr, size);
} }

View File

@@ -21,7 +21,7 @@ wapp_intern const i32 access_types[] = {
[WAPP_MEM_ACCESS_READ_WRITE_EXEC] = PAGE_EXECUTE_READWRITE, [WAPP_MEM_ACCESS_READ_WRITE_EXEC] = PAGE_EXECUTE_READWRITE,
}; };
void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type) { void *os_mem_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type) {
// Ensure memory is committed if it's meant to be initialised // Ensure memory is committed if it's meant to be initialised
if (type == WAPP_MEM_INIT_INITIALISED) { if (type == WAPP_MEM_INIT_INITIALISED) {
flags |= WAPP_MEM_ALLOC_COMMIT; flags |= WAPP_MEM_ALLOC_COMMIT;
@@ -30,7 +30,7 @@ void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags fl
return VirtualAlloc(addr, (SIZE_T)size, flags, access_types[access]); return VirtualAlloc(addr, (SIZE_T)size, flags, access_types[access]);
} }
void mem_util_free(void *ptr, u64 size) { void os_mem_free(void *ptr, u64 size) {
VirtualFree(ptr, size, MEM_RELEASE); VirtualFree(ptr, size, MEM_RELEASE);
} }