#include "../Core/PS4/Loader/Elf.h" #ifdef _WIN64 #include #else #include #endif #include "../Util/Log.h" namespace Memory { namespace VirtualMemory { u64 memory_alloc(u64 address, u64 size) { //TODO it supports only execute_read_write mode #ifdef _WIN64 auto ptr = reinterpret_cast(VirtualAlloc(reinterpret_cast(static_cast(address)), size, static_cast(MEM_COMMIT) | static_cast(MEM_RESERVE), PAGE_EXECUTE_READWRITE)); if (ptr == 0) { auto err = static_cast(GetLastError()); LOG_ERROR_IF(true, "VirtualAlloc() failed: 0x{:X}\n", err); } #else auto ptr = reinterpret_cast(mmap(reinterpret_cast(static_cast(address)), size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)); if (ptr == reinterpret_castMAP_FAILED) { LOG_ERROR_IF(true, "mmap() failed: {}\n", std::strerror(errno)); } #endif return ptr; } } }