From 5307e9d913b12a5aa3691f244914b176cc88d52d Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Mon, 2 Jun 2025 19:36:42 -0500 Subject: [PATCH] Swap do-while to while If we use a do-while loop, we waste time if `aligned_size = 0`. This is also still accurate to FreeBSD behavior, where it returns success if `start == end` during mprotect. This also effectively prevents the memory assert seen in updated versions of RESIDENT EVIL 2 (CUSA09193) --- src/core/memory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index bf9d1cabd..99da3472d 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -602,7 +602,7 @@ s32 MemoryManager::Protect(VAddr addr, size_t size, MemoryProt prot) { auto aligned_addr = Common::AlignDown(addr, 16_KB); auto aligned_size = Common::AlignUp(size + addr - aligned_addr, 16_KB); - do { + while (protected_bytes < aligned_size) { auto it = FindVMA(aligned_addr + protected_bytes); auto& vma_base = it->second; ASSERT_MSG(vma_base.Contains(addr + protected_bytes, 0), "Address {:#x} is out of bounds", @@ -615,7 +615,7 @@ s32 MemoryManager::Protect(VAddr addr, size_t size, MemoryProt prot) { return result; } protected_bytes += result; - } while (protected_bytes < aligned_size); + } return ORBIS_OK; }