From d17aed4439ac4dd3e8de9545e9f5f064b5170453 Mon Sep 17 00:00:00 2001 From: Eduardo Ruiz Date: Mon, 16 Nov 2026 02:34:44 +0100 Subject: [PATCH] fix(agc): hand out repeated low test mappings under ASan The low-memory helpers of agc_gcn_color_target and the EQAA execution test mapped their block at the first hint that was free and, on the next call, retried that same hint and then stepped by 4 GiB. With ASan every address at or above 0x7fff8000 belongs to its shadow, so the first block at 0x60000000 succeeded and every later attempt failed: the 2026-11-15 Sanitizers run stopped in agc_gcn_color_target with "cannot allocate multisampled array slice test memory below 1 TiB". Both helpers now keep the next free hint and step by the page-rounded block size while ASan is enabled, so consecutive blocks pack into the gap below its shadow. Without ASan the 4 GiB stride is kept. --- .../prx/libSceAgcDriver/tests/GcnColorTarget.cpp | 12 ++++++++++-- .../tests/execution/GcnEqaaColorTarget.cpp | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp b/core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp index 9e5ca9a00b57..3f0f70e8dba0 100644 --- a/core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp @@ -69,12 +69,20 @@ std::byte* LowMemory(std::size_t bytes) { #else #ifdef ANYPS5_ENABLE_ASAN constexpr std::uintptr_t FirstHint = 0x60000000; + constexpr std::uintptr_t MinimumStride = std::uintptr_t{1} << 12u; #else constexpr std::uintptr_t FirstHint = std::uintptr_t{1} << 32u; + constexpr std::uintptr_t MinimumStride = std::uintptr_t{1} << 32u; #endif - for (std::uintptr_t hint = FirstHint; hint < (std::uintptr_t{1} << 40u); hint += std::uintptr_t{1} << 32u) { + const std::uintptr_t rounded = (bytes + 0xfffu) & ~std::uintptr_t{0xfffu}; + const std::uintptr_t stride = rounded < MinimumStride ? MinimumStride : rounded; + static std::uintptr_t next = FirstHint; + for (std::uintptr_t hint = next; hint < (std::uintptr_t{1} << 40u); hint += stride) { void* mapped = mmap(reinterpret_cast(hint), bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0); - if (mapped != MAP_FAILED) return static_cast(mapped); + if (mapped != MAP_FAILED) { + next = hint + stride; + return static_cast(mapped); + } } return nullptr; #endif diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/GcnEqaaColorTarget.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/GcnEqaaColorTarget.cpp index aed859cc2a89..47f8efa29118 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/GcnEqaaColorTarget.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/GcnEqaaColorTarget.cpp @@ -101,12 +101,20 @@ class LowBlock { #else #ifdef ANYPS5_ENABLE_ASAN constexpr std::uintptr_t FirstHint = 0x60000000; + constexpr std::uintptr_t MinimumStride = std::uintptr_t{1} << 12u; #else constexpr std::uintptr_t FirstHint = std::uintptr_t{1} << 32u; + constexpr std::uintptr_t MinimumStride = std::uintptr_t{1} << 32u; #endif - for (std::uintptr_t hint = FirstHint; data == nullptr && hint < GcnAddressLimit; hint += std::uintptr_t{1} << 32u) { + const std::uintptr_t rounded = (BlockBytes + 0xfffu) & ~std::uintptr_t{0xfffu}; + const std::uintptr_t stride = rounded < MinimumStride ? MinimumStride : rounded; + static std::uintptr_t next = FirstHint; + for (std::uintptr_t hint = next; data == nullptr && hint < GcnAddressLimit; hint += stride) { void* mapped = mmap(reinterpret_cast(hint), BlockBytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0); - if (mapped != MAP_FAILED) data = static_cast(mapped); + if (mapped != MAP_FAILED) { + next = hint + stride; + data = static_cast(mapped); + } } if (data != nullptr && AgcDriver::GuestMemory::WriteWatched()) GuestWriteWatch::GuestWriteWatchRegister_nid_postfix(data, BlockBytes); #endif