loader: resolve jump tables and tail calls in the guest patcher #1281

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

@⁠NeySlim on GitHub · 2026-10-09 07:24 UTC · original
NeySlim:fix/patcher-jump-tables → main · +1418 −155 · 4 files · 4 commits · open

Problem

With --amd-cpu, God of War Ragnarök (PPSA08332, 05.005) logs at startup:

AMD CPU compatibility: eboot.bin patched (VRSQRTPS: native=3362, trapped=522, skipped=0; ...)

The 522 trapped sites get the reserved VEX.vvvv mark and go through the SIGILL handler on every execution: 21,000 to 27,000 SIGILL per second from the opening cutscene on, from about 125 distinct sites.

All 522 sites are four-byte vrsqrtps xmm, xmm in functions with an indirect jump the patcher cannot resolve, so it may not borrow neighbouring bytes for the five-byte jump to a trampoline. 284 of the 291 unresolved jumps in these functions are switch dispatches. The PS5 toolchain puts jump tables in read-only data, a separate segment, and ResolveBoundedJumpTable only reads tables inside the executable segment being patched. Most dispatches also fall outside its single pattern: the index is zero-extended after the bounds check, other instructions sit between the load and the add, the table base is set before a loop, a loop jumps again through the same register, or the index is bounded by a mask or set from constants:

cmp  al, 8 ; ja default ; movzx eax, al ; lea rcx, [rip + table]
movsxd rax, [rcx + rax*4] ; add rax, rcx ; jmp rax

mov  rcx, rbx ; shr rcx, 34 ; and ecx, 3
movsxd rcx, [rsi + rcx*4] ; add rcx, rsi ; jmp rcx

mov r13d, 2 / mov r13d, 3 / setne cl ; movzx r13d, cl   (three paths)
mov eax, r13d ; movsxd rax, [rcx + rax*4] ; add rax, rcx ; jmp rax

Four are tail calls after the epilogue (pop rbp ; jmp rax, pop rbp ; jmp [rax+0x48]).

The cases of an unresolved table are never decoded either, so 129 VRSQRTPS in them were not found at all and ran with the host approximation.

Change

  • Jump tables are read from the module's PT_LOAD segments that are readable and not writable (registered by the loader with RegisterGuestInstructionPatchReadOnlyData), not only from the executable segment. A writable segment, a RELRO segment (still written by relocations) or a segment without permissions is never read.

  • A dispatch is matched from the definitions of the jump register that reach the jmp: each must be the add target, table of movsxd target, dword [table + index*4], with unrelated instructions allowed in between. A loop that jumps again with the same computed target resolves to the same cases.

  • The index bound comes from a cmp + ja/jae on the straight path before the load, through zero-extending copies (movzx r32, r8/r16, mov r32, r32, also when the copy precedes the compare), or from every definition reaching it: constants, setcc, and, shr, xor r, r and copies of bounded registers. A compare narrower than the index (cmp al, 3 for rax) counts only when the index definition clears the bits above it (movzx from a byte, and eax, 0xf).

  • The table base must be the same RIP-relative lea on every path to the load (reaching definitions over the decoded control flow).

  • A call clobbers every caller-saved register, in the reaching definitions and in each backward scan of the dispatch path (bound, base, load and target), so cmp ecx, 3 ; ja ; call f ; ... gives no bound for ecx.

  • The target and table registers of the add must differ: add rax, rax doubles the entry instead of adding the base.

  • Nothing may enter the straight path between the bound and the dispatch.

  • An unresolved indirect jump is a tail call, and leaves the function, only when both hold:

    • the stack is back at its entry depth (forward analysis of RSP over the decoded control flow, with RBP followed from mov rbp, rsp so leave, mov rsp, rbp and lea rsp, [rbp + disp] keep a known depth);
    • every value reaching the target is an address from outside the function: a 64-bit load without an index register and not from the stack (a vtable or import slot, whose base is RIP, an argument or itself such a load), a constant outside the function, a value from the caller, or a register copy of one of these;
    • no label of the function has its address taken. Such a value can still be one of its labels, for example a protothread or a labels-as-values state machine that stores &&resume in caller memory and jumps back there on a later call. The function loses its tail calls when the module holds the address of an instruction strictly inside it, or when it takes its own address (its entry included, as a base for label offsets). Taken addresses are the targets of RIP-relative lea in the code segment, decoded linearly from each function start, and of R_X86_64_RELATIVE and R_X86_64_64 relocations, which the loader registers with RegisterGuestInstructionPatchCodeAddresses. The loader now parses the dynamic info before patching, so relocations are known then.

    Anything else, for example the sum of an unmatched switch or an indexed table of absolute addresses after the epilogue, keeps the function marked as having an unresolved indirect jump, so no neighbouring bytes are borrowed and no short relay is used in it.

  • Once every edge is known, each match is checked again. If one no longer holds, or the decoded instructions overlap, the function falls back to direct control flow only, as before.

  • Fix: the red-zone liveness analysis (Windows) now follows jump-table edges. Before, a resolved dispatch had no successors in it, so a red zone read only in a case was considered dead before the dispatch and a faultable instruction there was left unprotected.

Test

Three new tests in virtual_memory_allocation_tests (Linux and Windows, also under --rsqrt-only).

ReciprocalSquareRootBesideJumpTables: the table sits in read-only data of the module, outside the patched segment.

  • Accepted: a bounds check, a byte index, a mask, a byte compare of a masked index, a base set before a branch, a re-dispatch loop, an index set from constants and a flag, a tail call through a constant and one through a pointer slot (jmp [rax]). Both the straight-line site and the one in case 0 must be patched natively, run without SIGILL with exact results, and reach the right case for every selector.
  • Rejected, the straight-line site must stay trapped and still run correctly: an unbounded index, a byte compare of a 32-bit index, the index rewritten after the guard, two different lea bases, a branch entering the path below the guard, a call clobbering the index, a call clobbering the base, a table entry outside the function, add rax, rax (target register is the base), a table in writable memory, an unmatched dispatch after the epilogue, an absolute table after the epilogue, an indirect jump with the frame still in place, a second dispatch whose entry enters the first one's path (final re-check fallback) and an entry inside an instruction (overlap fallback).

ReciprocalSquareRootBesideAddressTakenLabels: a resumable function saves a label placed right after a four-byte vrsqrtps, and a later call jumps there through caller memory (mov rax, [rdi] ; jmp rax or jmp [rdi]). The label address comes from a lea in the function, an offset from its entry, a lea in another function or a registered relocation: the site must stay trapped, and the second call must continue after the label. With no label address taken, the same jump stays a tail call and the site is patched natively. Each source was checked by removing its handling: the corresponding case fails.

RedZoneLivenessAcrossJumpTables: runs the red-zone patcher (platform-independent code, so it runs on Linux too) on a leaf function that writes the red zone, dispatches through a table and reads it back only in case 0. The table load must be protected.

Each rejection added with this revision and the red-zone fix was checked by reverting it: the corresponding case fails. The first revision of the jump-table test fails on main (trapped instead of native).

Validation

Linux, Ryzen AI Max+ 395 (Zen 5), Radeon 8060S, Mesa RADV 26.2.3.

  • GoW eboot, same patcher code run offline on the extracted image: VRSQRTPS found 3884 to 4013, native 3362 to 4013, trapped 522 to 0. 4780 jump tables and 583 tail calls resolved; 66 functions keep an unresolved indirect jump, one falls back after the final check. No function with a tail call has a label whose address is taken by a lea or a relocation; one takes its own entry address (it passes itself as a callback) and keeps its jump unresolved, with no effect on the counts above. The pass takes about 1.55 s of CPU time instead of 1.15 s on main (fastest of 6 runs); finding the taken addresses costs about 0.15 s of it.
  • Same offline pass with the red-zone protection on, as Windows runs it: red-zone memory instructions found 28234 to 28958, left unrelocatable 99 to 0, red-zone functions with an unresolved indirect jump 8 to 0.
  • In game, new game to the sled ride (measured with the first revision of this PR; the current one patches the same 4013 sites natively, checked in the startup log), signals counted with perf stat -e signal:signal_deliver: the log now reads VRSQRTPS: native=4013, trapped=0; SIGILL go from 24,500 per second (the main game thread and the 11 task threads) to none, and all signals from 53,000 to 25,000 per second (the rest are write-tracking faults). A bare SIGILL round trip costs about 0.6 us on this CPU before any emulation, so this saves a few percent of one core. The frame rate does not change beyond run-to-run noise (12.3 fps before, 12.1 after, over the first 3 minutes of gameplay): the GPU command thread limits this game today. Rendering is unchanged.
  • virtual_memory_allocation_tests: all pass, as on main.

Not tested on Windows or macOS. The analysis is platform-independent; on Windows the red-zone patcher now runs its precise liveness analysis on more functions, and that analysis now follows jump-table edges.

Related: #833 also reads jump tables outside the code segment, in the red-zone patcher.

AI use

I used Claude Code (AI agent) to find why these sites were trapped, write the change and the test, and run the measurements above on my machine. I reviewed the diff and the results before opening this PR.

**@⁠NeySlim** on GitHub · 2026-10-09 07:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281) `NeySlim:fix/patcher-jump-tables` → `main` · +1418 −155 · 4 files · 4 commits · open ## Problem With `--amd-cpu`, God of War Ragnarök (PPSA08332, 05.005) logs at startup: ``` AMD CPU compatibility: eboot.bin patched (VRSQRTPS: native=3362, trapped=522, skipped=0; ...) ``` The 522 trapped sites get the reserved VEX.vvvv mark and go through the SIGILL handler on every execution: 21,000 to 27,000 SIGILL per second from the opening cutscene on, from about 125 distinct sites. All 522 sites are four-byte `vrsqrtps xmm, xmm` in functions with an indirect jump the patcher cannot resolve, so it may not borrow neighbouring bytes for the five-byte jump to a trampoline. 284 of the 291 unresolved jumps in these functions are switch dispatches. The PS5 toolchain puts jump tables in read-only data, a separate segment, and `ResolveBoundedJumpTable` only reads tables inside the executable segment being patched. Most dispatches also fall outside its single pattern: the index is zero-extended after the bounds check, other instructions sit between the load and the add, the table base is set before a loop, a loop jumps again through the same register, or the index is bounded by a mask or set from constants: ``` cmp al, 8 ; ja default ; movzx eax, al ; lea rcx, [rip + table] movsxd rax, [rcx + rax*4] ; add rax, rcx ; jmp rax mov rcx, rbx ; shr rcx, 34 ; and ecx, 3 movsxd rcx, [rsi + rcx*4] ; add rcx, rsi ; jmp rcx mov r13d, 2 / mov r13d, 3 / setne cl ; movzx r13d, cl (three paths) mov eax, r13d ; movsxd rax, [rcx + rax*4] ; add rax, rcx ; jmp rax ``` Four are tail calls after the epilogue (`pop rbp ; jmp rax`, `pop rbp ; jmp [rax+0x48]`). The cases of an unresolved table are never decoded either, so 129 VRSQRTPS in them were not found at all and ran with the host approximation. ## Change - Jump tables are read from the module's `PT_LOAD` segments that are readable and not writable (registered by the loader with `RegisterGuestInstructionPatchReadOnlyData`), not only from the executable segment. A writable segment, a RELRO segment (still written by relocations) or a segment without permissions is never read. - A dispatch is matched from the definitions of the jump register that reach the `jmp`: each must be the `add target, table` of `movsxd target, dword [table + index*4]`, with unrelated instructions allowed in between. A loop that jumps again with the same computed target resolves to the same cases. - The index bound comes from a `cmp` + `ja`/`jae` on the straight path before the load, through zero-extending copies (`movzx r32, r8/r16`, `mov r32, r32`, also when the copy precedes the compare), or from every definition reaching it: constants, `setcc`, `and`, `shr`, `xor r, r` and copies of bounded registers. A compare narrower than the index (`cmp al, 3` for `rax`) counts only when the index definition clears the bits above it (`movzx` from a byte, `and eax, 0xf`). - The table base must be the same RIP-relative `lea` on every path to the load (reaching definitions over the decoded control flow). - A call clobbers every caller-saved register, in the reaching definitions and in each backward scan of the dispatch path (bound, base, load and target), so `cmp ecx, 3 ; ja ; call f ; ...` gives no bound for `ecx`. - The target and table registers of the `add` must differ: `add rax, rax` doubles the entry instead of adding the base. - Nothing may enter the straight path between the bound and the dispatch. - An unresolved indirect jump is a tail call, and leaves the function, only when both hold: - the stack is back at its entry depth (forward analysis of RSP over the decoded control flow, with RBP followed from `mov rbp, rsp` so `leave`, `mov rsp, rbp` and `lea rsp, [rbp + disp]` keep a known depth); - every value reaching the target is an address from outside the function: a 64-bit load without an index register and not from the stack (a vtable or import slot, whose base is RIP, an argument or itself such a load), a constant outside the function, a value from the caller, or a register copy of one of these; - no label of the function has its address taken. Such a value can still be one of its labels, for example a protothread or a labels-as-values state machine that stores `&&resume` in caller memory and jumps back there on a later call. The function loses its tail calls when the module holds the address of an instruction strictly inside it, or when it takes its own address (its entry included, as a base for label offsets). Taken addresses are the targets of RIP-relative `lea` in the code segment, decoded linearly from each function start, and of `R_X86_64_RELATIVE` and `R_X86_64_64` relocations, which the loader registers with `RegisterGuestInstructionPatchCodeAddresses`. The loader now parses the dynamic info before patching, so relocations are known then. Anything else, for example the sum of an unmatched switch or an indexed table of absolute addresses after the epilogue, keeps the function marked as having an unresolved indirect jump, so no neighbouring bytes are borrowed and no short relay is used in it. - Once every edge is known, each match is checked again. If one no longer holds, or the decoded instructions overlap, the function falls back to direct control flow only, as before. - Fix: the red-zone liveness analysis (Windows) now follows jump-table edges. Before, a resolved dispatch had no successors in it, so a red zone read only in a case was considered dead before the dispatch and a faultable instruction there was left unprotected. ## Test Three new tests in `virtual_memory_allocation_tests` (Linux and Windows, also under `--rsqrt-only`). `ReciprocalSquareRootBesideJumpTables`: the table sits in read-only data of the module, outside the patched segment. - Accepted: a bounds check, a byte index, a mask, a byte compare of a masked index, a base set before a branch, a re-dispatch loop, an index set from constants and a flag, a tail call through a constant and one through a pointer slot (`jmp [rax]`). Both the straight-line site and the one in case 0 must be patched natively, run without SIGILL with exact results, and reach the right case for every selector. - Rejected, the straight-line site must stay trapped and still run correctly: an unbounded index, a byte compare of a 32-bit index, the index rewritten after the guard, two different `lea` bases, a branch entering the path below the guard, a call clobbering the index, a call clobbering the base, a table entry outside the function, `add rax, rax` (target register is the base), a table in writable memory, an unmatched dispatch after the epilogue, an absolute table after the epilogue, an indirect jump with the frame still in place, a second dispatch whose entry enters the first one's path (final re-check fallback) and an entry inside an instruction (overlap fallback). `ReciprocalSquareRootBesideAddressTakenLabels`: a resumable function saves a label placed right after a four-byte `vrsqrtps`, and a later call jumps there through caller memory (`mov rax, [rdi] ; jmp rax` or `jmp [rdi]`). The label address comes from a `lea` in the function, an offset from its entry, a `lea` in another function or a registered relocation: the site must stay trapped, and the second call must continue after the label. With no label address taken, the same jump stays a tail call and the site is patched natively. Each source was checked by removing its handling: the corresponding case fails. `RedZoneLivenessAcrossJumpTables`: runs the red-zone patcher (platform-independent code, so it runs on Linux too) on a leaf function that writes the red zone, dispatches through a table and reads it back only in case 0. The table load must be protected. Each rejection added with this revision and the red-zone fix was checked by reverting it: the corresponding case fails. The first revision of the jump-table test fails on main (trapped instead of native). ## Validation Linux, Ryzen AI Max+ 395 (Zen 5), Radeon 8060S, Mesa RADV 26.2.3. - GoW eboot, same patcher code run offline on the extracted image: VRSQRTPS found 3884 to 4013, native 3362 to 4013, trapped 522 to 0. 4780 jump tables and 583 tail calls resolved; 66 functions keep an unresolved indirect jump, one falls back after the final check. No function with a tail call has a label whose address is taken by a `lea` or a relocation; one takes its own entry address (it passes itself as a callback) and keeps its jump unresolved, with no effect on the counts above. The pass takes about 1.55 s of CPU time instead of 1.15 s on main (fastest of 6 runs); finding the taken addresses costs about 0.15 s of it. - Same offline pass with the red-zone protection on, as Windows runs it: red-zone memory instructions found 28234 to 28958, left unrelocatable 99 to 0, red-zone functions with an unresolved indirect jump 8 to 0. - In game, new game to the sled ride (measured with the first revision of this PR; the current one patches the same 4013 sites natively, checked in the startup log), signals counted with `perf stat -e signal:signal_deliver`: the log now reads `VRSQRTPS: native=4013, trapped=0`; SIGILL go from 24,500 per second (the main game thread and the 11 task threads) to none, and all signals from 53,000 to 25,000 per second (the rest are write-tracking faults). A bare SIGILL round trip costs about 0.6 us on this CPU before any emulation, so this saves a few percent of one core. The frame rate does not change beyond run-to-run noise (12.3 fps before, 12.1 after, over the first 3 minutes of gameplay): the GPU command thread limits this game today. Rendering is unchanged. - `virtual_memory_allocation_tests`: all pass, as on main. Not tested on Windows or macOS. The analysis is platform-independent; on Windows the red-zone patcher now runs its precise liveness analysis on more functions, and that analysis now follows jump-table edges. Related: #833 also reads jump tables outside the code segment, in the red-zone patcher. ## AI use I used Claude Code (AI agent) to find why these sites were trapped, write the change and the test, and run the measurements above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:10 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:29 UTC · original · edited 2026-10-12 16:02 UTC

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bc4e0e24-6151-4fda-9575-0750551dce28

📥 Commits

Reviewing files that changed from the base of the PR and between 97aca38070a47801b1b01c7fe04611b17e8aaa5c and 2abb606956.


📒 Files selected for processing (4)
  • src/loader/guestInstructionPatcher.cpp
  • src/loader/guestInstructionPatcher.h
  • src/loader/runtimeLinker.cpp
  • tests/VirtualMemoryAllocationTests.cpp

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 92e97a10-6f79-43f7-b376-dab1f36a4ff4

📥 Commits

Reviewing files that changed from the base of the PR and between 1feb4c5b522225fd219a14d19dc0a8e24706d786 and 97aca38070a47801b1b01c7fe04611b17e8aaa5c.


📒 Files selected for processing (4)
  • src/loader/guestInstructionPatcher.cpp
  • src/loader/guestInstructionPatcher.h
  • src/loader/runtimeLinker.cpp
  • tests/VirtualMemoryAllocationTests.cpp

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



📝 Walkthrough

Walkthrough

The patcher analyzes control flow and register definitions to resolve eligible bounded jump tables. It adds resolved targets to decoding and red-zone liveness analysis, and classifies indirect branches using stack depth and target provenance. The runtime linker registers qualifying read-only segments and relocation-derived code addresses. Generated-code tests cover patching behavior for jump tables, address-taken labels, and red-zone liveness.

Suggested reviewers: nmzik


Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 97aca

This change resolves more jump tables and tail calls so that additional reciprocal-square-root sites can be patched natively. No outstanding defects were identified at the current head, and the earlier concern about tail-call classification has been addressed. Windows and macOS runs were not reported.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 47.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description check Passed The description clearly explains the unresolved jump-table and tail-call problem, the implementation changes, tests, and validation results.
Title check Passed The title directly and concisely summarizes the main change: resolving jump tables and tail calls in the guest patcher.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#issuecomment-6076495808) · edited 2026-10-12 16:02 UTC <!-- 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/1281?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: rate limited by coderabbit.ai --> > [!WARNING] > ## Review limit reached > > You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. > > **Next included review available in 14 minutes.** > > [Check out review usage here](https://app.coderabbit.ai/dashboard/review-capacity?orgId=d7cf2749-f181-4119-ba0c-ad79606afdfe). > > <details> > <summary><strong>View limit details</strong></summary> > <dl> > <dd> > > **Limit details:** You’ve used all 8 included reviews currently available. > > [Learn how review limits work](https://docs.coderabbit.ai/management/plans#rate-limits). > > **Review configuration:** > > <details> > <summary><strong>⚙️ Run configuration</strong></summary> > <dl> > <dd> > > - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml > - **Review profile**: CHILL > - **Plan**: Advanced > - **Run ID**: `bc4e0e24-6151-4fda-9575-0750551dce28` > > > <hr> > > </dd> > </dl> > </details> > > <details> > <summary><strong>📥 Commits</strong></summary> > <dl> > <dd> > > Reviewing files that changed from the base of the PR and between 97aca38070a47801b1b01c7fe04611b17e8aaa5c and 2abb60695604f78f8f43b125e952eb0349f19a41. > > > <hr> > > </dd> > </dl> > </details> > > <details> > <summary><strong>📒 Files selected for processing (4)</strong></summary> > <dl> > <dd> > > * `src/loader/guestInstructionPatcher.cpp` > * `src/loader/guestInstructionPatcher.h` > * `src/loader/runtimeLinker.cpp` > * `tests/VirtualMemoryAllocationTests.cpp` > > </dd> > </dl> > </details> > > > <hr> > > </dd> > </dl> > </details> <!-- end of auto-generated comment: rate limited by coderabbit.ai --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `92e97a10-6f79-43f7-b376-dab1f36a4ff4` <hr> </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 1feb4c5b522225fd219a14d19dc0a8e24706d786 and 97aca38070a47801b1b01c7fe04611b17e8aaa5c. <hr> </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (4)</strong></summary> <dl> <dd> * `src/loader/guestInstructionPatcher.cpp` * `src/loader/guestInstructionPatcher.h` * `src/loader/runtimeLinker.cpp` * `tests/VirtualMemoryAllocationTests.cpp` <hr> </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review. <hr> </dd> </dl> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough The patcher analyzes control flow and register definitions to resolve eligible bounded jump tables. It adds resolved targets to decoding and red-zone liveness analysis, and classifies indirect branches using stack depth and target provenance. The runtime linker registers qualifying read-only segments and relocation-derived code addresses. Generated-code tests cover patching behavior for jump tables, address-taken labels, and red-zone liveness. **Suggested reviewers:** `nmzik` <hr> </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"97aca38070a47801b1b01c7fe04611b17e8aaa5c" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `97aca` <!-- final_review_risk_coverage:{"sourceCommitId":"97aca38070a47801b1b01c7fe04611b17e8aaa5c","coveredCommitId":"97aca38070a47801b1b01c7fe04611b17e8aaa5c","kind":"reviewed"} --> This change resolves more jump tables and tail calls so that additional reciprocal-square-root sites can be patched natively. No outstanding defects were identified at the current head, and the earlier concern about tail-call classification has been addressed. Windows and macOS runs were not reported. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>🚥 Pre-merge checks | ✅ 4 | ❌ 1</strong></summary> <dl> <dd> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 47.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ Passed checks (4 passed)</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------- | | 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. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description clearly explains the unresolved jump-table and tail-call problem, the implementation changes, tests, and validation results. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title directly and concisely summarizes the main change: resolving jump tables and tail calls in the guest patcher. | </dd> </dl> </details> <hr> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1281)! 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> - [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) <hr> </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 09:47 UTC · original

Updated after a review of the matching rules (1feb4c5b):

  • Tail calls: an unresolved indirect jump now leaves the function only if the stack is back at its entry depth and every value reaching the target comes from outside the function (pointer slot, constant outside it, caller value). The old pop rbp/leave rule also accepted an unmatched dispatch after the epilogue.
  • A call now clobbers caller-saved registers in every backward scan of the dispatch path, not only in the reaching definitions.
  • add rax, rax (target register equals the base) is rejected.
  • Tables are read only from readable, non-writable PT_LOAD segments registered by the loader.
  • Tests: 14 rejection cases, including the final re-check and overlap fallbacks, plus a red-zone liveness test across jump-table edges. Each new rejection was checked by reverting its fix.

GoW counts are unchanged (VRSQRTPS native 4013, trapped 0). Tail calls resolved go from 358 to 584 and functions with an unresolved indirect jump from 286 to 65. The body has the details.

**@⁠NeySlim** on GitHub · 2026-10-09 09:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#issuecomment-6078493480) Updated after a review of the matching rules (1feb4c5b): - Tail calls: an unresolved indirect jump now leaves the function only if the stack is back at its entry depth and every value reaching the target comes from outside the function (pointer slot, constant outside it, caller value). The old `pop rbp`/`leave` rule also accepted an unmatched dispatch after the epilogue. - A call now clobbers caller-saved registers in every backward scan of the dispatch path, not only in the reaching definitions. - `add rax, rax` (target register equals the base) is rejected. - Tables are read only from readable, non-writable `PT_LOAD` segments registered by the loader. - Tests: 14 rejection cases, including the final re-check and overlap fallbacks, plus a red-zone liveness test across jump-table edges. Each new rejection was checked by reverting its fix. GoW counts are unchanged (VRSQRTPS native 4013, trapped 0). Tail calls resolved go from 358 to 584 and functions with an unresolved indirect jump from 286 to 65. The body has the details.
@ -509,0 +1032,4 @@
default: return false;
}
});
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 09:52 UTC · original · edited 2026-10-09 10:07 UTC

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Indirect jumps through caller-owned memory are classified as tail calls even when they can target internal labels.

IsIndirectTailJump treats a jump as leaving the function when the stack depth is 0 and the target comes from the caller or from a pointer slot. The comment on lines 985-986 says "A caller cannot hold an address inside it." That premise fails when an earlier call of the same function stored an internal address in memory that the caller owns.

Example: a protothread or labels-as-values state machine.

  • One invocation runs lea rcx, [rip+resume]; mov [rdi+8], rcx.
  • A later invocation runs jmp [rdi+8], or mov rax, [rdi+8]; jmp rax, at depth 0.

The code accepts that jump at three places:

  • IsPointerSlot(..., check_base=true) gets entry_reached = true with no definitions for rdi, so all_of over the empty set is true.
  • HoldsExternalAddress accepts the MOV from that slot in the same way.
  • At the nested level, IsPointerSlot(..., false) accepts any base except RSP and RBP. Its doc comment says the base must be RIP, an argument, or such a pointer.

The same gap applies to a RIP-relative slot in writable data that the function itself fills with lea. It also applies to a constant-index read from a static &&label array.

Consequence: function.has_indirect_branch becomes false, so RelocateGuestInstructions may borrow neighboring bytes. The resume label is not in branch_targets, because a lea does not record its operand. A relocation span can therefore cover that label. The next resume then jumps into the overwritten jmp/nop bytes, which corrupts guest control flow or crashes it. The PR description says tail-call resolution grew from 358 to 584, so the new rules accept more of these jumps than before.

Fix: Before accepting a tail call, prove that the function never computes an address inside itself.

  • Reject the classification if any decoded instruction is a RIP-relative lea, or a mov r64, imm, whose result lies in [function_start, function_end) and is not a resolved jump-table base.
  • For a RIP-relative slot, accept the jump only if the slot is in read_only_data and its stored value lies outside the function.
Sketch of the guard
// Before classifying any indirect jump as a tail jump:
const bool materializes_internal_address = std::ranges::any_of(
    function.instructions, [&](const auto& entry) {
        const auto& decoded = entry.second;
        const auto& op      = decoded.operands[0];
        if (op.type != ZYDIS_OPERAND_TYPE_REGISTER) return false;
        std::optional<uintptr_t> value = DecodeRipRelativeLea(decoded, op.reg.value);
        if (!value && decoded.instruction.mnemonic == ZYDIS_MNEMONIC_MOV &&
            decoded.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE) {
            value = decoded.operands[1].imm.value.u;
        }
        return value && *value >= function_start && *value < function_end;
    });
// Treat every unresolved indirect jump as unknown when this is true.

✅ Addressed in commit 737087e

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 09:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#discussion_r4228850694) · edited 2026-10-09 10:07 UTC **🎯 Functional Correctness** | **🟠 Major** | **🏗️ Heavy lift** **Indirect jumps through caller-owned memory are classified as tail calls even when they can target internal labels.** `IsIndirectTailJump` treats a jump as leaving the function when the stack depth is 0 and the target comes from the caller or from a pointer slot. The comment on lines 985-986 says "A caller cannot hold an address inside it." That premise fails when an earlier call of the same function stored an internal address in memory that the caller owns. Example: a protothread or labels-as-values state machine. - One invocation runs `lea rcx, [rip+resume]; mov [rdi+8], rcx`. - A later invocation runs `jmp [rdi+8]`, or `mov rax, [rdi+8]; jmp rax`, at depth 0. The code accepts that jump at three places: - `IsPointerSlot(..., check_base=true)` gets `entry_reached = true` with no definitions for `rdi`, so `all_of` over the empty set is true. - `HoldsExternalAddress` accepts the `MOV` from that slot in the same way. - At the nested level, `IsPointerSlot(..., false)` accepts any base except RSP and RBP. Its doc comment says the base must be RIP, an argument, or such a pointer. The same gap applies to a RIP-relative slot in writable data that the function itself fills with `lea`. It also applies to a constant-index read from a static `&&label` array. Consequence: `function.has_indirect_branch` becomes false, so `RelocateGuestInstructions` may borrow neighboring bytes. The `resume` label is not in `branch_targets`, because a `lea` does not record its operand. A relocation span can therefore cover that label. The next resume then jumps into the overwritten `jmp`/`nop` bytes, which corrupts guest control flow or crashes it. The PR description says tail-call resolution grew from 358 to 584, so the new rules accept more of these jumps than before. Fix: Before accepting a tail call, prove that the function never computes an address inside itself. - Reject the classification if any decoded instruction is a RIP-relative `lea`, or a `mov r64, imm`, whose result lies in `[function_start, function_end)` and is not a resolved jump-table base. - For a RIP-relative slot, accept the jump only if the slot is in `read_only_data` and its stored value lies outside the function. <details> <summary>Sketch of the guard</summary> ```cpp // Before classifying any indirect jump as a tail jump: const bool materializes_internal_address = std::ranges::any_of( function.instructions, [&](const auto& entry) { const auto& decoded = entry.second; const auto& op = decoded.operands[0]; if (op.type != ZYDIS_OPERAND_TYPE_REGISTER) return false; std::optional<uintptr_t> value = DecodeRipRelativeLea(decoded, op.reg.value); if (!value && decoded.instruction.mnemonic == ZYDIS_MNEMONIC_MOV && decoded.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE) { value = decoded.operands[1].imm.value.u; } return value && *value >= function_start && *value < function_end; }); // Treat every unresolved indirect jump as unknown when this is true. ``` </details> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:bf15a8a4e81e3127c72253da --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 737087e
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 09:52 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0eb1f1b-ca0d-4904-ade1-c2b313b6c6b6
📥 Commits

Reviewing files that changed from the base of the PR and between a7719317a8b7ac779f329f855cc132f636b038e3 and 1feb4c5b522225fd219a14d19dc0a8e24706d786.

📒 Files selected for processing (4)
  • src/loader/guestInstructionPatcher.cpp
  • src/loader/guestInstructionPatcher.h
  • src/loader/runtimeLinker.cpp
  • tests/VirtualMemoryAllocationTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 09:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#pullrequestreview-5468502672) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `a0eb1f1b-ca0d-4904-ade1-c2b313b6c6b6` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between a7719317a8b7ac779f329f855cc132f636b038e3 and 1feb4c5b522225fd219a14d19dc0a8e24706d786. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/loader/guestInstructionPatcher.cpp` * `src/loader/guestInstructionPatcher.h` * `src/loader/runtimeLinker.cpp` * `tests/VirtualMemoryAllocationTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=acf31458-f4f4-47e6-b160-3175241d0e02 attempt=404cc302-f6c9-4150-b088-e82bd752c7c3 batch=1/1 -->
@ -509,0 +1032,4 @@
default: return false;
}
});
}
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 10:07 UTC · original

Right: a value from the caller or a pointer slot can still be a label of the function once its address is stored somewhere, so the premise did not hold.

Fixed in 737087e3 with an address-taken check. An unresolved indirect jump is no longer a tail call when the module holds the address of an instruction strictly inside the function, or when the function takes its own address (entry included, as a base for label offsets). Taken addresses are the targets of RIP-relative lea in the code segment (linear decode from each function start, so lea in other functions count too) and of R_X86_64_RELATIVE / R_X86_64_64 relocations, registered by the loader through RegisterGuestInstructionPatchCodeAddresses; the dynamic info is now parsed before patching. The IsPointerSlot comment now matches the nested case.

Test: ReciprocalSquareRootBesideAddressTakenLabels. A resumable function stores a label placed right after a four-byte vrsqrtps and a later call jumps there (mov rax, [rdi] ; jmp rax or jmp [rdi]), with the address from a lea in the function, an offset from its entry, a lea in another function or a relocation. The site must stay trapped and the resumed call must continue after the label; with no address taken it stays a native tail call. Removing each source fails its case.

GoW: 584 to 583 tail calls (one function takes its own entry as a callback), VRSQRTPS still 4013 native, 0 trapped.

**@⁠NeySlim** on GitHub · 2026-10-09 10:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#discussion_r4228971868) Right: a value from the caller or a pointer slot can still be a label of the function once its address is stored somewhere, so the premise did not hold. Fixed in 737087e3 with an address-taken check. An unresolved indirect jump is no longer a tail call when the module holds the address of an instruction strictly inside the function, or when the function takes its own address (entry included, as a base for label offsets). Taken addresses are the targets of RIP-relative `lea` in the code segment (linear decode from each function start, so `lea` in other functions count too) and of `R_X86_64_RELATIVE` / `R_X86_64_64` relocations, registered by the loader through `RegisterGuestInstructionPatchCodeAddresses`; the dynamic info is now parsed before patching. The `IsPointerSlot` comment now matches the nested case. Test: `ReciprocalSquareRootBesideAddressTakenLabels`. A resumable function stores a label placed right after a four-byte `vrsqrtps` and a later call jumps there (`mov rax, [rdi] ; jmp rax` or `jmp [rdi]`), with the address from a `lea` in the function, an offset from its entry, a `lea` in another function or a relocation. The site must stay trapped and the resumed call must continue after the label; with no address taken it stays a native tail call. Removing each source fails its case. GoW: 584 to 583 tail calls (one function takes its own entry as a callback), VRSQRTPS still 4013 native, 0 trapped.
@ -509,0 +1032,4 @@
default: return false;
}
});
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 10:08 UTC · original

@NeySlim, thanks for the fix and the explanation. The supplied DecodeFunction checks module-held internal addresses and addresses taken by the function before accepting an unresolved indirect jump as a tail call. This addresses the unsafe neighboring-byte relocation described in the finding.

The reported regression cases cover both jump forms and the address sources. The no-address-taken case also checks that native tail-call patching remains available. I have not independently run the tests.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1281
File: src/loader/guestInstructionPatcher.cpp:987-1018
Timestamp: 2026-10-09T10:08:03.900Z
Learning: In src/loader/guestInstructionPatcher.cpp, caller-provided targets and pointer slots can contain internal function labels across invocations. Tail-jump classification must account for address-taken labels. DecodeFunction checks module-held addresses strictly inside the function and RIP-relative LEA targets taken by the function, including its entry as a base for label offsets. Module address tracking includes RIP-relative LEA targets from other functions and R_X86_64_RELATIVE / R_X86_64_64 relocation targets registered through RegisterGuestInstructionPatchCodeAddresses.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 10:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#discussion_r4228976430) `@NeySlim`, thanks for the fix and the explanation. The supplied `DecodeFunction` checks module-held internal addresses and addresses taken by the function before accepting an unresolved indirect jump as a tail call. This addresses the unsafe neighboring-byte relocation described in the finding. The reported regression cases cover both jump forms and the address sources. The no-address-taken case also checks that native tail-call patching remains available. I have not independently run the tests. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1281 File: src/loader/guestInstructionPatcher.cpp:987-1018 Timestamp: 2026-10-09T10:08:03.900Z Learning: In src/loader/guestInstructionPatcher.cpp, caller-provided targets and pointer slots can contain internal function labels across invocations. Tail-jump classification must account for address-taken labels. DecodeFunction checks module-held addresses strictly inside the function and RIP-relative LEA targets taken by the function, including its entry as a base for label offsets. Module address tracking includes RIP-relative LEA targets from other functions and R_X86_64_RELATIVE / R_X86_64_64 relocation targets registered through RegisterGuestInstructionPatchCodeAddresses. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Indirect%20jumps%20may%20target%20stored%20internal%20labels%2C%20so%20misclassifying%20them%20as%20tail%20calls%20can%20corrupt%20resume%20code.%20CodeRabbit%E2%80%99s%20address-taken%20check%20prevents%20it%E2%80%94try%20%40coderabbitai%20%F0%9F%9B%A1%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1281%23discussion_r4228850694)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 12:07 UTC · original

Follow-up from another review pass (97aca380): a cmp guard narrower than the table index was accepted as a full bound. cmp al, 3 ; ja bounds only the low byte, so with mov eax, edi before it the index could still be any 32-bit value. A narrow guard now counts only when the index definition clears the bits above it (movzx from a byte, including from memory, or a mask such as and esi, 0xf), which is what the compiler emits in GoW.

Tests: one rejected case (byte compare of a 32-bit index, fails without the fix) and one accepted case (byte compare of a masked index). GoW offline pass unchanged: VRSQRTPS native 4013, trapped 0; 4780 tables, 66 functions with an unresolved indirect jump; red-zone counts unchanged.

**@⁠NeySlim** on GitHub · 2026-10-09 12:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1281#issuecomment-6080559134) Follow-up from another review pass (97aca380): a `cmp` guard narrower than the table index was accepted as a full bound. `cmp al, 3 ; ja` bounds only the low byte, so with `mov eax, edi` before it the index could still be any 32-bit value. A narrow guard now counts only when the index definition clears the bits above it (`movzx` from a byte, including from memory, or a mask such as `and esi, 0xf`), which is what the compiler emits in GoW. Tests: one rejected case (byte compare of a 32-bit index, fails without the fix) and one accepted case (byte compare of a masked index). GoW offline pass unchanged: VRSQRTPS native 4013, trapped 0; 4780 tables, 66 functions with an unresolved indirect jump; red-zone counts unchanged.
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/1281/head:github-bot/gh-1281'
git switch 'github-bot/gh-1281'

Merge

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