// Adapted from Unleashed Recompiled (https://github.com/hedge-dev/UnleashedRecomp), // GPL-3.0-or-later. Modified for SpeedBreaker. #pragma once #ifndef _WIN32 #define MEM_COMMIT 0x00001000 #define MEM_RESERVE 0x00002000 #endif struct Memory { uint8_t* base{}; Memory(); bool MapPhysicalMirrors(); // Physical offset of the 0xE0000000 window: 0x1000 on hardware, 0 on // hosts whose page size can't express it (see memory.cpp). uint32_t eWindowShift = 0; // SpeedBreaker: base is null because a step failed (memory_status.h's // Failure: 1, the 4 GB reservation; 2, the physical memory mirrors) with // this error (errno; a kern_return_t for the Apple mirrors). main.cpp // says so on screen. NFSMW_TEST_RESERVE_FAIL=1 or 2 fails that step on // purpose (testing the message on any machine). int failedStep = 0; int failedError = 0; bool IsInMemoryRange(const void* host) const noexcept { return host >= base && host < (base + PPC_MEMORY_SIZE); } void* Translate(size_t offset) const noexcept { if (offset) assert(offset < PPC_MEMORY_SIZE); return base + offset; } uint32_t MapVirtual(const void* host) const noexcept { if (host) assert(IsInMemoryRange(host)); return static_cast(static_cast(host) - base); } PPCFunc* FindFunction(uint32_t guest) const noexcept { return PPC_LOOKUP_FUNC(base, guest); } void InsertFunction(uint32_t guest, PPCFunc* host) { PPC_LOOKUP_FUNC(base, guest) = host; } }; extern "C" void* MmGetHostAddress(uint32_t ptr); extern Memory g_memory;