From 1c0a5c60eaf8aad7d0ccbebb0806def2471e160e Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Fri, 15 Aug 2025 04:21:59 -0500 Subject: [PATCH] Memory: Align size and address in posix_munmap (#3418) * Properly align address and size in munmap Based on observations of FreeBSD source code, fixes a Windows-related memory issue in War Thunder (CUSA00224) * Format len and phys_addr in mmap This should make logs slightly easier to understand, since we format these parameters in other memory calls. * Update memory.cpp --- src/core/libraries/kernel/memory.cpp | 7 ++++--- src/core/memory.cpp | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/libraries/kernel/memory.cpp b/src/core/libraries/kernel/memory.cpp index 714dc77cb..ddc556fcd 100644 --- a/src/core/libraries/kernel/memory.cpp +++ b/src/core/libraries/kernel/memory.cpp @@ -570,9 +570,10 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolBatch(const OrbisKernelMemoryPoolBatchEntry* } void* PS4_SYSV_ABI posix_mmap(void* addr, u64 len, s32 prot, s32 flags, s32 fd, s64 phys_addr) { - LOG_INFO(Kernel_Vmm, - "called addr = {}, len = {}, prot = {}, flags = {}, fd = {}, phys_addr = {}", - fmt::ptr(addr), len, prot, flags, fd, phys_addr); + LOG_INFO( + Kernel_Vmm, + "called addr = {}, len = {:#x}, prot = {:#x}, flags = {:#x}, fd = {}, phys_addr = {:#x}", + fmt::ptr(addr), len, prot, flags, fd, phys_addr); void* addr_out; auto* memory = Core::Memory::Instance(); diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 72ba70eba..a7af90e13 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -573,6 +573,8 @@ u64 MemoryManager::UnmapBytesFromEntry(VAddr virtual_addr, VirtualMemoryArea vma s32 MemoryManager::UnmapMemoryImpl(VAddr virtual_addr, u64 size) { u64 unmapped_bytes = 0; + virtual_addr = Common::AlignDown(virtual_addr, 16_KB); + size = Common::AlignUp(size, 16_KB); do { auto it = FindVMA(virtual_addr + unmapped_bytes); auto& vma_base = it->second;