From f0604eca004cad9221f28b1869b5b87e6f1efead Mon Sep 17 00:00:00 2001 From: Exverge Date: Wed, 15 Jul 2026 20:34:04 -0400 Subject: [PATCH] [core] don't keep trying to allocate HostMemory buffer --- src/common/host_memory.cpp | 7 ++++++- src/common/virtual_buffer.cpp | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 36cbc59efc..10c8022ed1 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -177,7 +177,7 @@ public: if (res == 0) { LOG_WARNING(HW_Memory, "Failed to check memory region: {}", GetLastError()); - continue; + break; } auto start_aligned = AlignUp(reinterpret_cast(info.BaseAddress), HugePageSize); @@ -187,6 +187,11 @@ public: if (info.RegionSize - (start_aligned - reinterpret_cast(info.BaseAddress)) >= virtual_size) { virtual_base = static_cast(pfn_VirtualAlloc2 (process, reinterpret_cast(start_aligned), virtual_size, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, PAGE_NOACCESS, nullptr, 0)); + if (virtual_base) { + break; + } else { + LOG_WARNING(HW_Memory, "Failed to allocate buffer at {:#x}, trying at at new address", start_aligned); + } } } diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp index 8a4265e3e6..3017e32775 100644 --- a/src/common/virtual_buffer.cpp +++ b/src/common/virtual_buffer.cpp @@ -22,12 +22,13 @@ void* AllocateMemoryPages(std::size_t size) noexcept { // Probably failing to reserve is less likely than failing to commit base = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); } + ASSERT_MSG(base, "Failed to allocate {} pages, error {}", size, GetLastError()); #else void* base = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (base == MAP_FAILED) base = nullptr; + ASSERT_MSG(base, "Failed to allocate {} pages, error {}", size, strerror(errno)); #endif - ASSERT(base); return base; }