A Game About Digging A Hole: fix crash after the intro #2304

Open
github-bot wants to merge 4 commits from github-bot/gh-2304 into main AGit
Owner

@⁠Oskie5802 on GitHub · 2026-11-16 19:58 UTC · original
Oskie5802:digging-hole-patcher-crash → main · +180 −22 · 1 files · 4 commits · open

Game:

A Game About Digging A Hole (PPSA30552, 01.100.000), issue #2249

Problem:

With --redzone, the game still crashed about 1.5-2 minutes in, after the intro, at eboot 0x323e347 inside the function at 0x323dfc0. That function is reached only through a pointer (lambda / virtual call), so it is neither listed in .eh_frame nor called directly. The red-zone patcher never found it and never protected its stores below RSP.

Depends on #2099

This PR is built on top of #2099 by @⁠joaocaparroz (red-zone protection for functions missing from .eh_frame) and includes its two commits unchanged. Only the last commit is new. If #2099 is merged first, I will rebase so this PR is just that one commit.

Change:

loader: Clang pads between functions with int3 up to the 16-byte function alignment, so the aligned address after the padding that ends a decoded function starts another function. The patcher now follows that padding to find the next function. When the decoded code does not reach the end of the function (an unresolved jump table), it steps over the remaining instructions up to the padding first.
Result: with --redzone, the patcher finds 257,989 functions in the eboot instead of 249,803, including the one that crashed.
Testing
Played from boot through the intro into gameplay without the crash (RX 6600, Windows 11). On this card the game also needs the AMD fixes from #2302 to render at all, so I tested both together.
CI test list on Windows: 32/32 pass.
Not tested on NVIDIA, Intel or Linux.

AI use

The investigation and the code were done with Claude Fable 5.2. I reviewed the changes and
tested them on my own hardware as described, this description are writted by human - Me :) and corrected by AI

**@⁠Oskie5802** on GitHub · 2026-11-16 19:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2304) `Oskie5802:digging-hole-patcher-crash` → `main` · +180 −22 · 1 files · 4 commits · open ### Game: A Game About Digging A Hole (PPSA30552, 01.100.000), issue #2249 ### Problem: With --redzone, the game still crashed about 1.5-2 minutes in, after the intro, at eboot 0x323e347 inside the function at 0x323dfc0. That function is reached only through a pointer (lambda / virtual call), so it is neither listed in .eh_frame nor called directly. The red-zone patcher never found it and never protected its stores below RSP. ### Depends on #2099 This PR is built on top of #2099 by @⁠joaocaparroz (red-zone protection for functions missing from .eh_frame) and includes its two commits unchanged. Only the last commit is new. If #2099 is merged first, I will rebase so this PR is just that one commit. ### Change: loader: Clang pads between functions with int3 up to the 16-byte function alignment, so the aligned address after the padding that ends a decoded function starts another function. The patcher now follows that padding to find the next function. When the decoded code does not reach the end of the function (an unresolved jump table), it steps over the remaining instructions up to the padding first. Result: with --redzone, the patcher finds 257,989 functions in the eboot instead of 249,803, including the one that crashed. Testing Played from boot through the intro into gameplay without the crash (RX 6600, Windows 11). On this card the game also needs the AMD fixes from #2302 to render at all, so I tested both together. CI test list on Windows: 32/32 pass. Not tested on NVIDIA, Intel or Linux. ### AI use The investigation and the code were done with Claude Fable 5.2. I reviewed the changes and tested them on my own hardware as described, this description are writted by human - Me :) and corrected by AI
--redzone only analyzed functions listed in .eh_frame, only recognized
RSP-relative red-zone operands, and dropped jump tables stored outside the
executable segment. Saros (PPSA07631) hits all three: leaf functions that are
not in .eh_frame keep locals below RSP, a Windows exception raised by a
tracked GPU write inside them overwrites those locals, and the game crashes
(a loop count turns into garbage and the loop runs past its buffer, or a
pointer reloads as null).

- Discover functions from the direct call targets of decoded code, to a
  fixpoint, so unlisted functions are analyzed instead of being decoded as
  the tail of the preceding function.
- Detect red-zone use through RBP in frame-pointer functions
  (push rbp; mov rbp, rsp; push/sub rsp) and protect such functions
  conservatively.
- Resolve jump tables that live anywhere in the loaded module (usually
  .rodata); targets are still required to be inside the function.
Direct calls into the current function's range were recorded only as
callees. When --redzone is off (--amd-cpu or the TSC-only path),
AddDecodedCallees does not run, so the function is never split there and
the entry of an unlisted function could end up inside a relocated span.
Record the target as a branch target as well, as before.
A Game About Digging A Hole (PPSA30552) crashed in a function reached only
through a pointer (eboot 0x323dfc0), which neither .eh_frame nor a direct call
names, so the red-zone patcher never protected its stores below RSP.

Clang pads between functions with int3 up to the 16-byte function alignment,
so the aligned address after the padding that ends a decoded function starts
another one. When the decoded code does not end the function (an unresolved
jump table), the walk steps over the remaining instructions up to the padding.
With --redzone the patcher now finds 257989 functions in the eboot instead of
249803, the crashing one included.
A call to the next instruction reads its own address with a following pop
and execution stays in the same function. Recording it as a callee split the
function at the pop, so liveness analysis could miss a red-zone store before
the call.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:23 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 20:06 UTC · original · edited 2026-11-16 20:21 UTC

Explain Change →

Walkthrough

The patcher records direct-call targets and expands known function starts through decoded callees and aligned functions after int3 padding. Jump-table reads can use tables within the loaded module image outside the executable segment. Red-zone analysis detects frame-pointer-relative accesses and marks affected functions for conservative tracking. When memory protection is enabled, the patch entry point runs callee discovery and checks for these accesses before liveness analysis.

Suggested reviewers: nmzik, ew-sudo

Change: Bug fix

Merge Risk: Low · up to 2f08d

The change fixes the post-intro crash by discovering more functions and detecting frame-pointer red-zone accesses. The new detection still misses some function shapes, so a few functions may remain unprotected. This is unlikely to cause regressions, but it is worth tightening before or soon after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "A Game About Digging A Hole: fix crash after the intro" names the game and the crash fix. The changeset modifies function discovery in guestInstructionPatcher.cpp so the red-zone patcher fi…
Description check Passed The description explains the problem (a crash about 1.5 to 2 minutes into the game with --redzone, in a function reached only through a pointer), the change (following int3 padding to find the next al…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "A Game About Digging A Hole: fix crash after the intro" names the game and the crash fix. The changeset modifies function discovery in guestInstructionPatcher.cpp so the red-zone patcher finds functions reached only through pointers, which addresses the crash described in the title. The title is specific and matches the primary change, though it does not name the technical mechanism (int3 padding follow-up and function discovery).

Full details: Description check

Explanation

The description explains the problem (a crash about 1.5 to 2 minutes into the game with --redzone, in a function reached only through a pointer), the change (following int3 padding to find the next aligned function start and stepping over instructions before unresolved jump tables), the test results, and the dependency on PR #2099. These points match the raw summary of the changes in guestInstructionPatcher.cpp.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 20:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2304#issuecomment-6927795470) · edited 2026-11-16 20:21 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/2304?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The patcher records direct-call targets and expands known function starts through decoded callees and aligned functions after `int3` padding. Jump-table reads can use tables within the loaded module image outside the executable segment. Red-zone analysis detects frame-pointer-relative accesses and marks affected functions for conservative tracking. When memory protection is enabled, the patch entry point runs callee discovery and checks for these accesses before liveness analysis. **Suggested reviewers:** `nmzik`, `ew-sudo` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"2f08d5200e9361ecf52d330498c85f648ac21e34" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · up to <code>2f08d</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `2f08d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"2f08d5200e9361ecf52d330498c85f648ac21e34","coveredCommitId":"2f08d5200e9361ecf52d330498c85f648ac21e34","kind":"reviewed"} --> The change fixes the post-intro crash by discovering more functions and detecting frame-pointer red-zone accesses. The new detection still misses some function shapes, so a few functions may remain unprotected. This is unlikely to cause regressions, but it is worth tightening before or soon after merge. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title "A Game About Digging A Hole: fix crash after the intro" names the game and the crash fix. The changeset modifies function discovery in guestInstructionPatcher.cpp so the red-zone patcher fi… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains the problem (a crash about 1.5 to 2 minutes into the game with --redzone, in a function reached only through a pointer), the change (following int3 padding to find the next al… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title "A Game About Digging A Hole: fix crash after the intro" names the game and the crash fix. The changeset modifies function discovery in guestInstructionPatcher.cpp so the red-zone patcher finds functions reached only through pointers, which addresses the crash described in the title. The title is specific and matches the primary change, though it does not name the technical mechanism (int3 padding follow-up and function discovery). </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description explains the problem (a crash about 1.5 to 2 minutes into the game with --redzone, in a function reached only through a pointer), the change (following int3 padding to find the next aligned function start and stepping over instructions before unresolved jump tables), the test results, and the dependency on PR `#2099`. These points match the raw summary of the changes in guestInstructionPatcher.cpp. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2304)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 20:06 UTC · original · edited 2026-11-16 20:22 UTC
On src/loader/guestInstructionPatcher.cpp line 550 (outdated):

@@ -531,6 +541,15 @@ DecodedFunction DecodeFunction(uintptr_t function_start, uintptr_t function_end,
 
 				const uintptr_t next_address  = address + decoded.instruction.length;
 				const uintptr_t branch_target = GetRelativeTarget(decoded);
+				if (decoded.instruction.meta.category == ZYDIS_CATEGORY_CALL) {
+					// A direct call always enters a function, even one that lies inside the
+					// caller's range because .eh_frame did not list it. Tail jumps are left
+					// out: they can target the middle of a function, and splitting it there
+					// would truncate the red-zone liveness of its first half.
+					if (branch_target >= segment_start && branch_target < segment_end) {
+						function.callees.insert(branch_target);

Minor · Functional Correctness · Quick win

Skip direct calls to the next instruction when recording callees.

A call to the next instruction returns to the code that follows it. A following pop reads the return address, and execution stays in the same function. The target is not a separate function entry, but line 549-550 records it as a callee. AddDecodedCallees then inserts it into starts, and the caller ends at the pop. Liveness analysis cannot see the pop as a successor. A red-zone store before the call can therefore be left unprotected, while the load after the pop is still protected.

The guard should exclude only the call target that equals the following instruction. Calls to other targets keep their current handling. Update the comment above the guard to match.

Suggested fix

 				if (decoded.instruction.meta.category == ZYDIS_CATEGORY_CALL) {
-					if (branch_target >= segment_start && branch_target < segment_end) {
+					if (branch_target != next_address && branch_target >= segment_start &&
+					    branch_target < segment_end) {
 						function.callees.insert(branch_target);
 					}
 				}

✅ Addressed in commit 2f08d52

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 20:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2304#discussion_r4590890105) · edited 2026-11-16 20:22 UTC On `src/loader/guestInstructionPatcher.cpp` line 550 (outdated): ```diff @@ -531,6 +541,15 @@ DecodedFunction DecodeFunction(uintptr_t function_start, uintptr_t function_end, const uintptr_t next_address = address + decoded.instruction.length; const uintptr_t branch_target = GetRelativeTarget(decoded); + if (decoded.instruction.meta.category == ZYDIS_CATEGORY_CALL) { + // A direct call always enters a function, even one that lies inside the + // caller's range because .eh_frame did not list it. Tail jumps are left + // out: they can target the middle of a function, and splitting it there + // would truncate the red-zone liveness of its first half. + if (branch_target >= segment_start && branch_target < segment_end) { + function.callees.insert(branch_target); ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** **Skip direct calls to the next instruction when recording callees.** A `call` to the next instruction returns to the code that follows it. A following `pop` reads the return address, and execution stays in the same function. The target is not a separate function entry, but line 549-550 records it as a callee. `AddDecodedCallees` then inserts it into `starts`, and the caller ends at the `pop`. Liveness analysis cannot see the `pop` as a successor. A red-zone store before the `call` can therefore be left unprotected, while the load after the `pop` is still protected. The guard should exclude only the call target that equals the following instruction. Calls to other targets keep their current handling. Update the comment above the guard to match. <details> <summary>Suggested fix</summary> <dl> <dd> <br> ```diff if (decoded.instruction.meta.category == ZYDIS_CATEGORY_CALL) { - if (branch_target >= segment_start && branch_target < segment_end) { + if (branch_target != next_address && branch_target >= segment_start && + branch_target < segment_end) { function.callees.insert(branch_target); } } ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3a3777695fc0708c9c7bebb4 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 2f08d52
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 20:06 UTC · original · reviewed

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d45b0865d8 and fb351dae58.

Files selected for processing: 1

  • src/loader/guestInstructionPatcher.cpp

Included 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-16 20:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2304#pullrequestreview-5926727794) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/d45b0865d85ced3da80f43ef2a2ecbeca6296637/.coderabbit.yaml>) - **Commit**: [d45b086](<https://github.com/KytyPS5/KytyPS5/commit/d45b0865d85ced3da80f43ef2a2ecbeca6296637>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f227d761-4c03-4319-beab-9f65fcc1a880` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between d45b0865d85ced3da80f43ef2a2ecbeca6296637 and fb351dae586aec89da23e2044f86d756e4e06073. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 1</summary> <dl> <dd> <br> * `src/loader/guestInstructionPatcher.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=e3cf0d1c-c518-44d8-9d71-f392aaa8a78a attempt=5bd39ff4-3d4f-4328-a2f5-b2aa3ca925d0 batch=1/1 -->
Author
Owner

@⁠Oskie5802 on GitHub · 2026-11-16 20:14 UTC · original
On src/loader/guestInstructionPatcher.cpp line 550 (outdated):

@@ -531,6 +541,15 @@ DecodedFunction DecodeFunction(uintptr_t function_start, uintptr_t function_end,
 
 				const uintptr_t next_address  = address + decoded.instruction.length;
 				const uintptr_t branch_target = GetRelativeTarget(decoded);
+				if (decoded.instruction.meta.category == ZYDIS_CATEGORY_CALL) {
+					// A direct call always enters a function, even one that lies inside the
+					// caller's range because .eh_frame did not list it. Tail jumps are left
+					// out: they can target the middle of a function, and splitting it there
+					// would truncate the red-zone liveness of its first half.
+					if (branch_target >= segment_start && branch_target < segment_end) {
+						function.callees.insert(branch_target);

This line comes from #2099, but the guard is cheap and safe, so I added it in 2f08d520. A call to the next instruction is no longer recorded as a function entry.

**@⁠Oskie5802** on GitHub · 2026-11-16 20:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2304#discussion_r4590974400) On `src/loader/guestInstructionPatcher.cpp` line 550 (outdated): ```diff @@ -531,6 +541,15 @@ DecodedFunction DecodeFunction(uintptr_t function_start, uintptr_t function_end, const uintptr_t next_address = address + decoded.instruction.length; const uintptr_t branch_target = GetRelativeTarget(decoded); + if (decoded.instruction.meta.category == ZYDIS_CATEGORY_CALL) { + // A direct call always enters a function, even one that lies inside the + // caller's range because .eh_frame did not list it. Tail jumps are left + // out: they can target the middle of a function, and splitting it there + // would truncate the red-zone liveness of its first half. + if (branch_target >= segment_start && branch_target < segment_end) { + function.callees.insert(branch_target); ``` This line comes from #2099, but the guard is cheap and safe, so I added it in 2f08d520. A call to the next instruction is no longer recorded as a function entry.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 20:21 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (4)

Major · Recognize frame setup after a leading instruction. · guestInstructionPatcher.cpp:679-681

src/loader/guestInstructionPatcher.cpp:679-681
Major · Functional Correctness · Heavy lift

Recognize frame setup after a leading instruction.

For endbr64; push rbp; mov rbp,rsp; mov [rbp-8],rax, this check returns before examining the access. The RSP-relative decoder also misses it, so liveness does not protect the red zone. Recognize valid leading instructions before the frame setup.

Major · Account for later stack-pointer changes. · guestInstructionPatcher.cpp:703-704

src/loader/guestInstructionPatcher.cpp:703-704
Major · Functional Correctness · Heavy lift

Account for later stack-pointer changes.

For push rbp; mov rbp,rsp; nop; sub rsp,0x100; mov [rbp-0x108],rax, the nop ends frame accounting with frame == 0. The access is eight bytes below the actual RSP, but the overlap test misses it. Track RSP changes at each access, or use conservative protection when the frame cannot be determined.

Minor · Keep an earlier red-zone match when a later instruction… · guestInstructionPatcher.cpp:714-717

src/loader/guestInstructionPatcher.cpp:714-717
Minor · Functional Correctness · Quick win

Keep an earlier red-zone match when a later instruction writes RBP.

When an RBP-relative red-zone access appears before a later write to RBP, the early return drops the local uses_red_zone result. The function never receives the red-zone flags, and liveness analysis runs without conservative tracking for that function. Record the match before returning. Accesses after the RBP write still fall outside the frame model and stay ignored.

Suggested fix

 		if (decoded.instruction.mnemonic != ZYDIS_MNEMONIC_POP &&
 		    decoded.instruction.mnemonic != ZYDIS_MNEMONIC_LEAVE &&
 		    WritesRegister(decoded, ZYDIS_REGISTER_RBP)) {
-			return;
+			if (uses_red_zone) {
+				function.uses_red_zone                           = true;
+				function.requires_conservative_red_zone_tracking = true;
+			}
+			return;
Minor · Track indexed RBP accesses as possible red-zone accesses. · guestInstructionPatcher.cpp:721-724

src/loader/guestInstructionPatcher.cpp:721-724
Minor · Functional Correctness · Quick win

Track indexed RBP accesses as possible red-zone accesses.

DetectFramePointerRedZone skips an RBP-based memory operand when it has an index register. The index is not evaluated, so the access address cannot be bounded. For example, push rbp; mov rbp,rsp; xor eax,eax; mov [rbp+rax-8],rdx stores 8 bytes below RSP. The RSP-relative decoder does not classify this operand as stack-relative, so no path marks the function as using the red zone. Conservative tracking for the function is then skipped.

Treat an indexed RBP access as a possible red-zone access. This triggers the same conservative tracking that the range check already uses. Accesses without an index keep the existing range check.

Suggested fix

-			if (operand.type != ZYDIS_OPERAND_TYPE_MEMORY ||
-			    operand.mem.base != ZYDIS_REGISTER_RBP ||
-			    operand.mem.index != ZYDIS_REGISTER_NONE || operand.mem.disp.size == 0) {
-				continue;
+			if (operand.type != ZYDIS_OPERAND_TYPE_MEMORY || operand.mem.base != ZYDIS_REGISTER_RBP) {
+				continue;
+			}
+			if (operand.mem.index != ZYDIS_REGISTER_NONE) {
+				// The effective address is unknown, so assume it can reach the red zone.
+				uses_red_zone = true;
+				continue;
+			}
+			if (operand.mem.disp.size == 0) {
+				continue;
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fb351dae58 and 2f08d5200e.

Files selected for processing: 1

  • src/loader/guestInstructionPatcher.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 20:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2304#pullrequestreview-5926951804) · **reviewed** <!-- coderabbit-ai-generated:v1 --> > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (4)** > > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major</strong> · Recognize frame setup after a leading instruction. · <code>guestInstructionPatcher.cpp:679-681</code></summary><blockquote> > <dl> > <dd> > <br> > > `src/loader/guestInstructionPatcher.cpp:679-681` > **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** > > **Recognize frame setup after a leading instruction.** > > For `endbr64; push rbp; mov rbp,rsp; mov [rbp-8],rax`, this check returns before examining the access. The RSP-relative decoder also misses it, so liveness does not protect the red zone. Recognize valid leading instructions before the frame setup. > > <!-- cr-comment:v1:961bc2accc0f5b9eda464394 --> > > </dd> > </dl> > </blockquote></details> > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major</strong> · Account for later stack-pointer changes. · <code>guestInstructionPatcher.cpp:703-704</code></summary><blockquote> > <dl> > <dd> > <br> > > `src/loader/guestInstructionPatcher.cpp:703-704` > **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Heavy lift** > > **Account for later stack-pointer changes.** > > For `push rbp; mov rbp,rsp; nop; sub rsp,0x100; mov [rbp-0x108],rax`, the `nop` ends frame accounting with `frame == 0`. The access is eight bytes below the actual RSP, but the overlap test misses it. Track RSP changes at each access, or use conservative protection when the frame cannot be determined. > > <!-- cr-comment:v1:c9d2b6c4079b8af876af6391 --> > > </dd> > </dl> > </blockquote></details> > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor</strong> · Keep an earlier red-zone match when a later instruction… · <code>guestInstructionPatcher.cpp:714-717</code></summary><blockquote> > <dl> > <dd> > <br> > > `src/loader/guestInstructionPatcher.cpp:714-717` > **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** > > **Keep an earlier red-zone match when a later instruction writes RBP.** > > When an RBP-relative red-zone access appears before a later write to RBP, the early `return` drops the local `uses_red_zone` result. The function never receives the red-zone flags, and liveness analysis runs without conservative tracking for that function. Record the match before returning. Accesses after the RBP write still fall outside the frame model and stay ignored. > > <details> > <summary>Suggested fix</summary> > <dl> > <dd> > <br> > > ```diff > if (decoded.instruction.mnemonic != ZYDIS_MNEMONIC_POP && > decoded.instruction.mnemonic != ZYDIS_MNEMONIC_LEAVE && > WritesRegister(decoded, ZYDIS_REGISTER_RBP)) { > - return; > + if (uses_red_zone) { > + function.uses_red_zone = true; > + function.requires_conservative_red_zone_tracking = true; > + } > + return; > ``` > > </dd> > </dl> > </details> > > <!-- cr-comment:v1:80f10f884736268124709352 --> > > </dd> > </dl> > </blockquote></details> > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor</strong> · Track indexed RBP accesses as possible red-zone accesses. · <code>guestInstructionPatcher.cpp:721-724</code></summary><blockquote> > <dl> > <dd> > <br> > > `src/loader/guestInstructionPatcher.cpp:721-724` > **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** > > **Track indexed RBP accesses as possible red-zone accesses.** > > `DetectFramePointerRedZone` skips an RBP-based memory operand when it has an index register. The index is not evaluated, so the access address cannot be bounded. For example, `push rbp; mov rbp,rsp; xor eax,eax; mov [rbp+rax-8],rdx` stores 8 bytes below RSP. The RSP-relative decoder does not classify this operand as stack-relative, so no path marks the function as using the red zone. Conservative tracking for the function is then skipped. > > Treat an indexed RBP access as a possible red-zone access. This triggers the same conservative tracking that the range check already uses. Accesses without an index keep the existing range check. > > <details> > <summary>Suggested fix</summary> > <dl> > <dd> > <br> > > ```diff > - if (operand.type != ZYDIS_OPERAND_TYPE_MEMORY || > - operand.mem.base != ZYDIS_REGISTER_RBP || > - operand.mem.index != ZYDIS_REGISTER_NONE || operand.mem.disp.size == 0) { > - continue; > + if (operand.type != ZYDIS_OPERAND_TYPE_MEMORY || operand.mem.base != ZYDIS_REGISTER_RBP) { > + continue; > + } > + if (operand.mem.index != ZYDIS_REGISTER_NONE) { > + // The effective address is unknown, so assume it can reach the red zone. > + uses_red_zone = true; > + continue; > + } > + if (operand.mem.disp.size == 0) { > + continue; > ``` > > </dd> > </dl> > </details> > > <!-- cr-comment:v1:23b2290558f6bfa77dd58d4e --> > > </dd> > </dl> > </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/d45b0865d85ced3da80f43ef2a2ecbeca6296637/.coderabbit.yaml>) - **Commit**: [d45b086](<https://github.com/KytyPS5/KytyPS5/commit/d45b0865d85ced3da80f43ef2a2ecbeca6296637>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `91c49a61-f76a-457f-ac9a-2def84c2ade0` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between fb351dae586aec89da23e2044f86d756e4e06073 and 2f08d5200e9361ecf52d330498c85f648ac21e34. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 1</summary> <dl> <dd> <br> * `src/loader/guestInstructionPatcher.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=9a56d948-b1f3-49f9-a291-8d6879122af1 attempt=4fa2c7bd-dc6e-4417-98eb-706866711cef batch=1/1 -->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2304/head:github-bot/gh-2304'
git switch 'github-bot/gh-2304'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2304'
git switch 'github-bot/gh-2304'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2304'
git switch 'github-bot/gh-2304'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2304'
git switch 'main'
git merge --squash 'github-bot/gh-2304'
git switch 'main'
git merge --ff-only 'github-bot/gh-2304'
git switch 'main'
git merge 'github-bot/gh-2304'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.