Repository navigation
fix(libkernel): unmap direct memory views when the memory is released - #2236
Merged
oneandonlydean merged 1 commit intoOct 10, 2026
Merged
oneandonlydean merged 1 commit into
oneandonlydean merged 1 commit into
Conversation
Releasing direct memory left the virtual ranges that mapped it registered, so sceKernelVirtualQuery reported them as flexible memory at offset 0 and titles walking a range with FIND_NEXT released physical page 0. Collect every view of the released pages before freeing them and unmap them through UnmapRegistered, as shadPS4's MemoryManager::Free does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Linux run: Linux 7.2 (x86_64), GCC 16.2.1, Release,
|
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
9 tasks done
oneandonlydean
added a commit
to oneandonlydean/AnyPS5
that referenced
this pull request
Oct 10, 2026
oneandonlydean
added a commit
to oneandonlydean/AnyPS5
that referenced
this pull request
Oct 10, 2026
9 tasks done
SleglJan
pushed a commit
to SleglJan/AnyPS5
that referenced
this pull request
Oct 10, 2026
…mory-unmaps-views fix(libkernel): unmap direct memory views when the memory is released
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sceKernelReleaseDirectMemoryandsceKernelCheckedReleaseDirectMemoryfree the physical pages and forget their direct mappings, but the virtual ranges that mapped them stay registered as guest allocations. A latersceKernelVirtualQuerythen reports those ranges as committed flexible memory at offset 0.A title that frees GPU memory by walking a virtual range with
FIND_NEXTand releasingoffset + (start - info.start)for each region it finds then frees physical offset 0. That stops withdirect memory range 0x0+0x200000 references unallocated physical page 0x0.With this change, releasing direct memory also unmaps every virtual view of the released pages, aliases included, so the range is free afterwards. The views are collected before the pages are freed and unmapped through the existing
UnmapRegisteredpath. The checked variant unmaps only when the release succeeds.This follows shadPS4's
MemoryManager::Free, which releases "any dmem mappings that reference this physical block": https://github.com/shadps4-emu/shadPS4/blob/main/src/core/memory.cppCheckReleaseDirectMemoryClearsMappingsasserted the old behaviour, where a fully released mapping still answered queries. It now checks that both the mapping and a second alias stop answering queries, and thatFIND_NEXTfrom them does not return them. It no longer depends on how a hole inside an allocation is reported, which #1731 changes.Tested
Windows 11, MinGW-w64 GCC (project toolchain), Release/Ninja on upstream main
d70b8998.guest_memorypasses with the change. On unchanged production code the updated test fails at the released-mapping query (GuestMemory.cpp:288).tools/check_conventions.pyandgit diff --checkpass.Checklist
main; no other open PR implements the same functions (fix(libkernel): query current guest mapping extents #1731 changessceKernelVirtualQueryrange selection and explicitly excludes memory release; the two are independent)🤖 Generated with Claude Code