Skip to content

Commit

Permalink
Allocator: Still need to return memory regions to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonicadvance1 committed Jan 24, 2025
1 parent 04fca7d commit 942838e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions FEXCore/Source/Utils/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ fextl::vector<MemoryRegion> StealMemoryRegion(uintptr_t Begin, uintptr_t End) {
return Regions;
}

void Setup48BitAllocatorIfExists() {
fextl::vector<MemoryRegion> Setup48BitAllocatorIfExists() {
size_t Bits = FEXCore::Allocator::DetermineVASize();
if (Bits < 48) {
return;
return {};
}

uintptr_t Begin48BitVA = 0x0'8000'0000'0000ULL;
Expand All @@ -316,6 +316,8 @@ void Setup48BitAllocatorIfExists() {

Alloc64 = Alloc::OSAllocator::Create64BitAllocatorWithRegions(Regions);
AssignHookOverrides();

return Regions;
}

void ReclaimMemoryRegion(const fextl::vector<MemoryRegion>& Regions) {
Expand Down
2 changes: 1 addition & 1 deletion FEXCore/include/FEXCore/Utils/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ FEX_DEFAULT_VISIBILITY void ReclaimMemoryRegion(const fextl::vector<MemoryRegion
// AArch64 canonical addresses are only up to bits 48/52 with the remainder being other things
// Use this to reserve the top 128TB of VA so the guest never see it
// Returns nullptr on host VA < 48bits
FEX_DEFAULT_VISIBILITY void Setup48BitAllocatorIfExists();
FEX_DEFAULT_VISIBILITY fextl::vector<MemoryRegion> Setup48BitAllocatorIfExists();

#ifndef _WIN32
FEX_DEFAULT_VISIBILITY void RegisterTLSData(FEXCore::Core::InternalThreadState* Thread);
Expand Down
4 changes: 3 additions & 1 deletion Source/Tools/FEXLoader/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FEX::HLE::MemAllocator> Allocator;
fextl::vector<FEXCore::Allocator::MemoryRegion> Base48Bit;
fextl::vector<FEXCore::Allocator::MemoryRegion> 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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 942838e

Please sign in to comment.