Add address parameter to wapp_mem_util_alloc
This commit is contained in:
parent
75bbb82058
commit
ccc86342cd
@ -19,7 +19,7 @@ internal const i32 access_types[] = {
|
||||
[WAPP_MEM_ACCESS_READ_WRITE_EXEC] = PAGE_EXECUTE_READWRITE,
|
||||
};
|
||||
|
||||
internal inline void *alloc_windows(u64 size, MemAccess access,
|
||||
internal inline void *alloc_windows(void *addr, u64 size, MemAccess access,
|
||||
MemAllocFlags flags);
|
||||
#elif defined(WAPP_PLATFORM_POSIX)
|
||||
#include <sys/mman.h>
|
||||
@ -33,7 +33,7 @@ internal const i32 access_types[] = {
|
||||
[WAPP_MEM_ACCESS_READ_WRITE_EXEC] = PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
};
|
||||
|
||||
internal inline void *alloc_posix(u64 size, MemAccess access,
|
||||
internal inline void *alloc_posix(void *addr, u64 size, MemAccess access,
|
||||
MemAllocFlags flags);
|
||||
#else
|
||||
#error "Unrecognised platform"
|
||||
@ -62,17 +62,17 @@ void *wapp_mem_util_align_forward(void *ptr, u64 alignment) {
|
||||
return (void *)p;
|
||||
}
|
||||
|
||||
void *wapp_mem_util_alloc(u64 size, MemAccess access, MemAllocFlags flags,
|
||||
MemInitType type) {
|
||||
void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access,
|
||||
MemAllocFlags flags, MemInitType type) {
|
||||
#if defined(WAPP_PLATFORM_WINDOWS)
|
||||
// Ensure memory is committed if it's meant to be initialised
|
||||
if (type == WAPP_MEM_INIT_INITIALISED) {
|
||||
flags |= WAPP_MEM_ALLOC_COMMIT;
|
||||
}
|
||||
|
||||
void *output = alloc_windows(size, access, flags);
|
||||
void *output = alloc_windows(addr, size, access, flags);
|
||||
#elif defined(WAPP_PLATFORM_POSIX)
|
||||
void *output = alloc_posix(size, access, flags);
|
||||
void *output = alloc_posix(addr, size, access, flags);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
@ -93,14 +93,14 @@ void wapp_mem_util_free(void *ptr, u64 size) {
|
||||
}
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
internal inline void *alloc_windows(u64 size, MemAccess access,
|
||||
internal inline void *alloc_windows(void *addr, u64 size, MemAccess access,
|
||||
MemAllocFlags flags) {
|
||||
return VirtualAlloc2(NULL, NULL, (SIZE_T)size, flags, access_types[access]);
|
||||
return VirtualAlloc2(addr, NULL, (SIZE_T)size, flags, access_types[access]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WAPP_PLATFORM_POSIX)
|
||||
internal inline void *alloc_posix(u64 size, MemAccess access,
|
||||
internal inline void *alloc_posix(void *addr, u64 size, MemAccess access,
|
||||
MemAllocFlags flags) {
|
||||
i32 alloc_flags = flags | MAP_ANON | MAP_PRIVATE;
|
||||
|
||||
@ -109,6 +109,6 @@ internal inline void *alloc_posix(u64 size, MemAccess access,
|
||||
alloc_flags |= MAP_NORESERVE;
|
||||
#endif
|
||||
|
||||
return mmap(NULL, size, access_types[access], alloc_flags, -1, 0);
|
||||
return mmap(addr, size, access_types[access], alloc_flags, -1, 0);
|
||||
}
|
||||
#endif
|
||||
|
@ -49,8 +49,8 @@ typedef enum mem_init_type {
|
||||
} MemInitType;
|
||||
|
||||
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
|
||||
void *wapp_mem_util_alloc(u64 size, MemAccess access, MemAllocFlags flags,
|
||||
MemInitType type);
|
||||
void *wapp_mem_util_alloc(void *addr, u64 size, MemAccess access,
|
||||
MemAllocFlags flags, MemInitType type);
|
||||
void wapp_mem_util_free(void *ptr, u64 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
Reference in New Issue
Block a user