loader: extend Windows red-zone protection to functions missing from .eh_frame (Saros) #2099
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!2099
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2099"
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?
@joaocaparroz on GitHub · 2026-11-04 04:20 UTC · original
joaocaparroz:redzone-unlisted-functions→main· +131 −2 · 1 files · 2 commits · openGame
Saros (PPSA07631, 01.005.002). Refs #1053.
Problem
On Windows the game crashed within about a minute of gameplay, both with and without
--redzone, with:It also crashes on build
02b17af, so this is not a recent regression.The faulting code is a leaf function in the game (
0x9001feffe) that copies 28-byte records into a locked GPU buffer. It keeps its loop count at[rbp-0x40], which is inside the SysV red zone (rsp = rbp - 0x28in that function). When a write to tracked GPU memory raises an exception, Windows builds the exception frame on the guest stack and overwrites that count. The loop then runs past the end of the buffer into an unmapped page. Dumping the caller's state at the fault showed a count of 1 while the loop was at record 16384.--redzonealready handles exactly this situation, but three gaps kept it from reaching the functions involved:.eh_framewere never analyzed.0x9001feffeisn't listed, so it was decoded as part of the preceding function, and that decode never reached it..rodata. A second function (0x9032ead00, reached when pressing X in game) dispatches through such a table before reloading a pointer from[rsp-0x30]. That part of the function was never decoded, the pointer came back as null, and the game crashed.Changes
All changes are in
src/loader/guestInstructionPatcher.cpp:calltargets found in decoded code are added as function starts, repeating until no new ones appear. They only come from decoded control flow, never from raw byte scans. Tail jumps are left out, since they can land in the middle of a function.DetectFramePointerRedZone: it gets the RBP-to-RSP distance from the prologue (push rbp; mov rbp, rsp, then pushes andsub rsp, imm). If any[rbp-d]access falls in the red zone, the function is protected conservatively. It does nothing if RBP is written outside the epilogue.ResolveBoundedJumpTableaccepts a table anywhere in the loaded module image. Every target still has to be inside the function.The function discovery only runs with
--redzone, so default runs behave as before. The jump-table change also affects the--amd-cpupatch path, where it only allows moreswitchbodies to be decoded.Testing
--redzone. Before the fix, four runs crashed after 27–70 s. With a diagnostic build I confirmed both faulting instructions now get rewritten. After the fix, the game runs past both points, pressing X no longer crashes, and it exits cleanly.ctest, 32 tests) passes locally with clang-cl.--redzone. Without the flag the game crashes too early to compare, so I couldn't isolate the overhead of the extra protected sites. I haven't measured the load-time cost of the extra decode pass either.AI use
I used an AI coding assistant for most of the investigation and the implementation: disassembling the game's code, adding temporary diagnostics to trace the fault, and writing the patcher changes and this description. I reviewed the final diff and tested the game on my machine before and after the change, as described above. The temporary diagnostics are not part of this PR.
Thanks for the existing
--redzoneprotection; it made this fix much smaller than it would otherwise have been. I'm happy to adjust anything, split the changes, or test other games if that helps.@coderabbitai[bot] on GitHub · 2026-11-04 04:24 UTC · original · edited 2026-11-04 04:46 UTC
No actionable comments were generated in the recent review.
Walkthrough
The patch records direct-call targets during function decoding and expands known function starts when memory protection is enabled. It accepts jump tables within a registered module image, while resolved targets must remain inside the function. During red-zone analysis, it detects certain RBP-relative accesses below RSP and marks the function for conservative tracking.
Suggested reviewers:
nmzik,ew-sudoChange: Bug fix
Merge Risk:
Minimal · up to
52235The change extends Windows red-zone protection to functions missing from .eh_frame and to RBP-relative accesses. No merge-blocking risk remains. A rare frame-pointer pattern with a later stack adjustment could stay unprotected, but this is a narrow edge case that can be handled as a follow-up.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title names the main change: extending Windows red-zone protection to functions missing from .eh_frame, with the game (Saros) named. The changeset adds call-target function discovery, RBP-relative red-zone detection, and jump-table bound changes in guestInstructionPatcher.cpp. The title covers the function-discovery part, which is the first of three changes, so it is a partial match. It is specific enough to identify the primary change. The title is 86 characters, slightly above the short-title guideline, but it is a single sentence.
Full details: Description check
Explanation
The description covers the game affected, the crash symptoms, the root causes (missing .eh_frame functions, RBP-relative red-zone operands, rejected out-of-segment jump tables), the specific changes in guestInstructionPatcher.cpp, testing done, and AI usage. It is directly related to the changeset.
Full details: Docstring Coverage
Explanation
Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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
b0d3b03a-b23d-4014-b3de-0f381e359330Reviewing files that changed from the base of the PR and between
ea342ad7a1and52235b3884.src/loader/guestInstructionPatcher.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-04 04:24 UTC · original · edited 2026-11-04 04:48 UTC
On
src/loader/guestInstructionPatcher.cppline 559 (outdated):Keep in-range direct-call targets in
branch_targets.Before this change, a direct call whose target was inside
[function_start, function_end)went intobranch_targets. The newif/else ifsends every call tocalleesonly. This is safe whenAddDecodedCalleesruns, because it splits the function at that target. It does not run whenprotect_memoryis false, which covers--amd-cpuwithout--redzoneand the TSC-only path.In those paths, an unlisted function that lies inside its predecessor's range is no longer marked as a branch target.
collect_forward_span,collect_backward_span, andfind_hostcheckbranch_targetsbefore they relocate instructions into a trampoline. A relocated span can now cover the entry of that function. A later direct call into the middle of the patched span then lands onnoppadding or a partial jump.Record the in-range target as a branch target in addition to recording the callee:
Proposed fix
After
AddDecodedCalleessplits the function, the callee lies outside the range. The extra entry then has no effect on the--redzonepath.Committable suggestion
✅ Addressed in commit
52235b3@coderabbitai[bot] on GitHub · 2026-11-04 04:24 UTC · original · reviewed
Actionable comments posted: 1
ef1e8452-40a9-46ab-960e-7bd0b9cb3947Reviewing files that changed from the base of the PR and between
eecd982193andea342ad7a1.src/loader/guestInstructionPatcher.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@joaocaparroz on GitHub · 2026-11-04 04:41 UTC · original
On
src/loader/guestInstructionPatcher.cppline 559 (outdated):Good catch, applied in
52235b38. In-range call targets are now kept as branch targets too, so the non---redzonepaths behave as before. Retested Saros with--redzoneand the CI test set.@coderabbitai[bot] on GitHub · 2026-11-04 04:48 UTC · original
On
src/loader/guestInstructionPatcher.cppline 559 (outdated):@joaocaparroz Thanks for the fix and retesting. The supplied code now records in-range direct-call targets in
branch_targetsindependently ofcallees. This preserves relocation boundaries whenAddDecodedCalleesdoes not run.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Review thread resolved.
You are interacting with an AI system.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.