memory: retry guest accesses while a mapping is briefly replaced #1229
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1229
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1229/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@TheCruZ on GitHub · 2026-10-08 19:10 UTC · original
pr/map-fixed-retry→main· +332 −0 · 5 files · 1 commits · closed without mergingSummary
Fixes an intermittent crash in Grand Theft Auto V (PPSA04263), about once every 100 sessions: the
[RAGE] HDD Streamerthread died with an unhandled access violation inside zlibinflate_fast(read of the output window) orinflate(first store intonext_out), on 64 KiB direct-memory pages at0x10xxxxxxxx. The page was mapped again a moment later: the crash report could read it, with the decompressed data in place.Problem
Two game threads commit the same page:
AsyncCommitThreadmaps it withMAP_FIXED, and one or two milliseconds later the main thread maps the same physical page at the same address again withMAP_FIXED. On the console that is an atomic no-op, and the streamer is already decompressing into the page. The emulator replaces a mapping by unmapping it and mapping it again (ReplaceFixedRangeWithReserved), so for that moment the page is gone and the streamer's access faults.Windows has the same kind of gap on its own: a file view can only be split by unmapping all of it, so unmapping part of a view briefly takes the parts that stay mapped away too. Those parts also came back with the view's protection, dropping the guest's
mprotectand the page manager's write and read tracking on them.Change
MAP_FIXEDreplacement and the Windows view split) publish the affected range in a small lock-free table while the mapping is absent. The runtime linker's fault handler waits until the range is mapped again and retries the access (unless the GPU tracking resolves the fault first). A page that keeps faulting after its range was mapped again is still reported as a crash, so real access violations are not hidden.Relation to #432 and #433
Both closed PRs targeted the same window: #432 skipped a fixed map that already matches the mapped range, #433 retried faults inside a
MAP_FIXEDreplacement window with a bounded yield loop. This PR also covers the Windows partial-unmap gap of a split view, keeps the protections of the parts that stay mapped, and keeps reporting a page that still faults once its range is back.Testing
virtual_memory_allocation_tests: new cases check that the survivors of a view split keep their protections on Windows, and that a thread keeps using memory while other parts of its view are unmapped and while its mapping is replaced withMAP_FIXED(hundreds of retried faults per run, an unhandled access violation without this change). Passes.page_manager_testsandmemory_tracker_testspass.AI usage
AI (Claude Opus 5.5) was used to investigate the issue (crash reports, mapping traces) and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my GTA V fork, i will be bringing PRs here after test them enough.
@coderabbitai[bot] on GitHub · 2026-10-08 19:10 UTC · original
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.Pull request closed