force NO fastmem

This commit is contained in:
lizzie 2025-12-01 20:07:43 +00:00
parent 9051fcb33b
commit 5d1e74533c
2 changed files with 39 additions and 17 deletions

View file

@ -6,6 +6,8 @@
#ifdef _WIN32
#include <windows.h>
#elif defined(__OPENORBIS__)
#include <orbis/libkernel.h>
#else
#include <sys/mman.h>
#endif
@ -17,23 +19,38 @@ namespace Common {
void* AllocateMemoryPages(std::size_t size) noexcept {
#ifdef _WIN32
void* base = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
void* addr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
ASSERT(addr != nullptr);
#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
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
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;
#ifdef _WIN32
ASSERT(VirtualFree(base, 0, MEM_RELEASE));
VirtualFree(addr, 0, MEM_RELEASE)
#elif defined(__OPENORBIS__)
#else
ASSERT(munmap(base, size) == 0);
int rc = munmap(addr, size);
ASSERT(rc == 0);
#endif
}