diff --git a/FEXCore/Source/Utils/Allocator.cpp b/FEXCore/Source/Utils/Allocator.cpp index 468f92c954..b254945c2e 100644 --- a/FEXCore/Source/Utils/Allocator.cpp +++ b/FEXCore/Source/Utils/Allocator.cpp @@ -304,10 +304,10 @@ fextl::vector StealMemoryRegion(uintptr_t Begin, uintptr_t End) { return Regions; } -void Setup48BitAllocatorIfExists() { +fextl::vector Setup48BitAllocatorIfExists() { size_t Bits = FEXCore::Allocator::DetermineVASize(); if (Bits < 48) { - return; + return {}; } uintptr_t Begin48BitVA = 0x0'8000'0000'0000ULL; @@ -316,6 +316,8 @@ void Setup48BitAllocatorIfExists() { Alloc64 = Alloc::OSAllocator::Create64BitAllocatorWithRegions(Regions); AssignHookOverrides(); + + return Regions; } void ReclaimMemoryRegion(const fextl::vector& Regions) { diff --git a/FEXCore/include/FEXCore/Utils/Allocator.h b/FEXCore/include/FEXCore/Utils/Allocator.h index efbb70f7ce..524288242f 100644 --- a/FEXCore/include/FEXCore/Utils/Allocator.h +++ b/FEXCore/include/FEXCore/Utils/Allocator.h @@ -86,7 +86,7 @@ FEX_DEFAULT_VISIBILITY void ReclaimMemoryRegion(const fextl::vector Setup48BitAllocatorIfExists(); #ifndef _WIN32 FEX_DEFAULT_VISIBILITY void RegisterTLSData(FEXCore::Core::InternalThreadState* Thread); diff --git a/Source/Tools/FEXLoader/FEXLoader.cpp b/Source/Tools/FEXLoader/FEXLoader.cpp index 48bc618085..53bf90cf41 100644 --- a/Source/Tools/FEXLoader/FEXLoader.cpp +++ b/Source/Tools/FEXLoader/FEXLoader.cpp @@ -491,11 +491,12 @@ int main(int argc, char** argv, char** const envp) { FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_IS64BIT_MODE, Loader.Is64BitMode() ? "1" : "0"); fextl::unique_ptr Allocator; + fextl::vector Base48Bit; fextl::vector Low4GB; if (Loader.Is64BitMode()) { // Destroy the 48th bit if it exists - FEXCore::Allocator::Setup48BitAllocatorIfExists(); + Base48Bit = FEXCore::Allocator::Setup48BitAllocatorIfExists(); } else { // Reserve [0x1_0000_0000, 0x2_0000_0000). // Safety net if 32-bit address calculation overflows in to 64-bit range. @@ -684,6 +685,7 @@ int main(int argc, char** argv, char** const envp) { LogMan::Msg::UnInstallHandler(); FEXCore::Allocator::ClearHooks(); + FEXCore::Allocator::ReclaimMemoryRegion(Base48Bit); FEXCore::Allocator::ReclaimMemoryRegion(Low4GB); // Allocator is now original system allocator