From d5402bce2bb2509712661d8c0d3cf3ece4bfaa5b Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sun, 16 Feb 2020 00:31:44 -0800 Subject: [PATCH] Lets the block cache understand the unified address space option There is a limitation that all executable code must live above the memory base at this moment --- Source/Interface/Core/BlockCache.cpp | 3 +++ Source/Interface/Core/BlockCache.h | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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{}; }; }