From 7d3699050e3a2abf9a05e2f3e2942c9e8a12a320 Mon Sep 17 00:00:00 2001 From: offtkp Date: Fri, 2 May 2025 02:26:34 +0300 Subject: [PATCH] Make shmdt reset the unmapped pages in the 32-bit allocator --- .../LinuxSyscalls/LinuxAllocator.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp index e4095a81d..5d2604f4a 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp @@ -514,8 +514,20 @@ uint64_t MemAllocator32Bit::Shmdt(const void* shmaddr) { return -EINVAL; } + int shmid = it->second; + struct shmid_ds buf {}; + if (shmctl(shmid, IPC_STAT, &buf) == 0) { + size_t PagesLength = FEXCore::AlignUp(buf.shm_segsz, FEXCore::Utils::FEX_PAGE_SIZE) >> FEXCore::Utils::FEX_PAGE_SHIFT; + SetFreePages(AddrPage, PagesLength); + } else { + LOGMAN_MSG_A_FMT("Failed to get shm size during shmdt"); + } + uint64_t Result = ::shmdt(shmaddr); - PageToShm.erase(it); + + if (Result == 0) { + PageToShm.erase(it); + } SYSCALL_ERRNO(); }