27#if REX_PLATFORM_ANDROID
29REX_API void AndroidInitialize();
44enum class PageAccess : u8 {
47 kReadWrite = kReadOnly | 1 << 1,
48 kExecuteReadOnly = kReadOnly | 1 << 2,
49 kExecuteReadWrite = kReadWrite | 1 << 2,
97 PageAccess* out_old_access =
nullptr);
116#if REX_PLATFORM_WIN32
117 return reinterpret_cast<T*
>(_aligned_malloc(
sizeof(T), alignment));
120 if (posix_memalign(&ptr, alignment,
sizeof(T))) {
123 return reinterpret_cast<T*
>(ptr);
134#if REX_PLATFORM_WIN32
141#if REX_PLATFORM_WIN32
162 PageAccess access,
bool commit);
191 PageAccess access,
size_t file_offset);
203 return reinterpret_cast<void*
>(
reinterpret_cast<u64
>(address) & 0xFFFFFFFF);
213 enum class Mode : u8 {
225 static std::unique_ptr<MappedMemory>
Open(
const std::filesystem::path& path, Mode mode,
226 size_t offset = 0,
size_t length = 0);
228 MappedMemory() =
default;
239 std::unique_ptr<MappedMemory>
Range(
size_t offset,
size_t length)
const {
240 return std::make_unique<MappedMemory>(
GetData() + offset, length);
244 u8*
GetData()
const {
return reinterpret_cast<u8*
>(data_); }
246 size_t GetSize()
const {
return size_; }
253 virtual void Close(u64 truncate_size = 0) { (void)truncate_size; }
255 virtual void Flush() {}
264 virtual bool Remap(
size_t offset,
size_t length) {
271 void* data_ =
nullptr;
286 static std::unique_ptr<ChunkedMappedMemoryWriter>
Open(
const std::filesystem::path& path,
288 bool low_address_space =
false);
298 virtual void Flush() = 0;
310 bool low_address_space)
311 : path_(path), chunk_size_(chunk_size), low_address_space_(low_address_space) {}
313 std::filesystem::path path_;
315 bool low_address_space_;
static std::unique_ptr< ChunkedMappedMemoryWriter > Open(const std::filesystem::path &path, size_t chunk_size, bool low_address_space=false)
ChunkedMappedMemoryWriter(const std::filesystem::path &path, size_t chunk_size, bool low_address_space)
Definition virtual_memory.h:309
virtual void FlushNew()=0
virtual u8 * Allocate(size_t length)=0
Definition virtual_memory.h:211
virtual bool Remap(size_t offset, size_t length)
Definition virtual_memory.h:264
std::unique_ptr< MappedMemory > Range(size_t offset, size_t length) const
Definition virtual_memory.h:239
MappedMemory(void *data, size_t size)
Definition virtual_memory.h:231
u8 * GetData() const
Definition virtual_memory.h:244
static std::unique_ptr< MappedMemory > Open(const std::filesystem::path &path, Mode mode, size_t offset=0, size_t length=0)
virtual void Close(u64 truncate_size=0)
Definition virtual_memory.h:253
T * AlignedAlloc(size_t alignment)
Definition virtual_memory.h:115
void AlignedFree(T *ptr)
Definition virtual_memory.h:133
int FileMappingHandle
Definition virtual_memory.h:148
std::filesystem::path CreateFileMappingName(std::string_view prefix)
bool UnmapFileView(FileMappingHandle handle, void *base_address, size_t length)
void * AllocFixed(void *base_address, size_t length, AllocationType allocation_type, PageAccess access)
size_t GetAllocationGranularity()
AllocationType
Definition virtual_memory.h:53
@ kCommit
Definition virtual_memory.h:55
@ kReserve
Definition virtual_memory.h:54
bool Protect(void *base_address, size_t length, PageAccess access, PageAccess *out_old_access=nullptr)
bool DeallocFixed(void *base_address, size_t length, DeallocationType deallocation_type)
bool QueryProtect(void *base_address, size_t &length, PageAccess &out_access)
FileMappingHandle CreateFileMappingHandle(const std::filesystem::path &path, size_t length, PageAccess access, bool commit)
void RemoveStaleFileMappings(std::string_view prefix)
bool IsWritableExecutableMemorySupported()
constexpr FileMappingHandle kFileMappingHandleInvalid
Definition virtual_memory.h:150
DeallocationType
Definition virtual_memory.h:60
@ kRelease
Definition virtual_memory.h:61
@ kDecommit
Definition virtual_memory.h:62
void * MapFileView(FileMappingHandle handle, void *base_address, size_t length, PageAccess access, size_t file_offset)
void CloseFileMappingHandle(FileMappingHandle handle, const std::filesystem::path &path)
void * LowAddress(void *address)
Definition virtual_memory.h:201
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.