diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 68bcf6ff78..d2b5e10769 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -1104,6 +1104,28 @@ namespace vm return result; }); + // Fill stack guards with STACKGRD + if (this->flags & 0x10) + { + auto fill64 = [](u8* ptr, u64 data, std::size_t count) + { + u64* target = reinterpret_cast(ptr); + +#ifdef _MSC_VER + __stosq(target, data, count); +#else + for (std::size_t i = 0; i < count; i++) + { + target[i] = data; + } +#endif + }; + + const u32 enda = addr + size - 4096; + fill64(g_sudo_addr + addr, "STACKGRD"_u64, 4096 / sizeof(u64)); + fill64(g_sudo_addr + enda, "UNDERFLO"_u64, 4096 / sizeof(u64)); + } + // Add entry m_map[addr] = std::make_pair(size, std::move(shm)); @@ -1293,6 +1315,13 @@ namespace vm // Unmap "real" memory pages verify(HERE), size == _page_unmap(addr, size, found->second.second.get()); + // Clear stack guards + if (flags & 0x10) + { + std::memset(g_sudo_addr + addr - 4096, 0, 4096); + std::memset(g_sudo_addr + addr + size, 0, 4096); + } + // Remove entry m_map.erase(found);