relinker: the two syscall-number paths disagree on sign-extension and on the constant-load forms they recognize #10422

Closed
opened 2026-10-23 23:54:48 +00:00 by KSWORK2001 · 0 comments
KSWORK2001 commented 2026-10-23 23:54:48 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by KSWORK2001 on 2026-10-23T23:54:48Z.


The refusal message of the syscall scan names the FreeBSD syscall number when a constant load before the pattern establishes it. Two different paths compute that number, and they disagree: ConstantSyscallNumber (core/relinker/relinker/src/analysis/SyscallScanner.cpp) walks the decoded instructions before the pattern through ConstantRaxLoad, and ConstantSyscallNumberInBytes/ConstantRaxSetEndingAt scan the raw bytes back from the pattern when unwind functions exist and the pattern lies outside them.

Measured on main 999e612599, relinker-only build, with the fixture style of test_syscall_number.py (no unwind table, decodable stream → first path) and test_sce_code_gaps.py (pattern in a gap after undecodable bytes → second path):

Load before syscall rax on AMD decodable stream reports byte window reports
48 C7 C0 FF FF FF FF (mov rax, imm32, -1) 0xFFFFFFFFFFFFFFFF syscall number 4294967295 syscall number 18446744073709551615
48 B8 imm64 (mov rax, imm64) the immediate no number at all the immediate
31 C0 (xor eax, eax) 0 no number at all syscall number 0

So the same instruction sequence names a different number depending on where it sits, mov rax, imm32 reports the raw immediate where the register holds the sign-extended value (ConstantRaxSetEndingAt already sign-extends; ConstantRaxLoad does not), and mov rax, imm64 or xor eax, eax immediately before a syscall establish a number that the decodable path never reports. The B8 imm32 form (mov eax, imm32) is reported zero-extended by both, which is correct.

Both paths end in the same refusal, so conversion results do not differ; the number in the message is the only divergence. That message is the primary diagnostic for the most common homebrew conversion failure, and the project's reports quote it verbatim.

Reproduction (decodable path): an executable whose code begins 48 C7 C0 FF FF FF FF 49 89 CA 0F 05 C3 fails with Forbidden syscall instruction at code offset 0xa: syscall number 4294967295; the same load in a gap after undecodable bytes fails with syscall number 18446744073709551615. 48 B8 09 00 00 00 00 00 00 00 49 89 CA 0F 05 C3 fails with no number, where the byte window names 9.

Direction: make ConstantRaxLoad recognize the same forms as ConstantRaxSetEndingAt with the same extension: 48 C7 C0 imm32 sign-extended, 48 B8 imm64, B8 imm32 zero-extended, and 31/33 C0 zeroing (an operand-size prefix excludes the xor forms, since 66 31 C0 clears only AX).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6007210409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10422). Originally posted by [KSWORK2001](https://github.com/KSWORK2001) on 2026-10-23T23:54:48Z. --- The refusal message of the syscall scan names the FreeBSD syscall number when a constant load before the pattern establishes it. Two different paths compute that number, and they disagree: `ConstantSyscallNumber` (core/relinker/relinker/src/analysis/SyscallScanner.cpp) walks the decoded instructions before the pattern through `ConstantRaxLoad`, and `ConstantSyscallNumberInBytes`/`ConstantRaxSetEndingAt` scan the raw bytes back from the pattern when unwind functions exist and the pattern lies outside them. Measured on `main` `999e612599`, relinker-only build, with the fixture style of `test_syscall_number.py` (no unwind table, decodable stream → first path) and `test_sce_code_gaps.py` (pattern in a gap after undecodable bytes → second path): | Load before `syscall` | rax on AMD | decodable stream reports | byte window reports | |---|---|---|---| | `48 C7 C0 FF FF FF FF` (mov rax, imm32, -1) | `0xFFFFFFFFFFFFFFFF` | `syscall number 4294967295` | `syscall number 18446744073709551615` | | `48 B8 imm64` (mov rax, imm64) | the immediate | no number at all | the immediate | | `31 C0` (xor eax, eax) | 0 | no number at all | `syscall number 0` | So the same instruction sequence names a different number depending on where it sits, `mov rax, imm32` reports the raw immediate where the register holds the sign-extended value (`ConstantRaxSetEndingAt` already sign-extends; `ConstantRaxLoad` does not), and `mov rax, imm64` or `xor eax, eax` immediately before a syscall establish a number that the decodable path never reports. The `B8 imm32` form (mov eax, imm32) is reported zero-extended by both, which is correct. Both paths end in the same refusal, so conversion results do not differ; the number in the message is the only divergence. That message is the primary diagnostic for the most common homebrew conversion failure, and the project's reports quote it verbatim. Reproduction (decodable path): an executable whose code begins `48 C7 C0 FF FF FF FF 49 89 CA 0F 05 C3` fails with `Forbidden syscall instruction at code offset 0xa: syscall number 4294967295`; the same load in a gap after undecodable bytes fails with `syscall number 18446744073709551615`. `48 B8 09 00 00 00 00 00 00 00 49 89 CA 0F 05 C3` fails with no number, where the byte window names 9. Direction: make `ConstantRaxLoad` recognize the same forms as `ConstantRaxSetEndingAt` with the same extension: `48 C7 C0 imm32` sign-extended, `48 B8 imm64`, `B8 imm32` zero-extended, and `31`/`33 C0` zeroing (an operand-size prefix excludes the xor forms, since `66 31 C0` clears only AX). AI-assisted: yes
Sign in to join this conversation.
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#10422
No description provided.