|
|
@ -6,6 +6,8 @@ |
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
#include <windows.h>
|
|
|
#include <windows.h>
|
|
|
|
|
|
#elif defined(__OPENORBIS__)
|
|
|
|
|
|
#include <orbis/libkernel.h>
|
|
|
#else
|
|
|
#else
|
|
|
#include <sys/mman.h>
|
|
|
#include <sys/mman.h>
|
|
|
#endif
|
|
|
#endif
|
|
|
@ -22,22 +24,36 @@ void* AllocateMemoryPages(std::size_t size) noexcept { |
|
|
// Probably failing to reserve is less likely than failing to commit
|
|
|
// Probably failing to reserve is less likely than failing to commit
|
|
|
base = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); |
|
|
base = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); |
|
|
} |
|
|
} |
|
|
|
|
|
#elif defined(__OPENORBIS__)
|
|
|
|
|
|
u64 align = 16384; |
|
|
|
|
|
void *addr = nullptr; |
|
|
|
|
|
off_t direct_mem_off; |
|
|
|
|
|
int32_t rc; |
|
|
|
|
|
if ((rc = sceKernelAllocateDirectMemory(0, sceKernelGetDirectMemorySize(), size, align, 3, &direct_mem_off)) < 0) { |
|
|
|
|
|
ASSERT(false && "sceKernelAllocateDirectMemory"); |
|
|
|
|
|
return nullptr; |
|
|
|
|
|
} |
|
|
|
|
|
if ((rc = sceKernelMapDirectMemory(&addr, size, 0x33, 0, direct_mem_off, align)) < 0) { |
|
|
|
|
|
ASSERT(false && "sceKernelMapDirectMemory"); |
|
|
|
|
|
return nullptr; |
|
|
|
|
|
} |
|
|
|
|
|
ASSERT(addr != nullptr); |
|
|
#else
|
|
|
#else
|
|
|
void* base = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); |
|
|
|
|
|
if (base == MAP_FAILED) |
|
|
|
|
|
base = nullptr; |
|
|
|
|
|
|
|
|
void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); |
|
|
|
|
|
ASSERT(addr != MAP_FAILED); |
|
|
#endif
|
|
|
#endif
|
|
|
ASSERT(base); |
|
|
|
|
|
return base; |
|
|
|
|
|
|
|
|
return addr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) noexcept { |
|
|
|
|
|
if (!base) |
|
|
|
|
|
|
|
|
void FreeMemoryPages(void* addr, [[maybe_unused]] std::size_t size) noexcept { |
|
|
|
|
|
if (!addr) |
|
|
return; |
|
|
return; |
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
ASSERT(VirtualFree(base, 0, MEM_RELEASE)); |
|
|
|
|
|
|
|
|
VirtualFree(addr, 0, MEM_RELEASE) |
|
|
|
|
|
#elif defined(__OPENORBIS__)
|
|
|
#else
|
|
|
#else
|
|
|
ASSERT(munmap(base, size) == 0); |
|
|
|
|
|
|
|
|
int rc = munmap(addr, size); |
|
|
|
|
|
ASSERT(rc == 0); |
|
|
#endif
|
|
|
#endif
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|