AllocatorHooks: Mark JIT code memory as EC code on ARM64EC

Executable mapped memory is treated as x86 code by default when
running under EC, VirtualAlloc2 needs to be used together with a
special flag to map JIT arm64 code.
This commit is contained in:
Billy Laws committed 2024-04-06 12:40:52 +00:00
1 parent e8127b92e8
commit bd5b817c3a
2 files changed
+18 -4

No files matched your search

+3
View File
@@ -200,6 +200,9 @@ if (NOT MINGW_BUILD)
list (APPEND LIBS dl)
else()
list (APPEND LIBS synchronization)
if (_M_ARM_64EC)
list (APPEND LIBS kernelbase)
endif()
endif()
if (ENABLE_JEMALLOC)
+15 -4
View File
@@ -8,6 +8,7 @@
#endif
#ifdef _WIN32
#define NTDDI_VERSION 0x0A000005
#include <memoryapi.h>
#else
#include <sys/mman.h>
@@ -38,12 +39,22 @@ extern "C" {
namespace FEXCore::Allocator {
#ifdef _WIN32
inline void *VirtualAlloc(size_t Size, bool Execute = false) {
return ::VirtualAlloc(nullptr, Size, MEM_COMMIT, Execute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE);
inline void *VirtualAlloc(void* Base, size_t Size, bool Execute = false) {
#ifdef _M_ARM_64EC
MEM_EXTENDED_PARAMETER Parameter{};
if (Execute) {
Parameter.Type = MemExtendedParameterAttributeFlags;
Parameter.ULong64 = MEM_EXTENDED_PARAMETER_EC_CODE;
};
return ::VirtualAlloc2(nullptr, Base, Size, MEM_COMMIT | (Base ? MEM_RESERVE : 0), Execute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE,
&Parameter, Execute ? 1 : 0);
#else
return ::VirtualAlloc(Base, Size, MEM_COMMIT | (Base ? MEM_RESERVE : 0), Execute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE);
#endif
}
inline void *VirtualAlloc(void* Base, size_t Size, bool Execute = false) {
return ::VirtualAlloc(Base, Size, MEM_COMMIT | MEM_RESERVE, Execute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE);
inline void *VirtualAlloc(size_t Size, bool Execute = false) {
return VirtualAlloc(nullptr, Size, Execute);
}
inline void VirtualFree(void *Ptr, size_t Size) {