shadPS4
shadPS4 copied to clipboard
Unmap Fixes
This PR fixes several memory issues I've noticed.
- 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
. - 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
. -
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. - When games overwrite memory with reserved pages, our check for
vma.type == VMAType::Free
would fail. This is because, while theUnmapMemoryImpl
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.