fix(relinker): report the syscall number of a forbidden syscall instruction #2206
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2206"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by StarMrGamer on 2026-10-09T11:32:35Z.
What
Part of #2136: the syscall check now names the syscall the guest tried to reach, instead of only the code offset.
Seven catalog homebrew titles stop on the raw FreeBSD syscall stubs that
ps5-payload-dev's libc carries (libc/syscalls.c), and the current message gives nothing to act on:The fixed stubs set the number with a constant right before the instruction (
48 C7 C0 09 00 00 00ismov rax, 9, FreeBSDlink;B8 39 00 00 00ismov eax, 57,symlink).SyscallScannernow looks back for a constant load into rax and adds it:The number is only reported when it can be established. The constant load must be the instruction directly before the syscall, or one
mov r10, rcx(the SDK's first-argument move, which does not write rax) in front of it. Any other intervening instruction stops the inference rather than returning a stale value, somov rax, 9; add rax, 1; syscallreports no number instead of 9. A stub that takes the number from a register — the SDK's genericsyscall()/__syscall()wrapper reads rax from rdi — also reports no number and keeps today's text. The check still throws and nothing else changes;--skip-syscall-checkis unaffected.This does not pick one of the three directions in #2136, and the relinker still refuses the title. It makes the failure say which call it hit, which all three directions need, and it is the number #2136's author had to recover by hand with a disassembler.
Tested
Linux x86-64, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), GCC 16.2.1:ctest45/45.syscall_scannercovers all four forbidden opcodes — the 64-bit constant stub → number 9, the 32-bit constant stub → number 57,int 0x80→ number 11,sysenter→ no number,sysretwith a constant load in front of it → no number, a stub that loads rax from a register → no number, and a stub whose intervening instruction writes rax → no number (the regression for the review).test_syscall_numbercovers the same contract through the Python harness, so it also runs on Windows and macOS, where the C++ fixture helpers do not build.tools/check_conventions.py --base origin/mainandtools/check_test_registration.pyboth pass.Windows: not run here. @rmz-24 built
529476c7(the previous head, unchanged in this respect) ontomaind70b8998with MinGW-w64 GCC 15.2.0 and reported 510/510 on the fullctest.Not tested: a real title; no PS5 or homebrew title was run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T12:06:53Z.
Review: CHANGES_REQUESTED
The syscall-number lookback can report a stale value after an intervening instruction writes RAX. I reproduced this on the PR head by adding
48 83 C0 01(add rax, 1) between themov rax, 9andsyscallinkConstantStub, and expecting 10. The test fails: the scanner still reportssyscall number 9.ConstantSyscallNumbercurrently checks onlyFlowKind::Sequentialbefore continuing backward; it does not check whether the intervening instruction changes RAX/EAX. Please stop the inference when an intervening instruction may write RAX (or accurately propagate the value for supported instructions), and add a regression for this case. The original test suite passes; the added local repro exposes the diagnostic error.Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T13:31:10Z.
Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
-DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build pluslibs. 529476c7 cherry-picked onto currentmaind70b8998(applies cleanly).syscall_scanneritself isn't built on Windows: it is registered inside the Linux x86-64 block, and the sharedElfFixture.hppincludessys/mman.h, so it can't be moved out as is. The rest of the relinker suite, including its Windows PE execution tests, passes with this change.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:06Z.
#1935 is on main now and conflicts in
SyscallScanner.cpp(andcore/relinker/CMakeLists.txt); please rebase, keeping its opcode-offset classification as you described.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:33:11Z.
Review: CHANGES_REQUESTED
Checked on Linux:
syscall_scannerandsyscall_numberpass, and both fail withSyscallScanner.cppreverted tomain, so they pin the change. The lookback logic (constant load directly before the instruction, or onemov r10, rcxin between, otherwise no number) looks right, and the rax-clobber case from the earlier review is covered.One blocker, same as @oneandonlydean asked above:
mainnow and conflicts with this PR incore/relinker/relinker/src/analysis/SyscallScanner.cppandcore/relinker/CMakeLists.txt(git merge-treereports content conflicts in both). Please rebase and make the lookback work with the prefixed-opcode offset #1935 introduces, then re-runsyscall_scannerandsyscall_number.Not covered by the Windows run linked above: it ran the previous head, and
syscall_number.pywas added afterwards.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T10:36:08Z.
Review: APPROVED
I re-reviewed current head
5fc98348b71bedb1b2f92a2ee9437f84965b93ab. The earlier issues I raised are addressed: an unrecognized intervening instruction stops syscall-number inference, and the lookback uses decoded opcode offsets so prefixed instructions work with #1935's scanner change.upstream/maingit diff --checkMy earlier
CHANGES_REQUESTEDreview no longer reflects this head, so I approve the code changes. This does not replace the repository-required manual Linux/Windows Build and Linux/Windows/macOS relinker workflow; those full Build checks are still skipped on the PR and remain required before merge.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-10T11:19:57Z.
Independent run on macOS (Apple silicon M2, macOS 26.7.1, Apple clang 21.0.0, CMake 4.2.3, Release, relinker-only build).
5fc98348 merged onto main
b5f5362d(clean merge):syscall_number.SyscallScanner.cpprestored to main's version,syscall_numberfails and the other 90 pass, so the test pins the change.syscall_scanneris not registered on macOS.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-10T13:27:09Z.
Independent validation on Windows
Built the
relinkerand ran the PR head5fc98348's test on my own box:Release,BUILD_TESTING=ON.Results:
test_syscall_number.pyPASSES against the builtrelinker. All nine cases behave as documented:int 0x80→ 11; prefixed constant → 9;sysenter,sysret(with a const load in front), clobbered-rax, and prefixed-clobbered → no number (kept the plain offset text);Rigor check (is the test real?): I disabled the number-reporting branch in
SyscallScanner.cpp(forced theInvocationguard false), rebuilt, and the test failed —AssertionError: ('constant', 'did not report syscall number 9'). Restoring the line → PASS. So the harness genuinely verifies the new diagnostic rather than passing unconditionally.Note on the C++ fixture: I confirmed in
core/relinker/CMakeLists.txtthatsyscall_scanner_tests(C++) is gated toLinux x86_64only, so on Windows/macOS the Python harness is the complete path — consistent with your note that the C++ fixture helpers don't build there. I validated via the Python harness accordingly.Honest limits: I only verified the syscall-number diagnostic (a message improvement). I did not run a real title (you note none was run either), and I did not test Linux/macOS.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:28:55Z.
Review: APPROVED
Rebased onto current
main(only conflict: theadd_testlines incore/relinker/CMakeLists.txtnext toto_rosetta, both kept). Relinker build,syscall_scannerandsyscall_numberpass, and the scoped ctest is 92/92. The failedwrite-watch (macos-15-intel)job is awrite_watch_threadstimeout unrelated to this relinker-only change. Also confirmed by @MarcZX100 (Linux), @rmz-24 and @klosixgaming-arch (Windows), @DavidSamir (macOS). Merging.