diff --git a/Source/Windows/Common/InvalidationTracker.cpp b/Source/Windows/Common/InvalidationTracker.cpp index 34cd0c91a..d3e6f3c5c 100644 --- a/Source/Windows/Common/InvalidationTracker.cpp +++ b/Source/Windows/Common/InvalidationTracker.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "InvalidationTracker.h" #include @@ -13,6 +14,9 @@ namespace FEX::Windows { InvalidationTracker::InvalidationTracker(FEXCore::Context::Context& CTX, const std::unordered_map& Threads) : CTX {CTX} , Threads {Threads} { + FEX_CONFIG_OPT(SMCChecks, SMCCHECKS); + SMCDetectionDisabled = (SMCChecks == FEXCore::Config::CONFIG_SMC_NONE); + MEMORY_BASIC_INFORMATION Info; uint64_t Address = 0; @@ -138,6 +142,10 @@ void InvalidationTracker::ReprotectRWXIntervals(uint64_t Address, uint64_t Size) const auto End = Address + Size; std::shared_lock Lock(IntervalsLock); + if (SMCDetectionDisabled) { + return; + } + do { const auto Query = RWXIntervals.Query(Address); if (Query.Enclosed) { @@ -197,4 +205,23 @@ FEXCore::HLE::ExecutableRangeInfo InvalidationTracker::QueryExecutableRange(uint return {XResult.Interval.Offset, XResult.Interval.End - XResult.Interval.Offset, false}; } +void InvalidationTracker::DisableSMCDetection() { + std::unique_lock Lock(IntervalsLock); + SMCDetectionDisabled = true; + uint64_t Address = 0; + + // Reprotect all RWX intervals as RWX + FEXCore::IntervalList::QueryResult Query; + do { + Query = RWXIntervals.Query(Address); + if (Query.Enclosed) { + void* TmpAddress = reinterpret_cast(Address); + SIZE_T TmpSize = static_cast(Query.Size); + ULONG TmpProt; + NtProtectVirtualMemory(NtCurrentProcess(), &TmpAddress, &TmpSize, PAGE_EXECUTE_READWRITE, &TmpProt); + } + Address += Query.Size; + } while (Query.Size); +} + } // namespace FEX::Windows diff --git a/Source/Windows/Common/InvalidationTracker.h b/Source/Windows/Common/InvalidationTracker.h index 96d959fad..44bba0d47 100644 --- a/Source/Windows/Common/InvalidationTracker.h +++ b/Source/Windows/Common/InvalidationTracker.h @@ -34,10 +34,13 @@ public: FEXCore::HLE::ExecutableRangeInfo QueryExecutableRange(uint64_t Address); private: + void DisableSMCDetection(); + FEXCore::IntervalList XIntervals; FEXCore::IntervalList RWXIntervals; std::shared_mutex IntervalsLock; FEXCore::Context::Context& CTX; const std::unordered_map& Threads; + bool SMCDetectionDisabled {false}; // Protected by IntervalsLock }; } // namespace FEX::Windows