diff --git a/Source/Common/VolatileMetadata.h b/Source/Common/VolatileMetadata.h index e131e9dc2..a6141fe1b 100644 --- a/Source/Common/VolatileMetadata.h +++ b/Source/Common/VolatileMetadata.h @@ -16,4 +16,36 @@ struct ExtendedVolatileMetadata { }; fextl::unordered_map ParseExtendedVolatileMetadata(std::string_view ListOfDescriptors); + +inline void ApplyFEXExtendedVolatileMetadata(FEX::VolatileMetadata::ExtendedVolatileMetadata& ExtendedMetaData, + fextl::set& VolatileInstructions, FEXCore::IntervalList& VolatileValidRanges, + uint64_t Address, uint64_t EndAddress, uint64_t FileOffset = 0, uint64_t FileOffsetEnd = ~0ULL) { + // Load FEX extended volatile metadata. + // Walk the volatile instructions first if they exist. + for (const auto it_inst : ExtendedMetaData.VolatileInstructions) { + const auto inst_address = it_inst + Address; + if (inst_address < EndAddress) { + VolatileInstructions.emplace(Address + it_inst); + } else { + LogMan::Msg::DFmt("Volatile instruction 0x{:x} couldn't fit in to module range [0x{:x}, 0x{:x}). Not adding anymore volatile " + "instructions. Inspect your config!", + inst_address, Address, EndAddress); + return; + } + } + + // Walk the volatile list + for (const auto it_ranges : ExtendedMetaData.VolatileValidRanges) { + if (it_ranges.Offset >= FileOffset && it_ranges.End < FileOffsetEnd) { + VolatileValidRanges.Insert({Address + it_ranges.Offset - FileOffset, Address + it_ranges.End - FileOffset}); + } + } + + // If it is fully disabled, then set the entire module range + if (ExtendedMetaData.ModuleTSODisabled) { + VolatileValidRanges.Clear(); + VolatileValidRanges.Insert({Address, EndAddress}); + } +} + } // namespace FEX::VolatileMetadata diff --git a/Source/Windows/ARM64EC/Module.cpp b/Source/Windows/ARM64EC/Module.cpp index 33b7538bd..cc1332432 100644 --- a/Source/Windows/ARM64EC/Module.cpp +++ b/Source/Windows/ARM64EC/Module.cpp @@ -39,10 +39,10 @@ $end_info$ #include "Common/CRT/CRT.h" #include "Common/PortabilityInfo.h" #include "Common/Handle.h" +#include "Common/VolatileMetadata.h" #include "DummyHandlers.h" #include "BTInterface.h" #include "Windows/Common/SHMStats.h" -#include "Windows/Common/VolatileMetadata.h" #include #include @@ -314,7 +314,7 @@ void LoadImageVolatileMetadata(const fextl::string& ModuleName, uint64_t Address auto it = ExtendedMetaData.find(ModuleName); if (it != ExtendedMetaData.end()) { - FEX::Windows::ApplyFEXExtendedVolatileMetadata(it->second, VolatileInstructions, VolatileValidRanges, Address, EndAddress); + FEX::VolatileMetadata::ApplyFEXExtendedVolatileMetadata(it->second, VolatileInstructions, VolatileValidRanges, Address, EndAddress); } if (VolatileInstructions.empty() && VolatileValidRanges.Empty()) { diff --git a/Source/Windows/Common/VolatileMetadata.h b/Source/Windows/Common/VolatileMetadata.h deleted file mode 100644 index 8d6d3f813..000000000 --- a/Source/Windows/Common/VolatileMetadata.h +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: MIT -#pragma once - -#include "Common/VolatileMetadata.h" - -#include -#include -#include -#include - -namespace FEX::Windows { -inline void ApplyFEXExtendedVolatileMetadata(FEX::VolatileMetadata::ExtendedVolatileMetadata& ExtendedMetaData, - fextl::set& VolatileInstructions, - FEXCore::IntervalList& VolatileValidRanges, uint64_t Address, uint64_t EndAddress) { - // Load FEX extended volatile metadata. - // Walk the volatile instructions first if they exist. - for (const auto it_inst : ExtendedMetaData.VolatileInstructions) { - const auto inst_address = it_inst + Address; - if (inst_address < EndAddress) { - VolatileInstructions.emplace(Address + it_inst); - } else { - LogMan::Msg::DFmt("Volatile instruction 0x{:x} couldn't fit in to module range [0x{:x}, 0x{:x}). Not adding anymore volatile " - "instructions. Inspect your config!", - inst_address, Address, EndAddress); - return; - } - } - - // Walk the volatile list - for (const auto it_ranges : ExtendedMetaData.VolatileValidRanges) { - VolatileValidRanges.Insert({Address + it_ranges.Offset, Address + it_ranges.End}); - } - - // If it is fully disabled, then set the entire module range - if (ExtendedMetaData.ModuleTSODisabled) { - VolatileValidRanges.Clear(); - VolatileValidRanges.Insert({Address, EndAddress}); - } -} - - -} // namespace FEX::Windows diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index c5bd24721..143ed07a8 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -40,10 +40,10 @@ $end_info$ #include "Common/CRT/CRT.h" #include "Common/PortabilityInfo.h" #include "Common/Handle.h" +#include "Common/VolatileMetadata.h" #include "DummyHandlers.h" #include "BTInterface.h" #include "Windows/Common/SHMStats.h" -#include "Windows/Common/VolatileMetadata.h" #include #include @@ -173,7 +173,7 @@ void LoadImageVolatileMetadata(const fextl::string& ModuleName, uint64_t Address // Load FEX extended volatile metadata. auto it = ExtendedMetaData.find(ModuleName); if (it != ExtendedMetaData.end()) { - FEX::Windows::ApplyFEXExtendedVolatileMetadata(it->second, VolatileInstructions, VolatileValidRanges, Address, EndAddress); + FEX::VolatileMetadata::ApplyFEXExtendedVolatileMetadata(it->second, VolatileInstructions, VolatileValidRanges, Address, EndAddress); } if (VolatileInstructions.empty() && VolatileValidRanges.Empty()) {