diff --git a/FEXCore/Source/Interface/Core/CodeCache.cpp b/FEXCore/Source/Interface/Core/CodeCache.cpp index 4e3a15aa1..9ca86c3ac 100644 --- a/FEXCore/Source/Interface/Core/CodeCache.cpp +++ b/FEXCore/Source/Interface/Core/CodeCache.cpp @@ -50,6 +50,10 @@ MappedCodeCacheFile::~MappedCodeCacheFile() { if (!CodeBuffer.empty()) { FEXCore::Allocator::munmap(CodeBuffer.data(), CodeBuffer.size_bytes()); } +#elif defined(_M_ARM64EC) + if (!CodeBuffer.empty()) { + FEXCore::Allocator::VirtualFree(CodeBuffer.data(), CodeBuffer.size_bytes()); + } #endif } @@ -600,7 +604,16 @@ CodeCache::LoadCache(std::span CacheFile, const ExecutableFileInfo& F return nullptr; } auto CodeBuffer = std::span {static_cast(CodeBufferAllocation), header.CodeBufferSize}; -#else +#elif defined(_M_ARM64EC) + // TODO: Implement lazy mapping on Windows + // NOTE: The executed code must have MEM_EXTENDED_PARAMETER_EC_CODE set, so we can't operate on the mapped cache file directly + void* CodeBufferAllocation = Allocator::VirtualAlloc(header.CodeBufferSize, true); + if (!CodeBufferAllocation) { + LogMan::Msg::EFmt("Failed to allocate code cache memory"); + return nullptr; + } + auto CodeBuffer = std::span {reinterpret_cast(CodeBufferAllocation), header.CodeBufferSize}; +#else // WoW64 // TODO: Implement lazy mapping on Windows auto CodeBuffer = CodeDataInFile; #endif @@ -870,6 +883,9 @@ void CodeCache::FinalizeCodePages(MappedCodeCacheFile& Code, std::span