[PR #2080] [MERGED] Unmap Fixes #2477

Closed
opened 2026-02-27 22:00:04 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/2080
Author: @StevenMiller123
Created: 1/7/2025
Status: Merged
Merged: 1/8/2025
Merged by: @georgemoralis

Base: mainHead: fix-reserved-unmaps


📝 Commits (5)

📊 Changes

1 file changed (+16 additions, -8 deletions)

View changed files

📝 src/core/memory.cpp (+16 -8)

📄 Description

This PR fixes several memory issues I've noticed.

  1. When games try to unmap reserved memory, this would cause address_space asserts on Windows. This is because reserved memory was never mapped in address_space to begin with. My fix is to only unmap in address_space if the unmapped VMA had type != VMAType::Reserved.
  2. Some games also attempt to unmap free memory. This causes address_space asserts on Windows, and also messes up later memory use calculations. My solution is adding an early return if the VMA to unmap has type == VMAType::Free.
  3. UnmapMemoryImpl doesn't properly handle pooled memory. PoolReserved memory can either be reserved or decommitted memory, either case isn't mapped in address_space. Additionally, Pooled memory is GPU mapped. My solution is adding those relevant checks so we don't run into any strange Windows-specific issues.
  4. When games overwrite memory with reserved pages, our check for vma.type == VMAType::Free would fail. This is because, while the UnmapMemoryImpl call modifies vma_map, the vma retrieved before that call is not modified. To fix this, I add an extra FindVMA call after the unmap.

This should fix cases of:

[Debug] <Critical> address_space.cpp:operator():268: Assertion Failed!
Invalid address/size given to unmap.

And some cases of:

[Debug] <Critical> memory.cpp:operator():217: Assertion Failed!

Credits to @red-prig for providing relevant information.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/2080 **Author:** [@StevenMiller123](https://github.com/StevenMiller123) **Created:** 1/7/2025 **Status:** ✅ Merged **Merged:** 1/8/2025 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `fix-reserved-unmaps` --- ### 📝 Commits (5) - [`09b683b`](https://github.com/shadps4-emu/shadPS4/commit/09b683bc50a277f87fadb1bd3b330bcd71991e9c) Fix unmapping reserved memory - [`7e70278`](https://github.com/shadps4-emu/shadPS4/commit/7e7027880bd56a3306472f02dce9c76835c4da67) Fix bug with unmapping before reserve - [`ad2cedd`](https://github.com/shadps4-emu/shadPS4/commit/ad2cedd7647feb230485fc873734ea53a6f97a05) Clang - [`f2be980`](https://github.com/shadps4-emu/shadPS4/commit/f2be980a936c87dc83467136291bc72733d451de) Ignore free memory pages - [`2be3e93`](https://github.com/shadps4-emu/shadPS4/commit/2be3e93cf4d7757b33643ccce0baff5e270b3320) Handle pooled memory ### 📊 Changes **1 file changed** (+16 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/core/memory.cpp` (+16 -8) </details> ### 📄 Description This PR fixes several memory issues I've noticed. 1. When games try to unmap reserved memory, this would cause address_space asserts on Windows. This is because reserved memory was never mapped in address_space to begin with. My fix is to only unmap in address_space if the unmapped VMA had `type != VMAType::Reserved`. 2. Some games also attempt to unmap free memory. This causes address_space asserts on Windows, and also messes up later memory use calculations. My solution is adding an early return if the VMA to unmap has `type == VMAType::Free`. 3. `UnmapMemoryImpl` doesn't properly handle pooled memory. PoolReserved memory can either be reserved or decommitted memory, either case isn't mapped in address_space. Additionally, Pooled memory is GPU mapped. My solution is adding those relevant checks so we don't run into any strange Windows-specific issues. 4. When games overwrite memory with reserved pages, our check for `vma.type == VMAType::Free` would fail. This is because, while the `UnmapMemoryImpl` call modifies vma_map, the vma retrieved before that call is not modified. To fix this, I add an extra FindVMA call after the unmap. This should fix cases of: ``` [Debug] <Critical> address_space.cpp:operator():268: Assertion Failed! Invalid address/size given to unmap. ``` And some cases of: ``` [Debug] <Critical> memory.cpp:operator():217: Assertion Failed! ``` Credits to @red-prig for providing relevant information. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:00:04 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#2477
No description provided.