fix(relinker): treat data between PS4 unwind functions as data in the syscall scan and the code roots #8166

Merged
savvaniss merged 5 commits from upstream-pr/8166 into main 2026-10-20 16:17:05 +00:00
savvaniss commented 2026-10-20 01:04:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T01:04:49Z.


What

PS4 images keep read-only data inside the executable segment, between the functions that .eh_frame describes. boggle.self and tp.self from CUSA03312 (Hasbro Family Fun Pack) are Unity players with about 15 MB of such data between their unwind functions. Two parts of the relinker treat bytes there as code:

  1. Syscall scan. A table in a gap can hold 0f 05. The scan failed with Forbidden syscall instruction at 0xa579ad (Boggle) and 0xa8a209 (Trivial Pursuit). Outside the unwind functions of a PS4 image, a syscall, sysenter or int 0x80 pattern now fails the relink only when a constant syscall number is set before it. The others, and every sysret pattern, are skipped and counted in one Skipped N syscall byte pattern(s) line. The number is looked for in two places:

    • in the decoded instructions, as ConstantSyscallNumber already does, now requiring each instruction it looks back over to end where the next one starts;
    • in the raw bytes in front of the pattern, whatever alignment the decoding took: a mov eax, imm32, mov rax, imm32, mov rax, imm64 or xor eax, eax, optionally followed by mov al, imm8 or mov ax, imm16, then by any number of register moves or zeroings that leave rax alone.

    The scan merges nested and overlapping unwind ranges with the instruction scanner's MergeCodeRanges, which is now exported. Inside the unwind functions, in images without PT_SCE_DYNLIBDATA, and in guest modules without it, every such instruction still fails.

  2. Code roots for the Windows and macOS outputs. CodeInstructionCollector followed every relocation and lea target inside the code range as code. Strings and tables in the gaps then decoded into garbage, and the conversion failed with Instruction exceeds 15 bytes. Outside the unwind functions, such a target is now decoded linearly up to its first jump, return or trap, the start of the next unwind function, or 256 instructions. It is followed as code when either holds:

    • that run contains an fs:[disp32] access, the form the linear TLS sweep already roots;
    • it is 16-byte aligned, starts less than 256 bytes after the end of an unwind function, and the run ends in a jump, return or trap.

    Every other such target is taken as data. These targets are counted in one Took N pointer target(s) outside the unwind functions as data line, and the Windows TLS rewrite fails instead of overwriting one. lea targets go through the same rule instead of the graph's own address-taken roots. Images without unwind functions are unchanged.

The debt file records both rules as heuristics.

The first two commits are the original change, rebased on main now that #7660 is merged. The last two address the reviews by @SandstromPL and @wachi35676:

  • nested FDE ranges;
  • PS5 modules;
  • the adjacency check in the number lookback;
  • the raw-byte number check;
  • the TLS follow, message and entry protection of the pointer rule.

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON) on main 56b299c3a.

  • Full ctest: 223/223 pass, both at the head and with only the first three commits.
  • After wachi35676's second run, e0095e5b4 also accepts mov rax, imm64, a mov al/mov ax immediate after a constant, and more than seven register moves. Their three missed rows (and a mov ax row) are refused now; each fails at 58a2a4962. On the stack below, all four Hasbro games still convert with the same 67 and 28 skipped patterns.
  • test_sce_code_gaps.py and test_sce_code_extent.py gain the reviewers' cases:
    • nested FDEs, a PS5 module, the six gap rows and the jump-table row, and the 15-prefix lookback;
    • the edges of the syscall skip, with assertions on the Skipped line;
    • the accept side and the lea path of the pointer rule, with assertions on the Took line;
    • a TLS load behind a far pointer, rewritten with PT_TLS and refused without it;
    • a run into the next unwind function;
    • a TLS rewrite over a target taken as data.
  • Mutation check, one rebuild per mutant: reverting any single fix fails at least one new case, and so does each of the 10 mutants from the first review. With #8076's change to GuestModuleBuilder.cpp:346 and without the module gate, the PS5 module case fails; with the gate, it passes.
  • Hasbro Family Fun Pack (CUSA03312): the launcher plus each game (--executable <game>.self), for Windows, macOS and Linux. The base stack is main, #6684, #8168 and the TLS relocation commit from #6977; each game was converted on it with and without this PR:
    • Risk and Monopoly convert either way, and every output file is byte-identical. The Linux .desktop files differ only by the output path.
    • Boggle and Trivial Pursuit fail without this PR (Forbidden syscall instruction) and convert with it. Boggle skips 67 syscall patterns and takes 5676 pointer targets as data; Trivial Pursuit skips 28 and takes 5384.
    • Against the previous head (its two commits on the same stack), every output file of all four games is byte-identical for every target. That includes Boggle's and Trivial Pursuit's Unity Modules and Plugins (--module-dir), converted with each game as the input for Windows and with the launcher for macOS and Linux. No game was run for this update.
    • For Windows, converting the launcher together with a game and its --module-dir stops on Guest modules convert differently for <game>.self, so it cannot share them with the input executable. It stops the same way at the previous head, so it is not from this change.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch lists:
    • #8076 and #8042, which handle undecodable data in the same scan from other angles. #8076 also changes GuestModuleBuilder.cpp:346, which the module gate now covers.
    • #7996, whose CodeInstructionCollector.cpp line is the interpreter trim, not these rules.
    • #6586, which changes the GuestModuleWriter signatures that this PR extends with a message callback.

The jump-table case in Boggle's SavedGames.prx plugin is separate and is #8168. A function's relative jump table ends 8 bytes past its FDE, and code follows after 16-byte padding, which main's FindTrailingRelativeJumpTable did not accept. Trivial Pursuit converts without it.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: CUSA03312 #7198 (Boggle and Trivial Pursuit Live!)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4929513890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T01:04:49Z. --- ### What PS4 images keep read-only data inside the executable segment, between the functions that `.eh_frame` describes. `boggle.self` and `tp.self` from CUSA03312 (Hasbro Family Fun Pack) are Unity players with about 15 MB of such data between their unwind functions. Two parts of the relinker treat bytes there as code: 1. **Syscall scan.** A table in a gap can hold `0f 05`. The scan failed with `Forbidden syscall instruction` at `0xa579ad` (Boggle) and `0xa8a209` (Trivial Pursuit). Outside the unwind functions of a PS4 image, a `syscall`, `sysenter` or `int 0x80` pattern now fails the relink only when a constant syscall number is set before it. The others, and every `sysret` pattern, are skipped and counted in one `Skipped N syscall byte pattern(s)` line. The number is looked for in two places: - in the decoded instructions, as `ConstantSyscallNumber` already does, now requiring each instruction it looks back over to end where the next one starts; - in the raw bytes in front of the pattern, whatever alignment the decoding took: a `mov eax, imm32`, `mov rax, imm32`, `mov rax, imm64` or `xor eax, eax`, optionally followed by `mov al, imm8` or `mov ax, imm16`, then by any number of register moves or zeroings that leave `rax` alone. The scan merges nested and overlapping unwind ranges with the instruction scanner's `MergeCodeRanges`, which is now exported. Inside the unwind functions, in images without `PT_SCE_DYNLIBDATA`, and in guest modules without it, every such instruction still fails. 2. **Code roots for the Windows and macOS outputs.** `CodeInstructionCollector` followed every relocation and `lea` target inside the code range as code. Strings and tables in the gaps then decoded into garbage, and the conversion failed with `Instruction exceeds 15 bytes`. Outside the unwind functions, such a target is now decoded linearly up to its first jump, return or trap, the start of the next unwind function, or 256 instructions. It is followed as code when either holds: - that run contains an `fs:[disp32]` access, the form the linear TLS sweep already roots; - it is 16-byte aligned, starts less than 256 bytes after the end of an unwind function, and the run ends in a jump, return or trap. Every other such target is taken as data. These targets are counted in one `Took N pointer target(s) outside the unwind functions as data` line, and the Windows TLS rewrite fails instead of overwriting one. `lea` targets go through the same rule instead of the graph's own address-taken roots. Images without unwind functions are unchanged. The debt file records both rules as heuristics. The first two commits are the original change, rebased on `main` now that #7660 is merged. The last two address the reviews by @SandstromPL and @wachi35676: - nested FDE ranges; - PS5 modules; - the adjacency check in the number lookback; - the raw-byte number check; - the TLS follow, message and entry protection of the pointer rule. ### Tested Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`) on `main` `56b299c3a`. - Full `ctest`: 223/223 pass, both at the head and with only the first three commits. - After wachi35676's second run, e0095e5b4 also accepts `mov rax, imm64`, a `mov al`/`mov ax` immediate after a constant, and more than seven register moves. Their three missed rows (and a `mov ax` row) are refused now; each fails at 58a2a4962. On the stack below, all four Hasbro games still convert with the same 67 and 28 skipped patterns. - `test_sce_code_gaps.py` and `test_sce_code_extent.py` gain the reviewers' cases: - nested FDEs, a PS5 module, the six gap rows and the jump-table row, and the 15-prefix lookback; - the edges of the syscall skip, with assertions on the `Skipped` line; - the accept side and the `lea` path of the pointer rule, with assertions on the `Took` line; - a TLS load behind a far pointer, rewritten with `PT_TLS` and refused without it; - a run into the next unwind function; - a TLS rewrite over a target taken as data. - Mutation check, one rebuild per mutant: reverting any single fix fails at least one new case, and so does each of the 10 mutants from the first review. With #8076's change to `GuestModuleBuilder.cpp:346` and without the module gate, the PS5 module case fails; with the gate, it passes. - **Hasbro Family Fun Pack (CUSA03312):** the launcher plus each game (`--executable <game>.self`), for Windows, macOS and Linux. The base stack is `main`, #6684, #8168 and the TLS relocation commit from #6977; each game was converted on it with and without this PR: - Risk and Monopoly convert either way, and every output file is byte-identical. The Linux `.desktop` files differ only by the output path. - Boggle and Trivial Pursuit fail without this PR (`Forbidden syscall instruction`) and convert with it. Boggle skips 67 syscall patterns and takes 5676 pointer targets as data; Trivial Pursuit skips 28 and takes 5384. - Against the previous head (its two commits on the same stack), every output file of all four games is byte-identical for every target. That includes Boggle's and Trivial Pursuit's Unity `Modules` and `Plugins` (`--module-dir`), converted with each game as the input for Windows and with the launcher for macOS and Linux. No game was run for this update. - For Windows, converting the launcher together with a game and its `--module-dir` stops on `Guest modules convert differently for <game>.self, so it cannot share them with the input executable`. It stops the same way at the previous head, so it is not from this change. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch` lists: - #8076 and #8042, which handle undecodable data in the same scan from other angles. #8076 also changes `GuestModuleBuilder.cpp:346`, which the module gate now covers. - #7996, whose `CodeInstructionCollector.cpp` line is the interpreter trim, not these rules. - #6586, which changes the `GuestModuleWriter` signatures that this PR extends with a message callback. The jump-table case in Boggle's `SavedGames.prx` plugin is separate and is #8168. A function's relative jump table ends 8 bytes past its FDE, and code follows after 16-byte padding, which `main`'s `FindTrailingRelativeJumpTable` did not accept. Trivial Pursuit converts without it. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: CUSA03312 #7198 (Boggle and Trivial Pursuit Live!) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 01:19:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T01:19:49Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6586 core/relinker/elfpatcher/include/elfpatcher/general/GuestModuleWriter.hpp L10-12
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L397
PR 7996 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp L98

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/relinker.md
PR 6618 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
PR 6977 core/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
core/relinker/relinker/tests/test_sce_code_extent.py
docs/dev/debt/relinker.md
PR 8042 core/relinker/codegen/include/codegen/IInstructionScanner.hpp
core/relinker/codegen/src/InstructionScanner.cpp
core/relinker/relinker/src/analysis/SyscallScanner.cpp
PR 8076 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
core/relinker/relinker/tests/test_sce_code_extent.py
docs/dev/debt/relinker.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281070998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6281070998). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T01:19:49Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6586](https://www.github.com/boykopovar/AnyPS5/pull/6586) | `core/relinker/elfpatcher/include/elfpatcher/general/GuestModuleWriter.hpp` [L10-12](https://github.com/boykopovar/AnyPS5/blob/30fda0a03a43339037677d3a9f4a021d5b078566/core/relinker/elfpatcher/include/elfpatcher/general/GuestModuleWriter.hpp#L10-L12)<br>`core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` [L397](https://github.com/boykopovar/AnyPS5/blob/30fda0a03a43339037677d3a9f4a021d5b078566/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L397) | | | | [PR 7996](https://www.github.com/boykopovar/AnyPS5/pull/7996) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` [L98](https://github.com/boykopovar/AnyPS5/blob/30fda0a03a43339037677d3a9f4a021d5b078566/core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp#L98) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/relinker.md` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cpp`<br>`core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp`<br>`core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`<br>`core/relinker/relinker/tests/test_sce_code_extent.py`<br>`docs/dev/debt/relinker.md` | | [PR 8042](https://www.github.com/boykopovar/AnyPS5/pull/8042) | `core/relinker/codegen/include/codegen/IInstructionScanner.hpp`<br>`core/relinker/codegen/src/InstructionScanner.cpp`<br>`core/relinker/relinker/src/analysis/SyscallScanner.cpp` | | [PR 8076](https://www.github.com/boykopovar/AnyPS5/pull/8076) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`<br>`core/relinker/relinker/tests/test_sce_code_extent.py`<br>`docs/dev/debt/relinker.md` |
ntamas94 commented 2026-10-20 02:39:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T02:39:55Z.


Confirmation from Gang Beasts (CUSA04865, own dump): Media/Modules/MonoAssembliesPS4.prx holds 78 Mono AOT images (mono_aot_version 67) whose tables, PLT info words and strings sit in the executable segment outside any FDE.

  • On main at c2b0159d6 the relinker stops with Forbidden syscall instruction at code offset 0x129f1c, inside class_name_table.
  • With this PR (5cababf14) merged on top, relinker --skip-sce-module converts it. The executable PT_LOAD of the output is byte-identical to the input (48,101,680 bytes, SHA-1 dd2fd057bf50…), and the trampolines go to a new segment.
  • #7660 or #8076 alone stop at the same offset.

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7. I'm closing my #8198, which did the same for this module with a Mono-specific reader of each image's globals table.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6282062362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6282062362). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-20T02:39:55Z. --- Confirmation from Gang Beasts (CUSA04865, own dump): `Media/Modules/MonoAssembliesPS4.prx` holds 78 Mono AOT images (`mono_aot_version` 67) whose tables, PLT info words and strings sit in the executable segment outside any FDE. - On `main` at c2b0159d6 the relinker stops with `Forbidden syscall instruction at code offset 0x129f1c`, inside `class_name_table`. - With this PR (5cababf14) merged on top, `relinker --skip-sce-module` converts it. The executable `PT_LOAD` of the output is byte-identical to the input (48,101,680 bytes, SHA-1 `dd2fd057bf50…`), and the trampolines go to a new segment. - #7660 or #8076 alone stop at the same offset. Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7. I'm closing my #8198, which did the same for this module with a Mono-specific reader of each image's `globals` table.
SandstromPL commented 2026-10-20 11:14:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-20T11:14:37Z.


@savvaniss Review of your two commits on 5cababf14 (cddd6cfff and a0ccdeee2). Base for comparison: main a569f47cb + #7660 c92f09d1d. All results come from synthetic fixtures built with your test helpers. We have not seen any of these on a real title.

1. Nested FDE ranges let a syscall without a number through

SyscallScanner.cpp:194-199, used at :226, sorts the unwind ranges by Begin. insideFunction then tests only the last range whose Begin <= offset, and the ranges are never merged. InstructionScanner does merge the same ranges, with MergeCodeRanges (InstructionScanner.cpp:13-24, :30).

Nothing upstream refuses overlapping FDEs: ReadExceptionFunctions and SceCodeExtent don't check for them. Only the opt-in strict NID filter does.

Fixture: test_sce_code_extent.fixture(gap=0x20) with the FDE table [(0x180,0x80),(0x190,0x8),(0x200,0x10)], the ranges filled with NOPs, and 89 f8 0f 05 c3 (mov eax,edi; syscall; ret) at 0x1c0.

  • #8166: rc 0 on Linux, --windows and --macos, with "Skipped 1 syscall byte pattern(s) … the first at code offset 0x1c2".
  • base: rc 2 on all three, with "Forbidden syscall instruction at code offset 0x1c2".
  • Without the inner FDE, both refuse.

This contradicts the body's "Inside the unwind functions … any such instruction still fails". Linkers rarely emit nested FDEs (lld drops entries with duplicate starts, and GNU ld warns about overlaps), so this is a risk rather than a bug we have seen. The fix is small: merge after the sort (not built), or expose MergeCodeRanges from codegen so the two components can't disagree.

     std::sort(functions.begin(), functions.end(), [](const CodeRange& left, const CodeRange& right) { return left.Begin < right.Begin; });
+    std::vector<CodeRange> merged;
+    for (const auto& range : functions) {
+        if (!merged.empty() && range.Begin <= merged.back().End) merged.back().End = std::max(merged.back().End, range.End);
+        else merged.push_back(range);
+    }
+    functions = std::move(merged);

Test: add the fixture above to test_sce_code_gaps.py, expecting "Forbidden syscall instruction at code offset 0x1c2".

2. Only the sceImage ? at GuestModuleBuilder.cpp:346 keeps PS5 modules strict, and #8076 changes that line

GuestModuleBuilder.cpp:352, which comes from #7660, calls SceUnwindRanges without a sceImage gate. Non-SCE modules stay strict only because :346 leaves unwindFunctions empty. cddd6cfff widens what non-empty ranges unlock. On the #8166 binary, with identical module bytes and FDE (gap bytes 8b c7 0f 05 c3 at 0x1000, FDE at 0x1010):

  • with the SCE header: rc 0, "Skipped 1 … 0x1002";
  • with PT_SCE_DYNLIBDATA turned into PT_NULL and standard DT_ tags: rc 2, "Forbidden syscall instruction at code offset 0x1002".

#8076 (e4034102a) changes :346 to sceImage || PT_GNU_EH_FRAME. In a git merge-tree of the two heads, that line merges outside the conflict markers, because the conflict covers only the scan-call lines. A resolution that keeps both sides therefore turns on the gap leniency for PS5 modules. cc @oneandonlydean, since you are assigned both.

Removing sceImage ? from :346 also passes all 219 tests today. Suggested gate:

-            const auto unwindRanges = SceUnwindRanges(code, header.MappedAddress, unwindFunctions);
+            const auto unwindRanges = sceImage ? SceUnwindRanges(code, header.MappedAddress, unwindFunctions) : std::vector<CodeRange>{};

Suggested test for test_sce_code_gaps.py, which turns header 3 (PT_SCE_DYNLIBDATA) into PT_NULL. Head and main refuse it, and it converts without sceImage ?. sce_module() keeps its PT_GNU_EH_FRAME, so the test also catches the #8076 merge.

def ps5_module():
    image = sce_module()
    struct.pack_into("<I", image, 64 + 3 * 56, 0)
    for index, tag in enumerate([(5, 0x2200), (10, 1), (6, 0x2220), (11, 24), (4, 0x2240), (0, 0)]):
        struct.pack_into("<qQ", image, 0x600 + index * 16, *tag)
    struct.pack_into("<II", image, 0x840, 1, 1)
    return image

run_module(relinker, work, "ps5-module-gap-syscall-bytes", ps5_module(), [],
           ["Forbidden syscall instruction at code offset 0x1020"])

3. The pointer rule drops code without any message, TLS accesses included

addPointerRoot (CodeInstructionCollector.cpp:165-166, used at :171, :268 and :276, with the graph's lea following turned off at :447) drops a relocation or lea target outside every FDE in three cases: it is unaligned, it is 256 bytes or more past the previous FDE end, or it is before the first FDE. No message is printed. Base follows such targets.

Fixture: fixture(gap=0x140) plus PT_TLS, an FDE at 0x200-0x210, a RELATIVE pointer to 0x310, NOP padding, and 64 48 8b 04 25 00 00 00 00 c3 at 0x310.

  • base: rc 0, and the fs load is rewritten in both the PE and the Mach-O.
  • #8166: rc 0, the raw fs:[0] stays in both outputs, and nothing is printed.

The same mechanism turns refusals on base into silent conversions on #8166:

  • without PT_TLS, base fails with "Guest TLS access without PT_TLS";
  • on macOS with 64 48 8b 00 48 89 c7 c3, base fails with "Unsupported macOS guest TLS instruction";
  • for an FDE function that calls 0x300 and does lea rdi,[rip→0x304], base fails on Windows with "TLS rewrite would overwrite an executable entry point (offset 0x304)". #8166 converts it, and the rewrite overwrites the lea target.

What limits the damage:

  • The existing linear fs:[disp32] sweep still catches local-exec loads behind 16-aligned cc cc padding. With 0xCC padding, the output is identical to base.
  • call/jmp [rip+slot] targets are still followed.
  • Syscalls are not affected.
  • The only real case we know of is Mono AOT method code, which has no FDEs (#8198). This rule almost certainly drops it, but on Gang Beasts that code has no fs/gs accesses (see ntamas94's byte-identical result above).

decodesToTransfer also filters very little. The decoder throws only on length or truncation errors, and the probe walks on into the next FDE function. So Hello everyone!\0 at an aligned address 0x40 past an FDE end is accepted, and its 65 bytes become UD2+NOP. Base does the same, so that part is not a regression. In practice, the alignment check and the 256-byte window are what do the filtering.

Suggestions:

  • Print one line with the count and first address of the targets taken as data, as the syscall skip already does.
  • Before dropping a target, decode linearly up to its first transfer or the next FDE Begin. If a 64/65-prefixed instruction shows up, follow the target or refuse.
  • Stop decodesToTransfer at the next FDE Begin.

Two questions:

  • On titles that main already converts for --windows/--macos, are the outputs byte-identical with and without a0ccdeee2?
  • In Boggle and Trivial Pursuit, how many targets are dropped, and does any of them decode to a 64/65-prefixed instruction before its first transfer?

4. The syscall-number lookback ignores adjacency (this one fails safe)

ConstantSyscallNumber (SyscallScanner.cpp:149-172) uses recent.Before(step) without checking that it ends where the next instruction starts. #7660's byte-by-byte skip in gaps (InstructionScanner.cpp:61-65) pushes nothing to recent.

Using your executable() with gap b8 14 00 00 00 + 41×15 + 0f 05 c3:

  • the result is rc 2, "Forbidden syscall instruction at code offset 0x217: syscall number 20";
  • with 90×5 in place of the mov, it is rc 0, "Skipped 1 … 0x217".

On a CPU, that mov is followed by a 17-byte instruction (#GP), so it cannot set eax for the syscall. The flaw only causes false refusals, and it needs more than 15 prefix bytes before 0f 05. Suggested fix (not built):

 static std::optional<std::uint32_t> ConstantSyscallNumber(const std::vector<std::uint8_t>& codeSection, const FileByteOffset codeSectionOffset, const RecentInstructions& recent) {
+    FileByteOffset next = recent.Before(0).Offset;
     for (std::size_t step = 1; step <= SYSCALL_NUMBER_LOOKBACK && step < recent.count; ++step) {
         const auto& match = recent.Before(step);
+        if (match.Offset + match.Length != next) return std::nullopt;
+        next = match.Offset;

Test: executable(SYSCALL_NUMBER + b"\x41" * 15 + SYSCALL) with no expected errors.

Test gaps. Each mutant below passes the full 219-test suite. Each killer below was run against the head binary and the mutant binary.

  • The accept side of addPointerRoot is never tested. Making the third disjunct on :166 false survives, and TLS in gap thunks would then go unrewritten. So does dropping the alignment check or the near-end check, or letting the transfer probe accept the first instruction it decodes. Case, for windows and macos: fixture(early_function=True, pointer_target=0x1B0, gap_bytes=(0x1B0, UNSUPPORTED_TLS)), and the same at 0x170, both expecting "Unsupported Windows/macOS guest TLS instruction". Head refuses both, and the mutant converts them. To kill the other three mutants, add these to your aligned/unaligned loop (all three convert on head):
    • (0x1A4, UNSUPPORTED_TLS) (alignment);
    • fixture(gap=0x140, pointer_target=0x310, gap_bytes=(0x310, UNSUPPORTED_TLS)) (near-end);
    • (0x1B0, b"\x90" + INVALID) (transfer probe).
  • The lea path is never tested. Reverting :171, :447, or both survives. Case: fixture(early_function=True, gap_bytes=(0x1B0, INVALID)), with FUNCTION set to 48 8d 05 <rel32 to 0x1B0> c3. Head converts it, and each revert fails with "Instruction exceeds 15 bytes".
  • The edges of the syscall skip are never tested. Making the End check on :198 <=, skipping only Invocation kinds, or deleting the "Skipped" message all survive. Cases:
    • executable(SYSCALL), the pattern at 0x210 right after the FDE, expecting rc 0;
    • executable(SLOT + bytes.fromhex("0f 07")) (sysret), expecting rc 0;
    • an assertion on "Skipped 1 syscall byte pattern(s) … 0x214" in stdout for sce-gap-table-with-syscall-bytes. run() ignores stdout today.

Our runs (Linux GCC, relinker-only Release):

  • 5cababf14, full ctest: 219/219.
  • Merged onto main e9a5a0c84: 227/227.
  • Differential of main against main + #8166 + #8168 over the 133 relinker ctests: 2808 of 2822 relinker calls are byte-identical. The 14 that differ are exactly your new SCE gap fixtures.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289599319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6289599319). Originally posted by [SandstromPL](https://github.com/SandstromPL) on 2026-10-20T11:14:37Z. --- @savvaniss Review of your two commits on 5cababf14 (cddd6cfff and a0ccdeee2). Base for comparison: main a569f47cb + #7660 c92f09d1d. All results come from synthetic fixtures built with your test helpers. We have not seen any of these on a real title. **1. Nested FDE ranges let a syscall without a number through** `SyscallScanner.cpp:194-199`, used at :226, sorts the unwind ranges by `Begin`. `insideFunction` then tests only the last range whose `Begin <= offset`, and the ranges are never merged. `InstructionScanner` does merge the same ranges, with `MergeCodeRanges` (`InstructionScanner.cpp:13-24`, :30). Nothing upstream refuses overlapping FDEs: `ReadExceptionFunctions` and `SceCodeExtent` don't check for them. Only the opt-in strict NID filter does. Fixture: `test_sce_code_extent.fixture(gap=0x20)` with the FDE table `[(0x180,0x80),(0x190,0x8),(0x200,0x10)]`, the ranges filled with NOPs, and `89 f8 0f 05 c3` (mov eax,edi; syscall; ret) at 0x1c0. - #8166: rc 0 on Linux, `--windows` and `--macos`, with "Skipped 1 syscall byte pattern(s) … the first at code offset 0x1c2". - base: rc 2 on all three, with "Forbidden syscall instruction at code offset 0x1c2". - Without the inner FDE, both refuse. This contradicts the body's "Inside the unwind functions … any such instruction still fails". Linkers rarely emit nested FDEs (lld drops entries with duplicate starts, and GNU ld warns about overlaps), so this is a risk rather than a bug we have seen. The fix is small: merge after the sort (not built), or expose `MergeCodeRanges` from codegen so the two components can't disagree. ```diff std::sort(functions.begin(), functions.end(), [](const CodeRange& left, const CodeRange& right) { return left.Begin < right.Begin; }); + std::vector<CodeRange> merged; + for (const auto& range : functions) { + if (!merged.empty() && range.Begin <= merged.back().End) merged.back().End = std::max(merged.back().End, range.End); + else merged.push_back(range); + } + functions = std::move(merged); ``` Test: add the fixture above to `test_sce_code_gaps.py`, expecting "Forbidden syscall instruction at code offset 0x1c2". **2. Only the `sceImage ?` at `GuestModuleBuilder.cpp:346` keeps PS5 modules strict, and #8076 changes that line** `GuestModuleBuilder.cpp:352`, which comes from #7660, calls `SceUnwindRanges` without a `sceImage` gate. Non-SCE modules stay strict only because :346 leaves `unwindFunctions` empty. cddd6cfff widens what non-empty ranges unlock. On the #8166 binary, with identical module bytes and FDE (gap bytes `8b c7 0f 05 c3` at 0x1000, FDE at 0x1010): - with the SCE header: rc 0, "Skipped 1 … 0x1002"; - with PT_SCE_DYNLIBDATA turned into PT_NULL and standard DT_ tags: rc 2, "Forbidden syscall instruction at code offset 0x1002". #8076 (e4034102a) changes :346 to `sceImage || PT_GNU_EH_FRAME`. In a `git merge-tree` of the two heads, that line merges outside the conflict markers, because the conflict covers only the scan-call lines. A resolution that keeps both sides therefore turns on the gap leniency for PS5 modules. cc @oneandonlydean, since you are assigned both. Removing `sceImage ?` from :346 also passes all 219 tests today. Suggested gate: ```diff - const auto unwindRanges = SceUnwindRanges(code, header.MappedAddress, unwindFunctions); + const auto unwindRanges = sceImage ? SceUnwindRanges(code, header.MappedAddress, unwindFunctions) : std::vector<CodeRange>{}; ``` Suggested test for `test_sce_code_gaps.py`, which turns header 3 (PT_SCE_DYNLIBDATA) into PT_NULL. Head and main refuse it, and it converts without `sceImage ?`. `sce_module()` keeps its PT_GNU_EH_FRAME, so the test also catches the #8076 merge. ```python def ps5_module(): image = sce_module() struct.pack_into("<I", image, 64 + 3 * 56, 0) for index, tag in enumerate([(5, 0x2200), (10, 1), (6, 0x2220), (11, 24), (4, 0x2240), (0, 0)]): struct.pack_into("<qQ", image, 0x600 + index * 16, *tag) struct.pack_into("<II", image, 0x840, 1, 1) return image run_module(relinker, work, "ps5-module-gap-syscall-bytes", ps5_module(), [], ["Forbidden syscall instruction at code offset 0x1020"]) ``` **3. The pointer rule drops code without any message, TLS accesses included** `addPointerRoot` (`CodeInstructionCollector.cpp:165-166`, used at :171, :268 and :276, with the graph's lea following turned off at :447) drops a relocation or lea target outside every FDE in three cases: it is unaligned, it is 256 bytes or more past the previous FDE end, or it is before the first FDE. No message is printed. Base follows such targets. Fixture: `fixture(gap=0x140)` plus PT_TLS, an FDE at 0x200-0x210, a RELATIVE pointer to 0x310, NOP padding, and `64 48 8b 04 25 00 00 00 00 c3` at 0x310. - base: rc 0, and the fs load is rewritten in both the PE and the Mach-O. - #8166: rc 0, the raw `fs:[0]` stays in both outputs, and nothing is printed. The same mechanism turns refusals on base into silent conversions on #8166: - without PT_TLS, base fails with "Guest TLS access without PT_TLS"; - on macOS with `64 48 8b 00 48 89 c7 c3`, base fails with "Unsupported macOS guest TLS instruction"; - for an FDE function that calls 0x300 and does `lea rdi,[rip→0x304]`, base fails on Windows with "TLS rewrite would overwrite an executable entry point (offset 0x304)". #8166 converts it, and the rewrite overwrites the lea target. What limits the damage: - The existing linear `fs:[disp32]` sweep still catches local-exec loads behind 16-aligned `cc cc` padding. With 0xCC padding, the output is identical to base. - `call/jmp [rip+slot]` targets are still followed. - Syscalls are not affected. - The only real case we know of is Mono AOT method code, which has no FDEs (#8198). This rule almost certainly drops it, but on Gang Beasts that code has no fs/gs accesses (see ntamas94's byte-identical result above). `decodesToTransfer` also filters very little. The decoder throws only on length or truncation errors, and the probe walks on into the next FDE function. So `Hello everyone!\0` at an aligned address 0x40 past an FDE end is accepted, and its `65` bytes become UD2+NOP. Base does the same, so that part is not a regression. In practice, the alignment check and the 256-byte window are what do the filtering. Suggestions: - Print one line with the count and first address of the targets taken as data, as the syscall skip already does. - Before dropping a target, decode linearly up to its first transfer or the next FDE `Begin`. If a `64`/`65`-prefixed instruction shows up, follow the target or refuse. - Stop `decodesToTransfer` at the next FDE `Begin`. Two questions: - On titles that main already converts for `--windows`/`--macos`, are the outputs byte-identical with and without a0ccdeee2? - In Boggle and Trivial Pursuit, how many targets are dropped, and does any of them decode to a `64`/`65`-prefixed instruction before its first transfer? **4. The syscall-number lookback ignores adjacency (this one fails safe)** `ConstantSyscallNumber` (`SyscallScanner.cpp:149-172`) uses `recent.Before(step)` without checking that it ends where the next instruction starts. #7660's byte-by-byte skip in gaps (`InstructionScanner.cpp:61-65`) pushes nothing to `recent`. Using your `executable()` with gap `b8 14 00 00 00` + `41`×15 + `0f 05 c3`: - the result is rc 2, "Forbidden syscall instruction at code offset 0x217: syscall number 20"; - with `90`×5 in place of the mov, it is rc 0, "Skipped 1 … 0x217". On a CPU, that mov is followed by a 17-byte instruction (#GP), so it cannot set eax for the syscall. The flaw only causes false refusals, and it needs more than 15 prefix bytes before `0f 05`. Suggested fix (not built): ```diff static std::optional<std::uint32_t> ConstantSyscallNumber(const std::vector<std::uint8_t>& codeSection, const FileByteOffset codeSectionOffset, const RecentInstructions& recent) { + FileByteOffset next = recent.Before(0).Offset; for (std::size_t step = 1; step <= SYSCALL_NUMBER_LOOKBACK && step < recent.count; ++step) { const auto& match = recent.Before(step); + if (match.Offset + match.Length != next) return std::nullopt; + next = match.Offset; ``` Test: `executable(SYSCALL_NUMBER + b"\x41" * 15 + SYSCALL)` with no expected errors. **Test gaps.** Each mutant below passes the full 219-test suite. Each killer below was run against the head binary and the mutant binary. - **The accept side of `addPointerRoot` is never tested.** Making the third disjunct on :166 false survives, and TLS in gap thunks would then go unrewritten. So does dropping the alignment check or the near-end check, or letting the transfer probe accept the first instruction it decodes. Case, for `windows` and `macos`: `fixture(early_function=True, pointer_target=0x1B0, gap_bytes=(0x1B0, UNSUPPORTED_TLS))`, and the same at 0x170, both expecting "Unsupported Windows/macOS guest TLS instruction". Head refuses both, and the mutant converts them. To kill the other three mutants, add these to your aligned/unaligned loop (all three convert on head): - `(0x1A4, UNSUPPORTED_TLS)` (alignment); - `fixture(gap=0x140, pointer_target=0x310, gap_bytes=(0x310, UNSUPPORTED_TLS))` (near-end); - `(0x1B0, b"\x90" + INVALID)` (transfer probe). - **The lea path is never tested.** Reverting :171, :447, or both survives. Case: `fixture(early_function=True, gap_bytes=(0x1B0, INVALID))`, with `FUNCTION` set to `48 8d 05 <rel32 to 0x1B0> c3`. Head converts it, and each revert fails with "Instruction exceeds 15 bytes". - **The edges of the syscall skip are never tested.** Making the End check on :198 `<=`, skipping only Invocation kinds, or deleting the "Skipped" message all survive. Cases: - `executable(SYSCALL)`, the pattern at 0x210 right after the FDE, expecting rc 0; - `executable(SLOT + bytes.fromhex("0f 07"))` (sysret), expecting rc 0; - an assertion on "Skipped 1 syscall byte pattern(s) … 0x214" in stdout for `sce-gap-table-with-syscall-bytes`. `run()` ignores stdout today. Our runs (Linux GCC, relinker-only Release): - 5cababf14, full ctest: 219/219. - Merged onto main e9a5a0c84: 227/227. - Differential of main against main + #8166 + #8168 over the 133 relinker ctests: 2808 of 2822 relinker calls are byte-identical. The 14 that differ are exactly your new SCE gap fixtures. AI-assisted: yes (Claude Code)
wachi35676 commented 2026-10-20 11:38:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T11:38:46Z.


Verdict: defect. In a gap, data that ends right before code can absorb the mov eax, N. The syscall after it then has no constant number, and the scan skips it.

Tested at 5cababf14, merged onto main 02fb1ce53. Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release. WSL Ubuntu 24.04, GCC 13.3.

Probe: the PS4 fixture(gap=0x20) that test_sce_code_gaps.py uses (PT_SCE_DYNLIBDATA, one unwind function at 0x200..0x210). The listed bytes start at 0x210, in the gap. Both the Linux default and --windows give the same result:

gap bytes at 0x210 main this PR
b8 3b 00 00 00 0f 05 c3 (mov eax,59; syscall; ret) rc 2 Forbidden syscall ... 0x215: syscall number 59 rc 2, same
0f 78 11 22 33 44 + b8 3b 00 00 00 0f 05 c3 rc 2 Cannot decode instruction: Unsupported 0F 78 opcode ... (offset 0x210) rc 0, Skipped 1 syscall byte pattern(s) ... 0x21b, output still holds 0f 05
0f 78 11 22 33 44 3c + the same code rc 2 Cannot decode instruction rc 0, Skipped ... 0x21c
0f 78 11 22 33 44 cc cc + the same code rc 2 Cannot decode instruction rc 2 Forbidden syscall ... syscall number 59
b8 3b 00 00 00 48 89 df 0f 05 c3 rc 2 Forbidden syscall ... 0x218 rc 0, skipped
31 c0 0f 05 c3 rc 2 Forbidden syscall ... 0x212 rc 0, skipped

What happens in the second and third rows: the scanner fails to decode at 0x210 and moves on one byte at a time. It then decodes 44 b8 3b 00 00 00 as one instruction (mov eax with a REX prefix), or decodes 3c b8 as cmp al, 0xb8. ConstantRaxLoad accepts only b8 imm32 with no REX and 48 c7 c0 imm32, so the load is not recognised. The PR describes a constant number loaded right before the syscall as "still rejected". That only holds when padding or a decodable instruction ends the data before the code, as in the fourth row. The last two rows are what the new debt line already says ("whose number is set further back"). mov eax, N; mov rsi, rbx; syscall is also the shape of the SDK's own inline mmap stub.

#8076 at e4034102a refuses all six rows on the same probe: rc 2, the same errors as main.

A jump table directly followed by code makes the same thing happen. Probe: two unwind functions, 0x200 and 0x230. The first is lea rcx,[rip+9]; movsxd rax,[rcx+rdi*4]; add rax,rcx; jmp rax with a 4-entry table at 0x210, followed directly by mov eax,59; syscall; ret at 0x220:

  • main and #8076: rc 2 Forbidden syscall instruction at code offset 0x225, without a number, because the table words misalign the decode.
  • This PR: rc 0, Skipped ... 0x225, and the syscall is still in the output.
  • This PR with #8168 merged too (your stack): rc 2 ... 0x225: syscall number 59. #8168 masks the table only up to 0x220, so the load is decoded. Data that is not a recognised jump table, as in rows 2 and 3 of the table above, still gets skipped with #8168 merged; I measured the same results for all six rows.

Other results:

  • ctest: Windows 222/222 (main 221/221), WSL 227/227 (main 226/226).
  • Negative control: a relinker built from #7660 alone (c92f09d1d) fails this branch's test_sce_code_gaps.py at sce-gap-syscall-bytes-after-slot and test_sce_code_extent.py at sce-pointer-to-unaligned-gap-data-windows. main fails at sce-gap-slot-linux (Instruction exceeds 15 bytes).
  • The four PS5 homebrew I have (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with 16 Wine modules) have no PT_SCE_DYNLIBDATA, so the new rules don't run for them. Relinked with --windows --to-intel, --macos --to-rosetta and Linux --to-intel, all 12 output sets are byte-identical to main.

One way to keep the refusal: before skipping a pattern, also check the raw bytes in front of it for a b8 imm32 or 48 c7 c0 imm32 load, independent of how the scanner aligned its decode.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289993320 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6289993320). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T11:38:46Z. --- Verdict: defect. In a gap, data that ends right before code can absorb the `mov eax, N`. The syscall after it then has no constant number, and the scan skips it. Tested at `5cababf14`, merged onto `main` `02fb1ce53`. Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release. WSL Ubuntu 24.04, GCC 13.3. Probe: the PS4 `fixture(gap=0x20)` that `test_sce_code_gaps.py` uses (`PT_SCE_DYNLIBDATA`, one unwind function at 0x200..0x210). The listed bytes start at 0x210, in the gap. Both the Linux default and `--windows` give the same result: | gap bytes at 0x210 | `main` | this PR | |---|---|---| | `b8 3b 00 00 00 0f 05 c3` (`mov eax,59; syscall; ret`) | rc 2 `Forbidden syscall ... 0x215: syscall number 59` | rc 2, same | | `0f 78 11 22 33 44` + `b8 3b 00 00 00 0f 05 c3` | rc 2 `Cannot decode instruction: Unsupported 0F 78 opcode ... (offset 0x210)` | rc 0, `Skipped 1 syscall byte pattern(s) ... 0x21b`, output still holds `0f 05` | | `0f 78 11 22 33 44 3c` + the same code | rc 2 `Cannot decode instruction` | rc 0, `Skipped ... 0x21c` | | `0f 78 11 22 33 44 cc cc` + the same code | rc 2 `Cannot decode instruction` | rc 2 `Forbidden syscall ... syscall number 59` | | `b8 3b 00 00 00 48 89 df 0f 05 c3` | rc 2 `Forbidden syscall ... 0x218` | rc 0, skipped | | `31 c0 0f 05 c3` | rc 2 `Forbidden syscall ... 0x212` | rc 0, skipped | What happens in the second and third rows: the scanner fails to decode at 0x210 and moves on one byte at a time. It then decodes `44 b8 3b 00 00 00` as one instruction (`mov eax` with a REX prefix), or decodes `3c b8` as `cmp al, 0xb8`. `ConstantRaxLoad` accepts only `b8 imm32` with no REX and `48 c7 c0 imm32`, so the load is not recognised. The PR describes a constant number loaded right before the syscall as "still rejected". That only holds when padding or a decodable instruction ends the data before the code, as in the fourth row. The last two rows are what the new debt line already says ("whose number is set further back"). `mov eax, N; mov rsi, rbx; syscall` is also the shape of the SDK's own inline mmap stub. #8076 at `e4034102a` refuses all six rows on the same probe: rc 2, the same errors as `main`. A jump table directly followed by code makes the same thing happen. Probe: two unwind functions, 0x200 and 0x230. The first is `lea rcx,[rip+9]; movsxd rax,[rcx+rdi*4]; add rax,rcx; jmp rax` with a 4-entry table at 0x210, followed directly by `mov eax,59; syscall; ret` at 0x220: - `main` and #8076: rc 2 `Forbidden syscall instruction at code offset 0x225`, without a number, because the table words misalign the decode. - This PR: rc 0, `Skipped ... 0x225`, and the syscall is still in the output. - This PR with #8168 merged too (your stack): rc 2 `... 0x225: syscall number 59`. #8168 masks the table only up to 0x220, so the load is decoded. Data that is not a recognised jump table, as in rows 2 and 3 of the table above, still gets skipped with #8168 merged; I measured the same results for all six rows. Other results: - `ctest`: Windows 222/222 (`main` 221/221), WSL 227/227 (`main` 226/226). - Negative control: a relinker built from #7660 alone (`c92f09d1d`) fails this branch's `test_sce_code_gaps.py` at `sce-gap-syscall-bytes-after-slot` and `test_sce_code_extent.py` at `sce-pointer-to-unaligned-gap-data-windows`. `main` fails at `sce-gap-slot-linux` (`Instruction exceeds 15 bytes`). - The four PS5 homebrew I have (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with 16 Wine modules) have no `PT_SCE_DYNLIBDATA`, so the new rules don't run for them. Relinked with `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`, all 12 output sets are byte-identical to `main`. One way to keep the refusal: before skipping a pattern, also check the raw bytes in front of it for a `b8 imm32` or `48 c7 c0 imm32` load, independent of how the scanner aligned its decode. AI-assisted: yes (Claude Code); results above were run on this machine.
savvaniss commented 2026-10-20 12:58:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:58:19Z.


@SandstromPL Thank you for the review and the fixtures. Everything below is at 58a2a4962: the branch is rebased on main 56b299c3a (#7660 is merged), with two new commits on top of the original two. "Before" means 5cababf14.

1. Nested FDE ranges. MergeCodeRanges is now exported from IInstructionScanner.hpp. The syscall scan uses it instead of its own sort, so the scan and the instruction scanner cannot disagree. CodeInstructionCollector merges its ranges the same way. Your fixture is in test_sce_code_gaps.py as sce-nested-function-syscall-{linux,windows,macos}: FDEs (0x180,0x80),(0x190,0x8),(0x200,0x10), NOPs, and 89 f8 0f 05 c3 at 0x1c0.

  • Before: rc 0 on all three targets.
  • After: rc 2 on all three, Forbidden syscall instruction at code offset 0x1c2.

2. PS5 modules. GuestModuleBuilder.cpp:352 now reads sceImage ? SceUnwindRanges(...) : std::vector<CodeRange>{}. ps5_module() is added as you wrote it, expecting Forbidden syscall instruction at code offset 0x1020. I checked the #8076 merge by changing line 346 to read the unwind table for every module:

  • without the gate, the case converts and the test fails;
  • with the gate, it is refused and the test passes.

3. The pointer rule. All three suggestions are in, with one narrowing that your second question decided:

  • Message. One line per image: Took N pointer target(s) outside the unwind functions as data, the first at 0x.... A message callback goes from Conversion and GuestModuleBuilder through the Windows and macOS writers into CodeInstructionCollector::Collect. Every new parameter is defaulted.
  • Linear decode before dropping. A target outside the unwind functions is decoded up to its first jump, return or trap, the start of the next unwind function, or 256 instructions. It is followed when that run holds an fs:[disp32] access, the same check the linear sweep uses (now one shared lambda). I did not follow on every 64/65 prefix, because in Boggle and Trivial Pursuit about 2,500 data targets each hit one; numbers below. Following all of them makes both conversions fail: Instruction exceeds 15 bytes (Boggle) and Code analysis: overlapping instruction boundaries (Trivial Pursuit).
  • decodesToTransfer stops at the next FDE Begin. The same run serves both checks.
  • Entry protection. Targets taken as data are also returned in entryRoots. So the Windows TLS rewrite fails instead of overwriting one, as it did on base when they were roots.

Your fixtures, now in test_sce_code_extent.py for --windows and --macos unless noted:

Case Before After
PT_TLS, pointer to 0x310, 64 48 8b 04 25 00 00 00 00 c3 rc 0, raw fs:[0] in PE and Mach-O rc 0, rewritten (the bytes are absent from both outputs)
same without PT_TLS rc 0 rc 2, Guest TLS access without PT_TLS / ... a non-empty PT_TLS
macOS 64 48 8b 00 48 89 c7 c3 at 0x310 rc 0, silent rc 0, Took 1 pointer target(s) ... the first at 0x310
FDE calls 0x300 and lea rdi,[rip→0x304] (Windows) rc 0, lea target overwritten rc 2, TLS rewrite would overwrite an executable entry point (offset 0x304)

The fs:[rax] form behind a far pointer stays a known gap, and the debt entry now names it. Hello everyone!\0 near an FDE end is still accepted if it decodes to a transfer before the next FDE start, as on base.

Your questions:

  • Byte-identical with and without the pointer rule. I compared outputs on a base stack of main, #6684, #8168 and the TLS relocation commit from #6977, with and without the whole PR. The syscall half only turns refusals into skips, so for titles that convert either way, any output difference would come from the pointer rule. Risk and Monopoly (CUSA03312), each with the pack's launcher, convert either way. All 11 output files of each are byte-identical for --windows and --macos. Linux output is identical too, apart from the path in the .desktop file. That stack also carries #8168. Against the previous head on the same stack, every output of all four games is byte-identical for every target, Boggle's and Trivial Pursuit's Unity Modules and Plugins included. So the review changes alter nothing these titles get.
  • Dropped targets in Boggle and Trivial Pursuit. I measured them with a temporary counter, with nothing followed. A run here goes up to the first jump, return or trap, the next FDE start, or 256 instructions:
Image Targets taken as data Run hits 64/65 of which fs / gs Runs that end in a jump, return or trap Run hits fs:[disp32]
boggle.self 5676 2591 910 / 2575 601 0
tp.self 5384 2446 646 / 2389 413 0
launcher eboot.bin 78 0 0 / 0 n/a 0

So yes, many decode to a 64/65-prefixed instruction, mostly gs from the e bytes of strings. None decodes to the fs:[disp32] form the rule now follows, and both titles still convert with the same 67 and 28 skipped syscall patterns.

4. Lookback adjacency. Your diff is in ConstantSyscallNumber. The test is sce-gap-syscall-after-overlong-instruction, executable(SYSCALL_NUMBER + b"\x41" * 15 + SYSCALL):

  • Before: rc 2, ... 0x217: syscall number 20.
  • After: rc 0, Skipped 1 ... 0x217.

The new raw-byte check (see wachi35676's thread) does not find a number there either, because 15 41 bytes sit between the load and the pattern.

Test gaps. All three are covered, and each of your 10 mutants now fails at least one case:

  • Accept side of the pointer rule. UNSUPPORTED_TLS at 0x170 and at 0x1B0 through a RELATIVE pointer, and at 0x1B0 through a lea. Each expects Unsupported Windows/macOS guest TLS instruction.
  • The three filters. Unaligned (0x1A4), far (0x310 with gap=0x140) and 90 + INVALID each expect rc 0 and the Took line. A new FS_SUBTRACT run at 0x1F0, which reaches the next FDE at 0x200, covers the stop at the next FDE start.
  • The lea path. FUNCTION = 48 8d 05 <rel32 to 0x1B0> c3 with INVALID at 0x1B0 expects rc 0 and Took 1 ... 0x1b0.
  • The skip edges. A pattern at 0x210 right after the FDE, sysret after a slot, and sce-gap-table-with-syscall-bytes. All assert the Skipped line, which run() now checks.
Mutant Killed by
third disjunct false the 6 tail-TLS cases
no alignment check unaligned TLS (both targets), TLS rewrite over the lea target
no near-end check far TLS (both targets)
probe accepts the first instruction 90+INVALID, run into the next FDE (both targets)
revert :171, :447, or both lea to gap data (both targets), TLS rewrite over the lea target
End check <= pattern right after the FDE
skip only Invocation sysret
no Skipped message 6 skip cases

Results: full ctest 223/223 at the head, and 223/223 with only the first three commits (Windows 11, WinLibs GCC 15.2, relinker-only Release). check_conventions.py passes.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6291390724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6291390724). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T12:58:19Z. --- @SandstromPL Thank you for the review and the fixtures. Everything below is at 58a2a4962: the branch is rebased on `main` `56b299c3a` (#7660 is merged), with two new commits on top of the original two. "Before" means 5cababf14. **1. Nested FDE ranges.** `MergeCodeRanges` is now exported from `IInstructionScanner.hpp`. The syscall scan uses it instead of its own sort, so the scan and the instruction scanner cannot disagree. `CodeInstructionCollector` merges its ranges the same way. Your fixture is in `test_sce_code_gaps.py` as `sce-nested-function-syscall-{linux,windows,macos}`: FDEs `(0x180,0x80),(0x190,0x8),(0x200,0x10)`, NOPs, and `89 f8 0f 05 c3` at 0x1c0. - Before: rc 0 on all three targets. - After: rc 2 on all three, `Forbidden syscall instruction at code offset 0x1c2`. **2. PS5 modules.** `GuestModuleBuilder.cpp:352` now reads `sceImage ? SceUnwindRanges(...) : std::vector<CodeRange>{}`. `ps5_module()` is added as you wrote it, expecting `Forbidden syscall instruction at code offset 0x1020`. I checked the #8076 merge by changing line 346 to read the unwind table for every module: - without the gate, the case converts and the test fails; - with the gate, it is refused and the test passes. **3. The pointer rule.** All three suggestions are in, with one narrowing that your second question decided: - **Message.** One line per image: `Took N pointer target(s) outside the unwind functions as data, the first at 0x...`. A message callback goes from `Conversion` and `GuestModuleBuilder` through the Windows and macOS writers into `CodeInstructionCollector::Collect`. Every new parameter is defaulted. - **Linear decode before dropping.** A target outside the unwind functions is decoded up to its first jump, return or trap, the start of the next unwind function, or 256 instructions. It is followed when that run holds an `fs:[disp32]` access, the same check the linear sweep uses (now one shared lambda). I did not follow on every `64`/`65` prefix, because in Boggle and Trivial Pursuit about 2,500 data targets each hit one; numbers below. Following all of them makes both conversions fail: `Instruction exceeds 15 bytes` (Boggle) and `Code analysis: overlapping instruction boundaries` (Trivial Pursuit). - **`decodesToTransfer` stops at the next FDE `Begin`.** The same run serves both checks. - **Entry protection.** Targets taken as data are also returned in `entryRoots`. So the Windows TLS rewrite fails instead of overwriting one, as it did on base when they were roots. Your fixtures, now in `test_sce_code_extent.py` for `--windows` and `--macos` unless noted: | Case | Before | After | |---|---|---| | PT_TLS, pointer to 0x310, `64 48 8b 04 25 00 00 00 00 c3` | rc 0, raw `fs:[0]` in PE and Mach-O | rc 0, rewritten (the bytes are absent from both outputs) | | same without PT_TLS | rc 0 | rc 2, `Guest TLS access without PT_TLS` / `... a non-empty PT_TLS` | | macOS `64 48 8b 00 48 89 c7 c3` at 0x310 | rc 0, silent | rc 0, `Took 1 pointer target(s) ... the first at 0x310` | | FDE calls 0x300 and `lea rdi,[rip→0x304]` (Windows) | rc 0, lea target overwritten | rc 2, `TLS rewrite would overwrite an executable entry point (offset 0x304)` | The `fs:[rax]` form behind a far pointer stays a known gap, and the debt entry now names it. `Hello everyone!\0` near an FDE end is still accepted if it decodes to a transfer before the next FDE start, as on base. Your questions: - **Byte-identical with and without the pointer rule.** I compared outputs on a base stack of `main`, #6684, #8168 and the TLS relocation commit from #6977, with and without the whole PR. The syscall half only turns refusals into skips, so for titles that convert either way, any output difference would come from the pointer rule. Risk and Monopoly (CUSA03312), each with the pack's launcher, convert either way. All 11 output files of each are byte-identical for `--windows` and `--macos`. Linux output is identical too, apart from the path in the `.desktop` file. That stack also carries #8168. Against the previous head on the same stack, every output of all four games is byte-identical for every target, Boggle's and Trivial Pursuit's Unity `Modules` and `Plugins` included. So the review changes alter nothing these titles get. - **Dropped targets in Boggle and Trivial Pursuit.** I measured them with a temporary counter, with nothing followed. A run here goes up to the first jump, return or trap, the next FDE start, or 256 instructions: | Image | Targets taken as data | Run hits `64`/`65` | of which fs / gs | Runs that end in a jump, return or trap | Run hits `fs:[disp32]` | |---|---|---|---|---|---| | `boggle.self` | 5676 | 2591 | 910 / 2575 | 601 | 0 | | `tp.self` | 5384 | 2446 | 646 / 2389 | 413 | 0 | | launcher `eboot.bin` | 78 | 0 | 0 / 0 | n/a | 0 | So yes, many decode to a `64`/`65`-prefixed instruction, mostly `gs` from the `e` bytes of strings. None decodes to the `fs:[disp32]` form the rule now follows, and both titles still convert with the same 67 and 28 skipped syscall patterns. **4. Lookback adjacency.** Your diff is in `ConstantSyscallNumber`. The test is `sce-gap-syscall-after-overlong-instruction`, `executable(SYSCALL_NUMBER + b"\x41" * 15 + SYSCALL)`: - Before: rc 2, `... 0x217: syscall number 20`. - After: rc 0, `Skipped 1 ... 0x217`. The new raw-byte check (see wachi35676's thread) does not find a number there either, because 15 `41` bytes sit between the load and the pattern. **Test gaps.** All three are covered, and each of your 10 mutants now fails at least one case: - **Accept side of the pointer rule.** `UNSUPPORTED_TLS` at 0x170 and at 0x1B0 through a RELATIVE pointer, and at 0x1B0 through a `lea`. Each expects `Unsupported Windows/macOS guest TLS instruction`. - **The three filters.** Unaligned (0x1A4), far (0x310 with `gap=0x140`) and `90` + `INVALID` each expect rc 0 and the `Took` line. A new `FS_SUBTRACT` run at 0x1F0, which reaches the next FDE at 0x200, covers the stop at the next FDE start. - **The `lea` path.** `FUNCTION = 48 8d 05 <rel32 to 0x1B0> c3` with `INVALID` at 0x1B0 expects rc 0 and `Took 1 ... 0x1b0`. - **The skip edges.** A pattern at 0x210 right after the FDE, `sysret` after a slot, and `sce-gap-table-with-syscall-bytes`. All assert the `Skipped` line, which `run()` now checks. | Mutant | Killed by | |---|---| | third disjunct false | the 6 tail-TLS cases | | no alignment check | unaligned TLS (both targets), TLS rewrite over the lea target | | no near-end check | far TLS (both targets) | | probe accepts the first instruction | `90`+`INVALID`, run into the next FDE (both targets) | | revert :171, :447, or both | `lea` to gap data (both targets), TLS rewrite over the lea target | | End check `<=` | pattern right after the FDE | | skip only Invocation | `sysret` | | no `Skipped` message | 6 skip cases | Results: full `ctest` 223/223 at the head, and 223/223 with only the first three commits (Windows 11, WinLibs GCC 15.2, relinker-only Release). `check_conventions.py` passes. AI-assisted: yes (Claude Code)
savvaniss commented 2026-10-20 12:58:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:58:21Z.


@wachi35676 Thank you, confirmed and fixed at 58a2a4962. Before a pattern outside the unwind functions is skipped, the scan now looks for a constant syscall number in the raw bytes in front of it, independent of where its decoding landed. It accepts any of these, ending at the pattern:

  • mov eax, imm32 (b8);
  • mov rax, imm32 (48 c7 c0);
  • xor eax, eax (31 c0 or 33 c0).

It also accepts one of them followed by at most seven register moves or zeroings (89/8b/31/33 with a register ModRM and an optional REX prefix) that leave rax alone. Those cover your fifth row, the SDK's inline mmap stub (mov rsi, rbx), and the mprotect stub's movs and xor r10d/r8d/r9d.

Your six rows and the jump-table row are in test_sce_code_gaps.py for Linux, --windows and --macos. Before is 5cababf14; after is this head:

Gap bytes at 0x210 Before After
b8 3b 00 00 00 0f 05 c3 rc 2, 0x215: syscall number 59 rc 2, same
0f 78 11 22 33 44 + the same rc 0, Skipped 1 ... 0x21b rc 2, 0x21b: syscall number 59
0f 78 11 22 33 44 3c + the same rc 0, skipped rc 2, 0x21c: syscall number 59
0f 78 11 22 33 44 cc cc + the same rc 2, syscall number 59 rc 2, 0x21d: syscall number 59
b8 3b 00 00 00 48 89 df 0f 05 c3 rc 0, skipped rc 2, 0x218: syscall number 59
31 c0 0f 05 c3 rc 0, skipped rc 2, 0x212: syscall number 0
jump table at 0x210 (4 entries of -16), mov eax,59; syscall; ret at 0x220 rc 0, Skipped 1 ... 0x225 rc 2, 0x225: syscall number 59

Each of these "after" results needs the raw-byte check: removing it makes the five changed rows fail on all three targets. A new case, b8 3b 00 00 00 48 89 f8 0f 05 c3, pins the other side: mov rax, rdi overwrites the number, so the pattern is still skipped. It fails if a move into rax is allowed as an intermediate.

On the real data, the check refuses none of the 67 patterns in Boggle or the 28 in Trivial Pursuit. Both still convert with the same Skipped counts, and for every target Risk and Monopoly produce the same bytes as without this PR.

The debt entry now says what is still not refused: a syscall without an unwind entry whose number comes from memory or from another register.

Results: full ctest 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release). The other review findings and the measurements are in my reply to SandstromPL above.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6291391210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6291391210). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T12:58:21Z. --- @wachi35676 Thank you, confirmed and fixed at 58a2a4962. Before a pattern outside the unwind functions is skipped, the scan now looks for a constant syscall number in the raw bytes in front of it, independent of where its decoding landed. It accepts any of these, ending at the pattern: - `mov eax, imm32` (`b8`); - `mov rax, imm32` (`48 c7 c0`); - `xor eax, eax` (`31 c0` or `33 c0`). It also accepts one of them followed by at most seven register moves or zeroings (`89`/`8b`/`31`/`33` with a register ModRM and an optional REX prefix) that leave `rax` alone. Those cover your fifth row, the SDK's inline mmap stub (`mov rsi, rbx`), and the mprotect stub's `mov`s and `xor r10d/r8d/r9d`. Your six rows and the jump-table row are in `test_sce_code_gaps.py` for Linux, `--windows` and `--macos`. Before is 5cababf14; after is this head: | Gap bytes at 0x210 | Before | After | |---|---|---| | `b8 3b 00 00 00 0f 05 c3` | rc 2, `0x215: syscall number 59` | rc 2, same | | `0f 78 11 22 33 44` + the same | rc 0, `Skipped 1 ... 0x21b` | rc 2, `0x21b: syscall number 59` | | `0f 78 11 22 33 44 3c` + the same | rc 0, skipped | rc 2, `0x21c: syscall number 59` | | `0f 78 11 22 33 44 cc cc` + the same | rc 2, `syscall number 59` | rc 2, `0x21d: syscall number 59` | | `b8 3b 00 00 00 48 89 df 0f 05 c3` | rc 0, skipped | rc 2, `0x218: syscall number 59` | | `31 c0 0f 05 c3` | rc 0, skipped | rc 2, `0x212: syscall number 0` | | jump table at 0x210 (4 entries of -16), `mov eax,59; syscall; ret` at 0x220 | rc 0, `Skipped 1 ... 0x225` | rc 2, `0x225: syscall number 59` | Each of these "after" results needs the raw-byte check: removing it makes the five changed rows fail on all three targets. A new case, `b8 3b 00 00 00 48 89 f8 0f 05 c3`, pins the other side: `mov rax, rdi` overwrites the number, so the pattern is still skipped. It fails if a move into `rax` is allowed as an intermediate. On the real data, the check refuses none of the 67 patterns in Boggle or the 28 in Trivial Pursuit. Both still convert with the same `Skipped` counts, and for every target Risk and Monopoly produce the same bytes as without this PR. The debt entry now says what is still not refused: a syscall without an unwind entry whose number comes from memory or from another register. Results: full `ctest` 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release). The other review findings and the measurements are in my reply to SandstromPL above. AI-assisted: yes (Claude Code)
ntamas94 commented 2026-10-20 13:10:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T13:10:08Z.


Re-ran Gang Beasts (CUSA04865) on 58a2a49 against 5cababf: relinker --windows --windows-gui --registry --module-dir Media/Modules eboot.bin on an Itemzflow dump, with sce_module/ left out so the TLS stop that needs #6977's fix does not come first.

  • Both heads convert, and every output file is byte-identical between them: gb.exe, the two converted Media/Modules images and the json files.
  • Both skip the same 147 syscall byte patterns in MonoAssembliesPS4.prx; the new raw-byte check refuses none of them.
  • New at 58a2a49: Took 18554 pointer target(s) outside the unwind functions as data, the first at 0xf0 for MonoAssembliesPS4.prx, and 23 (the first at 0x19077) for eboot.bin. 0xf0 is where the first AOT image's methods range starts, so, as SandstromPL expected, the Mono AOT method code (no FDEs) is taken as data. It has no fs/gs accesses, which is why the output does not change.

Windows 11 26200, WinLibs GCC 15.2.0 r7.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6291621057 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6291621057). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-20T13:10:08Z. --- Re-ran Gang Beasts (CUSA04865) on 58a2a49 against 5cababf: `relinker --windows --windows-gui --registry --module-dir Media/Modules eboot.bin` on an Itemzflow dump, with `sce_module/` left out so the TLS stop that needs #6977's fix does not come first. - Both heads convert, and every output file is byte-identical between them: `gb.exe`, the two converted `Media/Modules` images and the json files. - Both skip the same 147 syscall byte patterns in `MonoAssembliesPS4.prx`; the new raw-byte check refuses none of them. - New at 58a2a49: `Took 18554 pointer target(s) outside the unwind functions as data, the first at 0xf0` for `MonoAssembliesPS4.prx`, and 23 (the first at 0x19077) for `eboot.bin`. 0xf0 is where the first AOT image's `methods` range starts, so, as SandstromPL expected, the Mono AOT method code (no FDEs) is taken as data. It has no fs/gs accesses, which is why the output does not change. Windows 11 26200, WinLibs GCC 15.2.0 r7.
wachi35676 commented 2026-10-20 13:33:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T13:33:12Z.


Verdict: confirm the fix for the six rows; it holds. One note on scope: the new raw-byte check still misses some ordinary constant syscall-number loads, and its debt line understates that.

Re-ran at 58a2a4962 merged onto main 30fda0a03 (clean merge, head a7c553bb3), Windows 11 with WinLibs GCC 15.2.0 (relinker-only Release). Current main already refuses every syscall pattern it finds in a PS4 gap (rc 2), so each row below is main rc 2 vs this head. Same fixture as before (executable(gap_bytes), one unwind function 0x200..0x210, bytes at 0x210); Linux, --windows and --macos all agree.

The six original rows are now refused, as you describe:

gap bytes at 0x210 main 30fda0a03 this head
b8 3b 00 00 00 0f 05 c3 rc 2, 0x215: number 59 rc 2, same
0f 78 11 22 33 44 + the same rc 2, 0x21b (no number) rc 2, 0x21b: number 59
0f 78 11 22 33 44 3c + the same rc 2, 0x21c rc 2, 0x21c: number 59
0f 78 11 22 33 44 cc cc + the same rc 2, 0x21d: number 59 rc 2, 0x21d: number 59
b8 3b 00 00 00 48 89 df 0f 05 c3 rc 2, 0x218 rc 2, 0x218: number 59
31 c0 0f 05 c3 rc 2, 0x212 rc 2, 0x212: number 0

What still skips (rc 0, the 0f 05 left in the output, Skipped 1 ... without a syscall number), all forbidden syscalls main refuses with rc 2:

gap bytes at 0x210 meaning this head
48 b8 3b 00 00 00 00 00 00 00 0f 05 c3 mov rax, 59 (imm64); syscall rc 0, skipped 0x21a
31 c0 b0 3b 0f 05 c3 xor eax,eax; mov al, 59; syscall rc 0, skipped 0x214
b8 3b 00 00 00 + 89 db×8 + 0f 05 c3 mov eax,59; 8 reg moves; syscall rc 0, skipped 0x225
b9 3b 00 00 00 89 c8 0f 05 c3 mov ecx,59; mov eax,ecx; syscall rc 0, skipped 0x217
6a 3b 58 0f 05 c3 push 59; pop rax; syscall rc 0, skipped 0x213
0d 3b 00 00 00 0f 05 c3 or eax, 59; syscall rc 0, skipped 0x215
b8 3b 00 00 00 48 89 f8 0f 05 c3 mov eax,59; mov rax,rdi; syscall rc 0, skipped 0x218

The last four match the residual the debt line names (number from another register or from push/or/an overwrite). The first three do not: the syscall number is a plain compile-time immediate still live in rax/eax at syscall, the check just does not model that encoding.

  • mov rax, imm64 (48 b8) is missed, while the other 64-bit form mov rax, imm32 (48 c7 c0 3b 00 00 00) is accepted and refused (0x217: number 59). Both encode mov rax, 59.
  • xor eax,eax; mov al, N is missed; xor eax,eax on its own is accepted (row 6, number 0). The 8-bit mov al after the zeroing is not followed.
  • The ≤7-move window is a hard edge: mov eax,59 + 7 mov ebx,ebx is refused (0x223: number 59), + 8 is skipped (0x225), though rax is untouched throughout.

So the debt entry's "whose number comes from memory or from another register" could also say "or from an immediate the lookback does not decode (mov rax, imm64, xor eax,eax; mov al, N, or a constant more than seven register ops before the syscall)". These only matter if such bytes are real code in a gap rather than data; with the gap-as-data premise they are benign, but they are not refused the way the three constant-immediate cases above suggest.

No false refusals: main refuses every gap syscall, so this PR only ever relaxes relative to main; there is no pattern main converts that this head rejects.

Other results:

  • ctest: this head 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release). main 30fda0a03 has no gap-skip logic (no Skipped message in the source) and the added tests are this PR's.
  • The four PS5 homebrew I have (PPSA99005, PPSA47402, PPSA99581, PPSA99995 with 16 Wine modules) have no PT_SCE_DYNLIBDATA, so these rules don't run; relinked --windows --to-intel, --macos --to-rosetta and Linux --to-intel, all 12 output sets are byte-identical to main 30fda0a03.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6292083000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6292083000). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T13:33:12Z. --- Verdict: confirm the fix for the six rows; it holds. One note on scope: the new raw-byte check still misses some ordinary constant syscall-number loads, and its debt line understates that. Re-ran at `58a2a4962` merged onto `main` `30fda0a03` (clean merge, head `a7c553bb3`), Windows 11 with WinLibs GCC 15.2.0 (relinker-only Release). Current `main` already refuses every syscall pattern it finds in a PS4 gap (rc 2), so each row below is `main` rc 2 vs this head. Same fixture as before (`executable(gap_bytes)`, one unwind function 0x200..0x210, bytes at 0x210); Linux, `--windows` and `--macos` all agree. The six original rows are now refused, as you describe: | gap bytes at 0x210 | `main` `30fda0a03` | this head | |---|---|---| | `b8 3b 00 00 00 0f 05 c3` | rc 2, `0x215: number 59` | rc 2, same | | `0f 78 11 22 33 44` + the same | rc 2, `0x21b` (no number) | rc 2, `0x21b: number 59` | | `0f 78 11 22 33 44 3c` + the same | rc 2, `0x21c` | rc 2, `0x21c: number 59` | | `0f 78 11 22 33 44 cc cc` + the same | rc 2, `0x21d: number 59` | rc 2, `0x21d: number 59` | | `b8 3b 00 00 00 48 89 df 0f 05 c3` | rc 2, `0x218` | rc 2, `0x218: number 59` | | `31 c0 0f 05 c3` | rc 2, `0x212` | rc 2, `0x212: number 0` | What still skips (rc 0, the `0f 05` left in the output, `Skipped 1 ... without a syscall number`), all forbidden syscalls `main` refuses with rc 2: | gap bytes at 0x210 | meaning | this head | |---|---|---| | `48 b8 3b 00 00 00 00 00 00 00 0f 05 c3` | `mov rax, 59` (imm64); syscall | rc 0, skipped `0x21a` | | `31 c0 b0 3b 0f 05 c3` | `xor eax,eax; mov al, 59`; syscall | rc 0, skipped `0x214` | | `b8 3b 00 00 00` + `89 db`×8 + `0f 05 c3` | `mov eax,59`; 8 reg moves; syscall | rc 0, skipped `0x225` | | `b9 3b 00 00 00 89 c8 0f 05 c3` | `mov ecx,59; mov eax,ecx`; syscall | rc 0, skipped `0x217` | | `6a 3b 58 0f 05 c3` | `push 59; pop rax`; syscall | rc 0, skipped `0x213` | | `0d 3b 00 00 00 0f 05 c3` | `or eax, 59`; syscall | rc 0, skipped `0x215` | | `b8 3b 00 00 00 48 89 f8 0f 05 c3` | `mov eax,59; mov rax,rdi`; syscall | rc 0, skipped `0x218` | The last four match the residual the debt line names (number from another register or from `push`/`or`/an overwrite). The first three do not: the syscall number is a plain compile-time immediate still live in rax/eax at `syscall`, the check just does not model that encoding. - `mov rax, imm64` (`48 b8`) is missed, while the other 64-bit form `mov rax, imm32` (`48 c7 c0 3b 00 00 00`) is accepted and refused (`0x217: number 59`). Both encode `mov rax, 59`. - `xor eax,eax; mov al, N` is missed; `xor eax,eax` on its own is accepted (row 6, number 0). The 8-bit `mov al` after the zeroing is not followed. - The ≤7-move window is a hard edge: `mov eax,59` + 7 `mov ebx,ebx` is refused (`0x223: number 59`), + 8 is skipped (`0x225`), though rax is untouched throughout. So the debt entry's "whose number comes from memory or from another register" could also say "or from an immediate the lookback does not decode (`mov rax, imm64`, `xor eax,eax; mov al, N`, or a constant more than seven register ops before the syscall)". These only matter if such bytes are real code in a gap rather than data; with the gap-as-data premise they are benign, but they are not refused the way the three constant-immediate cases above suggest. No false refusals: `main` refuses every gap syscall, so this PR only ever relaxes relative to `main`; there is no pattern `main` converts that this head rejects. Other results: - `ctest`: this head 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release). `main` `30fda0a03` has no gap-skip logic (no `Skipped` message in the source) and the added tests are this PR's. - The four PS5 homebrew I have (PPSA99005, PPSA47402, PPSA99581, PPSA99995 with 16 Wine modules) have no `PT_SCE_DYNLIBDATA`, so these rules don't run; relinked `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`, all 12 output sets are byte-identical to `main` `30fda0a03`. AI-assisted: yes (Claude Code); results above were run on this machine.
savvaniss commented 2026-10-20 15:13:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T15:13:40Z.


@wachi35676 Thank you, all three were real gaps. Fixed in e0095e5b4 (fix(relinker): find more constant syscall numbers before a gap syscall). The raw-byte check now:

  • accepts mov rax, imm64 (48 b8) as a constant load;
  • merges a mov al, imm8 (b0) or mov ax, imm16 (66 b8) that follows a constant into that constant. A partial write with no constant before it stays unknown;
  • walks back over any number of register-to-register moves or zeroings that leave rax alone, instead of at most seven. Visited states keep the walk linear in the bytes it covers.

Same fixture (executable(gap_bytes), bytes at 0x210), on Linux, --windows and --macos. Before is 58a2a4962:

gap bytes at 0x210 58a2a4962 e0095e5b4
48 b8 3b 00 00 00 00 00 00 00 0f 05 c3 rc 0, skipped 0x21a rc 2, 0x21a: syscall number 59
31 c0 b0 3b 0f 05 c3 rc 0, skipped 0x214 rc 2, 0x214: syscall number 59
31 c0 66 b8 3b 01 0f 05 c3 rc 0, skipped 0x216 rc 2, 0x216: syscall number 315
b8 3b 00 00 00 + 89 db×7 + 0f 05 c3 rc 2, 0x223: syscall number 59 rc 2, same
b8 3b 00 00 00 + 89 db×8 + 0f 05 c3 rc 0, skipped 0x225 rc 2, 0x225: syscall number 59
b9 3b 00 00 00 89 c8 0f 05 c3 rc 0, skipped 0x217 rc 0, skipped 0x217
6a 3b 58 0f 05 c3 rc 0, skipped 0x213 rc 0, skipped 0x213
0d 3b 00 00 00 0f 05 c3 rc 0, skipped 0x215 rc 0, skipped 0x215
b8 3b 00 00 00 48 89 f8 0f 05 c3 rc 0, skipped 0x218 rc 0, skipped 0x218
b0 3b 0f 05 c3 rc 0, skipped 0x212 rc 0, skipped 0x212

test_sce_code_gaps.py gains the 48 b8, 31 c0 b0, 31 c0 66 b8 and eight-move rows; each fails at 58a2a4962 on all three targets. mov al alone is pinned as still skipped. The debt entry now lists exactly what is still not refused, following your wording: a number set from memory or another register (mov eax, ecx), by push/pop or arithmetic (or eax, imm32), or with any other instruction between the load and the pattern.

On the real data, Boggle's 67 and Trivial Pursuit's 28 patterns are all still skipped, and nothing new is refused. That holds on a stack of main, #6684, #8168 and #6977's TLS relocation commit: all four Hasbro games convert for Windows, Boggle and Trivial Pursuit with their Unity Modules and Plugins.

@ntamas94 Thank you for the Gang Beasts rerun on 58a2a49. It confirms SandstromPL's expectation on real AOT code, and it shows the raw-byte check leaves all 147 patterns in MonoAssembliesPS4.prx alone. This commit can only turn a skip into a refusal, so I expect the same output there. A rerun on this head would confirm it if you have time.

Results: full ctest 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release); check_conventions.py passes.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6294216149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6294216149). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T15:13:40Z. --- @wachi35676 Thank you, all three were real gaps. Fixed in e0095e5b4 (`fix(relinker): find more constant syscall numbers before a gap syscall`). The raw-byte check now: - accepts `mov rax, imm64` (`48 b8`) as a constant load; - merges a `mov al, imm8` (`b0`) or `mov ax, imm16` (`66 b8`) that follows a constant into that constant. A partial write with no constant before it stays unknown; - walks back over any number of register-to-register moves or zeroings that leave `rax` alone, instead of at most seven. Visited states keep the walk linear in the bytes it covers. Same fixture (`executable(gap_bytes)`, bytes at 0x210), on Linux, `--windows` and `--macos`. Before is 58a2a4962: | gap bytes at 0x210 | 58a2a4962 | e0095e5b4 | |---|---|---| | `48 b8 3b 00 00 00 00 00 00 00 0f 05 c3` | rc 0, skipped `0x21a` | rc 2, `0x21a: syscall number 59` | | `31 c0 b0 3b 0f 05 c3` | rc 0, skipped `0x214` | rc 2, `0x214: syscall number 59` | | `31 c0 66 b8 3b 01 0f 05 c3` | rc 0, skipped `0x216` | rc 2, `0x216: syscall number 315` | | `b8 3b 00 00 00` + `89 db`×7 + `0f 05 c3` | rc 2, `0x223: syscall number 59` | rc 2, same | | `b8 3b 00 00 00` + `89 db`×8 + `0f 05 c3` | rc 0, skipped `0x225` | rc 2, `0x225: syscall number 59` | | `b9 3b 00 00 00 89 c8 0f 05 c3` | rc 0, skipped `0x217` | rc 0, skipped `0x217` | | `6a 3b 58 0f 05 c3` | rc 0, skipped `0x213` | rc 0, skipped `0x213` | | `0d 3b 00 00 00 0f 05 c3` | rc 0, skipped `0x215` | rc 0, skipped `0x215` | | `b8 3b 00 00 00 48 89 f8 0f 05 c3` | rc 0, skipped `0x218` | rc 0, skipped `0x218` | | `b0 3b 0f 05 c3` | rc 0, skipped `0x212` | rc 0, skipped `0x212` | `test_sce_code_gaps.py` gains the `48 b8`, `31 c0 b0`, `31 c0 66 b8` and eight-move rows; each fails at 58a2a4962 on all three targets. `mov al` alone is pinned as still skipped. The debt entry now lists exactly what is still not refused, following your wording: a number set from memory or another register (`mov eax, ecx`), by `push`/`pop` or arithmetic (`or eax, imm32`), or with any other instruction between the load and the pattern. On the real data, Boggle's 67 and Trivial Pursuit's 28 patterns are all still skipped, and nothing new is refused. That holds on a stack of `main`, #6684, #8168 and #6977's TLS relocation commit: all four Hasbro games convert for Windows, Boggle and Trivial Pursuit with their Unity `Modules` and `Plugins`. @ntamas94 Thank you for the Gang Beasts rerun on 58a2a49. It confirms SandstromPL's expectation on real AOT code, and it shows the raw-byte check leaves all 147 patterns in `MonoAssembliesPS4.prx` alone. This commit can only turn a skip into a refusal, so I expect the same output there. A rerun on this head would confirm it if you have time. Results: full `ctest` 223/223 (Windows 11, WinLibs GCC 15.2, relinker-only Release); `check_conventions.py` passes. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8166
No description provided.