diff --git a/Source/Windows/ARM64EC/Module.cpp b/Source/Windows/ARM64EC/Module.cpp index 241da1038..c628cfc27 100644 --- a/Source/Windows/ARM64EC/Module.cpp +++ b/Source/Windows/ARM64EC/Module.cpp @@ -619,7 +619,7 @@ NTSTATUS ProcessInit() { CPUFeatures.emplace(*CTX); - X64ReturnInstr = ::VirtualAlloc(nullptr, FEXCore::Utils::FEX_PAGE_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + X64ReturnInstr = ::VirtualAlloc(nullptr, FEXCore::Utils::FEX_PAGE_SIZE, MEM_COMMIT | MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); InvalidationTracker->HandleMemoryProtectionNotification(reinterpret_cast(X64ReturnInstr), FEXCore::Utils::FEX_PAGE_SIZE, PAGE_EXECUTE_READ); *reinterpret_cast(X64ReturnInstr) = 0xc3; @@ -919,7 +919,8 @@ NTSTATUS ThreadInit() { const auto CPUArea = GetCPUArea(); static constexpr size_t EmulatorStackSize = 0x40000; - const uint64_t EmulatorStack = reinterpret_cast(::VirtualAlloc(nullptr, EmulatorStackSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)); + const uint64_t EmulatorStack = + reinterpret_cast(::VirtualAlloc(nullptr, EmulatorStackSize, MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE)); CPUArea.EmulatorStackLimit() = EmulatorStack; CPUArea.EmulatorStackBase() = EmulatorStack + EmulatorStackSize; diff --git a/Source/Windows/Common/CallRetStack.h b/Source/Windows/Common/CallRetStack.h index d2ddee3e0..215591b39 100644 --- a/Source/Windows/Common/CallRetStack.h +++ b/Source/Windows/Common/CallRetStack.h @@ -22,8 +22,8 @@ CallRetStackInfo GetInfoThread(FEXCore::Core::InternalThreadState* Thread) { void InitializeThread(FEXCore::Core::InternalThreadState* Thread) { // Allocate the call-ret stack with guard pages on both sides - const void* CallRetStackAlloc = ::VirtualAlloc( - nullptr, FEXCore::Core::InternalThreadState::CALLRET_STACK_SIZE + 2 * FEXCore::Utils::FEX_PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS); + const void* CallRetStackAlloc = ::VirtualAlloc(nullptr, FEXCore::Core::InternalThreadState::CALLRET_STACK_SIZE + 2 * FEXCore::Utils::FEX_PAGE_SIZE, + MEM_RESERVE | MEM_TOP_DOWN, PAGE_NOACCESS); FEXCore::Allocator::VirtualName("FEXMem_CallRetStacks", CallRetStackAlloc, FEXCore::Core::InternalThreadState::CALLRET_STACK_SIZE + 2 * FEXCore::Utils::FEX_PAGE_SIZE);