relinker: route ps5-payload-dev SDK syscall stubs to the libkernel exports that already implement them #10219

Closed
opened 2026-10-23 14:24:21 +00:00 by VakzOs · 0 comments
VakzOs commented 2026-10-23 14:24:21 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by VakzOs on 2026-10-23T14:24:21Z.


Follow-up to #2136, which #3804 closed by adding --trap-sdk-syscall-stubs.

What happens

Homebrew built with the ps5-payload-dev SDK carries numbered syscall stubs (mov rax, N; mov r10, rcx; syscall; ret). Without --trap-sdk-syscall-stubs the relinker refuses the executable:

FAIL: Forbidden syscall instruction at code offset 0xca968a: syscall number 191

With the flag the stub becomes UD2. The title converts, and it crashes only if the stub runs. USAGE.md documents the flag as debugging only.

The flag is now part of the normal recipe for catalog homebrew. Public reports collected on the blocker map use it for 18 titles:

  • PPSA01153 OliSe Player
  • PPSA68091 Ruffle Flash
  • PPSA69420 ScreenTester5
  • PPSA69421 SuperTuxKart
  • PPSA97510 PSXS5
  • PPSA98510 SwanStationPS5
  • PPSA99004 ProsperoAI
  • PPSA99007 Yamagi Quake II
  • PPSA99008 ProsperoEden
  • PPSA99011 PS5 FSR4 Showcase
  • PPSA99203 PS5SX2
  • PPSA99288 Nuvio Max'd
  • PPSA99305 Dusklight
  • PPSA99309 Wind Waker
  • PPSA99360 PS5CEMU-HAR
  • PPSA99474 Twispero
  • PPSA99865 Java 25 JVM Startup
  • PPSA99869 DNS

A 19th is Apotris (PPSA98513, catalog v1.0.0), tested this week.

One case, disassembled

I looked at a single title. In Apotris the only raw syscall in the executable is that stub. Its number is 191, FreeBSD pathconf. It has one caller:

lea  rdi, [rip+...]   ; "."
mov  esi, 5           ; _PC_PATH_MAX
call stub_191         ; mov rax, 0xbf; mov r10, rcx; syscall; ret
cmp  rax, -1

The caller sits next to the current_path string, which matches libc++ std::filesystem::current_path(). AnyPS5 already implements this call as libkernel_sys pathconf, including name 5 = 1024. Only the route is missing.

Proposal

When the relinker matches an exact numbered SDK stub whose syscall number is on a fixed list, it would replace the stub with a jump to the libkernel export that implements that syscall, instead of UD2. The stub's arguments are already in SysV order: the mov r10, rcx only feeds the kernel. Numbers that are not on the list keep today's behaviour: refuse by default, UD2 with the flag. The list starts with the numbers that converted titles actually contain, one entry per verified syscall, each with a test. Pathconf (191) would be the first.

A second way would leave the relinker alone. A trapped stub still runs mov rax, N before its UD2, and the caller's return address is on top of the stack. A runtime illegal-instruction handler could check for the exact trapped stub bytes, look up N, and set rip to the libkernel export. That is a tail call that returns straight to the caller, with the arguments untouched. Windows already has a precedent in HandleSse4a in CrashReport.cpp. Linux and macOS have no SIGILL handler, though, and a guest can install its own, so this way needs more design than the relinker one.

Open questions for maintainers

  1. Is redirecting stubs wanted, or is the refusal deliberate beyond "not implemented yet"? The flag's documentation says it "does not implement FreeBSD syscalls", which reads as a scope decision.
  2. Error convention: a raw FreeBSD syscall reports failure with the carry flag and a positive errno in rax, while the libkernel export returns -1 and sets errno. The Apotris caller tests for -1. Should the redirect keep libkernel's convention, or should it go through a thunk that reproduces the raw one?
  3. Which way is preferred: rewriting the stub at relink time, or handling the trap at run time? And where should the list of syscall numbers live?

AI-assisted: yes. The disassembly and the list of titles above were gathered with an AI assistant; only Apotris was disassembled.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5999577624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10219). Originally posted by [VakzOs](https://github.com/VakzOs) on 2026-10-23T14:24:21Z. --- Follow-up to #2136, which #3804 closed by adding `--trap-sdk-syscall-stubs`. ### What happens Homebrew built with the ps5-payload-dev SDK carries numbered syscall stubs (`mov rax, N; mov r10, rcx; syscall; ret`). Without `--trap-sdk-syscall-stubs` the relinker refuses the executable: ``` FAIL: Forbidden syscall instruction at code offset 0xca968a: syscall number 191 ``` With the flag the stub becomes `UD2`. The title converts, and it crashes only if the stub runs. USAGE.md documents the flag as debugging only. The flag is now part of the normal recipe for catalog homebrew. Public reports collected on the [blocker map](https://alxcbtw.github.io/anyps5-roadmap/) use it for 18 titles: - PPSA01153 OliSe Player - PPSA68091 Ruffle Flash - PPSA69420 ScreenTester5 - PPSA69421 SuperTuxKart - PPSA97510 PSXS5 - PPSA98510 SwanStationPS5 - PPSA99004 ProsperoAI - PPSA99007 Yamagi Quake II - PPSA99008 ProsperoEden - PPSA99011 PS5 FSR4 Showcase - PPSA99203 PS5SX2 - PPSA99288 Nuvio Max'd - PPSA99305 Dusklight - PPSA99309 Wind Waker - PPSA99360 PS5CEMU-HAR - PPSA99474 Twispero - PPSA99865 Java 25 JVM Startup - PPSA99869 DNS A 19th is Apotris (PPSA98513, catalog v1.0.0), tested this week. ### One case, disassembled I looked at a single title. In Apotris the only raw syscall in the executable is that stub. Its number is 191, FreeBSD `pathconf`. It has one caller: ``` lea rdi, [rip+...] ; "." mov esi, 5 ; _PC_PATH_MAX call stub_191 ; mov rax, 0xbf; mov r10, rcx; syscall; ret cmp rax, -1 ``` The caller sits next to the `current_path` string, which matches libc++ `std::filesystem::current_path()`. AnyPS5 already implements this call as `libkernel_sys` `pathconf`, including name 5 = 1024. Only the route is missing. ### Proposal When the relinker matches an exact numbered SDK stub whose syscall number is on a fixed list, it would replace the stub with a jump to the libkernel export that implements that syscall, instead of `UD2`. The stub's arguments are already in SysV order: the `mov r10, rcx` only feeds the kernel. Numbers that are not on the list keep today's behaviour: refuse by default, `UD2` with the flag. The list starts with the numbers that converted titles actually contain, one entry per verified syscall, each with a test. Pathconf (191) would be the first. A second way would leave the relinker alone. A trapped stub still runs `mov rax, N` before its `UD2`, and the caller's return address is on top of the stack. A runtime illegal-instruction handler could check for the exact trapped stub bytes, look up N, and set `rip` to the libkernel export. That is a tail call that returns straight to the caller, with the arguments untouched. Windows already has a precedent in `HandleSse4a` in `CrashReport.cpp`. Linux and macOS have no SIGILL handler, though, and a guest can install its own, so this way needs more design than the relinker one. ### Open questions for maintainers 1. Is redirecting stubs wanted, or is the refusal deliberate beyond "not implemented yet"? The flag's documentation says it "does not implement FreeBSD syscalls", which reads as a scope decision. 2. Error convention: a raw FreeBSD syscall reports failure with the carry flag and a positive errno in `rax`, while the libkernel export returns -1 and sets `errno`. The Apotris caller tests for -1. Should the redirect keep libkernel's convention, or should it go through a thunk that reproduces the raw one? 3. Which way is preferred: rewriting the stub at relink time, or handling the trap at run time? And where should the list of syscall numbers live? AI-assisted: yes. The disassembly and the list of titles above were gathered with an AI assistant; only Apotris was disassembled.
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#10219
No description provided.