62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#ifndef MEM_UTILS_H
|
|
#define MEM_UTILS_H
|
|
|
|
#include "aliases.h"
|
|
#include "platform.h"
|
|
|
|
#if defined(WAPP_PLATFORM_WINDOWS)
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <Windows.h>
|
|
#include <memoryapi.h>
|
|
#elif defined(WAPP_PLATFORM_POSIX)
|
|
#include <sys/mman.h>
|
|
#else
|
|
#error "Unrecognised platform"
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // __cplusplus
|
|
|
|
typedef enum mem_access {
|
|
WAPP_MEM_ACCESS_NONE,
|
|
WAPP_MEM_ACCESS_READ_ONLY,
|
|
WAPP_MEM_ACCESS_EXEC_ONLY,
|
|
WAPP_MEM_ACCESS_READ_WRITE,
|
|
WAPP_MEM_ACCESS_READ_EXEC,
|
|
WAPP_MEM_ACCESS_READ_WRITE_EXEC,
|
|
} MemAccess;
|
|
|
|
typedef enum mem_alloc_flags {
|
|
#if defined(WAPP_PLATFORM_WINDOWS)
|
|
WAPP_MEM_ALLOC_RESERVE = MEM_RESERVE,
|
|
WAPP_MEM_ALLOC_COMMIT = MEM_COMMIT,
|
|
#elif defined(WAPP_PLATFORM_LINUX) || defined(WAPP_PLATFORM_GNU)
|
|
WAPP_MEM_ALLOC_RESERVE = 0,
|
|
WAPP_MEM_ALLOC_COMMIT = MAP_POPULATE,
|
|
#elif defined(WAPP_PLATFORM_FREE_BSD)
|
|
WAPP_MEM_ALLOC_RESERVE = 0,
|
|
WAPP_MEM_ALLOC_COMMIT = MAP_PREFAULT_READ,
|
|
#elif defined(WAPP_PLATFORM_BSD) || defined(WAPP_PLATFORM_UNIX) || \
|
|
defined(WAPP_PLATFORM_APPLE)
|
|
WAPP_MEM_ALLOC_RESERVE = 0,
|
|
WAPP_MEM_ALLOC_COMMIT = 0,
|
|
#endif
|
|
} MemAllocFlags;
|
|
|
|
typedef enum mem_init_type {
|
|
WAPP_MEM_INIT_UNINITIALISED,
|
|
WAPP_MEM_INIT_INITIALISED,
|
|
} MemInitType;
|
|
|
|
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
|
|
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
|
|
}
|
|
#endif // __cplusplus
|
|
|
|
#endif // !MEM_UTILS_H
|