From 96ae671738579ab117edf7f346a43b31f862ffb4 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 28 Jul 2025 16:07:07 -0700 Subject: [PATCH] 64BitAllocator: Removes pair usage in allocator NFC --- .../Source/Utils/Allocator/64BitAllocator.cpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp b/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp index 0dd30b367..e99f000b9 100644 --- a/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp +++ b/FEXCore/Source/Utils/Allocator/64BitAllocator.cpp @@ -275,8 +275,13 @@ void* OSAllocator_64Bit::Mmap(void* addr, size_t length, int prot, int flags, in again: + struct RangeResult final { + LiveVMARegion *RegionInsertedInto; + void *Ptr; + }; + auto CheckIfRangeFits = [&AllocatedOffset](LiveVMARegion* Region, uint64_t length, int prot, int flags, int fd, off_t offset, - uint64_t StartingPosition = 0) -> std::pair { + uint64_t StartingPosition = 0) -> RangeResult { uint64_t AllocatedPage {~0ULL}; uint64_t NumberOfPages = length >> FEXCore::Utils::FEX_PAGE_SHIFT; @@ -314,13 +319,13 @@ again: void* MMapResult = ::mmap(reinterpret_cast(AllocatedOffset), length, prot, (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED, fd, offset); if (MMapResult == MAP_FAILED) { - return std::make_pair(Region, reinterpret_cast(-errno)); + return RangeResult {Region, reinterpret_cast(-errno)}; } - return std::make_pair(Region, MMapResult); + return RangeResult {Region, MMapResult}; } } - return std::make_pair(nullptr, nullptr); + return {}; }; if (Fixed) { @@ -329,7 +334,7 @@ again: // Found a slab that fits this if (flags & MAP_FIXED_NOREPLACE) { auto Fits = CheckIfRangeFits(LiveRegion, length, prot, flags, fd, offset, Addr); - if (Fits.first && Fits.second == reinterpret_cast(Addr)) { + if (Fits.RegionInsertedInto && Fits.Ptr == reinterpret_cast(Addr)) { // We fit correctly AllocatedOffset = Addr; } else { @@ -355,7 +360,7 @@ again: // We found a LiveRegion that could hold this address. Let's try to place it // Check if this area is free auto Fits = CheckIfRangeFits(LiveRegion, length, prot, flags, fd, offset, Addr); - if (Fits.first && Fits.second == reinterpret_cast(Addr)) { + if (Fits.RegionInsertedInto && Fits.Ptr == reinterpret_cast(Addr)) { // We fit correctly AllocatedOffset = Addr; } else { @@ -368,15 +373,15 @@ again: if (!LiveRegion) { for (auto it = LiveRegions->begin(); it != LiveRegions->end(); ++it) { auto Fits = CheckIfRangeFits(*it, length, prot, flags, fd, offset); - if (Fits.first && Fits.second == reinterpret_cast(AllocatedOffset)) { + if (Fits.RegionInsertedInto && Fits.Ptr == reinterpret_cast(AllocatedOffset)) { // We fit correctly - LiveRegion = Fits.first; + LiveRegion = Fits.RegionInsertedInto; break; } // Couldn't fit but mmap gave us an error - if (!Fits.first && Fits.second) { - return Fits.second; + if (!Fits.RegionInsertedInto && Fits.Ptr) { + return Fits.Ptr; } // nullptr on both means no error and couldn't fit