shadPS4 icon indicating copy to clipboard operation
shadPS4 copied to clipboard

Unmap Fixes

Open StevenMiller123 opened this issue 1 month ago • 5 comments

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.

StevenMiller123 avatar Jan 07 '25 07:01 StevenMiller123