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; }