diff --git a/Source/Interface/Core/BlockCache.cpp b/Source/Interface/Core/BlockCache.cpp index c665892e6..4ba00362d 100644 --- a/Source/Interface/Core/BlockCache.cpp +++ b/Source/Interface/Core/BlockCache.cpp @@ -28,6 +28,9 @@ BlockCache::BlockCache(FEXCore::Context::Context *CTX) // Can end up being inefficient if we compile a small number of blocks per page PageMemory = reinterpret_cast(mmap(nullptr, CODE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); LogMan::Throw::A(PageMemory != -1ULL, "Failed to allocate page memory"); + + MemoryBase = ctx->MemoryMapper.GetBaseOffset(0); + VirtualMemSize = ctx->Config.VirtualMemSize; } BlockCache::~BlockCache() { diff --git a/Source/Interface/Core/BlockCache.h b/Source/Interface/Core/BlockCache.h index 6992d6425..b6be34f31 100644 --- a/Source/Interface/Core/BlockCache.h +++ b/Source/Interface/Core/BlockCache.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "Interface/Context/Context.h" #include "LogManager.h" namespace FEXCore { @@ -33,6 +33,12 @@ public: } uintptr_t AddBlockMapping(uint64_t Address, void *Ptr) { + if (ctx->Config.UnifiedMemory) { + LogMan::Throw::A(Address >= MemoryBase, "Code Address before Memory Base"); + LogMan::Throw::A(Address < (MemoryBase + VirtualMemSize), "Code address after memory base"); + Address -= MemoryBase; + } + uint64_t PageOffset = Address & (0x0FFF); Address >>= 12; uintptr_t *Pointers = reinterpret_cast(PagePointer); @@ -79,6 +85,12 @@ private: } uintptr_t FindCodePointerForAddress(uint64_t Address) { + if (ctx->Config.UnifiedMemory) { + LogMan::Throw::A(!(Address < MemoryBase), "Code Address before Memory Base"); + LogMan::Throw::A(!(Address > (MemoryBase + VirtualMemSize)), "Code address after memory base"); + Address -= MemoryBase; + } + uint64_t PageOffset = Address & (0x0FFF); Address >>= 12; uintptr_t *Pointers = reinterpret_cast(PagePointer); @@ -101,6 +113,8 @@ private: size_t AllocateOffset {}; FEXCore::Context::Context *ctx; + uintptr_t MemoryBase{}; + uint64_t VirtualMemSize{}; }; }