ARM64EC: Implement call-ret stack management

This commit is contained in:
Billy Laws committed 2025-07-24 14:53:09 +01:00
1 parent 132de3160a
commit 2f16d25ab8
1 file changed
+8
+8
View File
@@ -27,6 +27,7 @@ $end_info$
#include <FEXCore/Utils/SignalScopeGuards.h>
#include "Common/ArgumentLoader.h"
#include "Common/CallRetStack.h"
#include "Common/Config.h"
#include "Common/Exception.h"
#include "Common/InvalidationTracker.h"
@@ -705,6 +706,10 @@ bool ResetToConsistentStateImpl(EXCEPTION_RECORD* Exception, CONTEXT* GuestConte
if (Exception->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
const auto FaultAddress = static_cast<uint64_t>(Exception->ExceptionInformation[1]);
if (FEX::Windows::CallRetStack::HandleAccessViolation(Thread, FaultAddress, NativeContext->X17)) {
return true;
}
std::scoped_lock Lock(ThreadCreationMutex);
if (InvalidationTracker && InvalidationTracker->HandleRWXAccessViolation(FaultAddress)) {
FEXCORE_PROFILE_INSTANT_INCREMENT(Thread, AccumulatedSMCCount, 1);
@@ -899,6 +904,8 @@ NTSTATUS ThreadInit() {
const auto CPUArea = GetCPUArea();
auto* Thread = CTX->CreateThread(0, 0);
FEX::Windows::CallRetStack::InitializeThread(Thread);
Thread->CurrentFrame->Pointers.Common.ExitFunctionEC = reinterpret_cast<uintptr_t>(&ExitFunctionEC);
CPUArea.StateFrame() = Thread->CurrentFrame;
@@ -957,6 +964,7 @@ NTSTATUS ThreadTerm(HANDLE Thread, LONG ExitCode) {
}
}
FEX::Windows::CallRetStack::DestroyThread(OldThreadState);
CTX->DestroyThread(OldThreadState);
::VirtualFree(reinterpret_cast<void*>(CPUArea.EmulatorStackLimit()), 0, MEM_RELEASE);
if (ThreadTID == GetCurrentThreadId()) {