Ratchet & Clank: Rift Apart: stack overflow in RegisterShader on a 48 KiB guest thread since #1988 #2603

Closed
opened 2026-10-10 08:20:51 +00:00 by EdouardSence · 1 comment
EdouardSence commented 2026-10-10 08:20:51 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-10T08:20:51Z.


What

Since #1988, Ratchet & Clank: Rift Apart (PPSA01474) dies about 12 s after start on Linux with a SIGSEGV and no log line. The stack overflows inside sceAgcCreateShader:

#0  AgcDriver::DriverDetail::Driver::RegisterShader(Shader const*)   libSceAgcDriver.prx + 0x22bb9f
#1  AgcDriverRegisterShader_nid_postfix                              libSceAgcDriver.prx + 0x1ceef6
#2  sceAgcCreateShader                                               libSceAgc.prx + 0x131e9
#3..#9  title code
#10 StartNativeThread                                                libkernel.prx + 0x5df17
  • si_code is SEGV_MAPERR and the fault address is rsp - 8, at the first call after the prologue.
  • The prologue is sub $0xc478,%rsp, so RegisterShader reserves 50,296 bytes of stack before calling anything. On the probe build I used earlier it reserved 0x18608 bytes. It depends on what gets inlined into it.
  • The title creates its shader-creating threads with small stacks. These are the requested sizes it passes to scePthreadCreate (logged locally):
threads stack size
Job Hi 0..7, Job Lo 0..7 49,152
Render Thread, File Video Stream, Archive Loose IO 65,536
User Trophy Thread, User UDS Thread 16,384

Before #1988, every guest thread on Linux ran on the host's default 8 MiB stack, so this never showed. Now the thread gets exactly what the title asked for, which is correct for the title's own code. But AnyPS5's HLE code runs on that same stack, and a call that is a light system call on the console runs the shader recompiler here.

Measured

Linux (CachyOS, GCC, Release), RX 9070 XT, RADV / Mesa 26.2.4, headless gamescope, scripted input.

build result
main 3539d1ce SIGSEGV at about 12 s, 3 of 3 runs (one with APS5_NO_WRITE_WATCH=1)
main 3539d1ce with #1988 reverted no crash. 241 presents per 10 s; it stops at 64 s on AGC driver: prepared shader artifact is missing for the requested static ABI ... stage=5, which is a separate issue

Options I can see (not tested)

  • Run the registration-time preparation on a host thread with a known stack (or a worker), and wait for it.
  • Give guest threads a fixed host reserve below the stack range the title sees. The title would still see the size it asked for, as #1988 intends.
  • Shrink RegisterShader's frame. That only moves the limit; Windows already has the same exact-size stacks.

I can't open a PR at the moment (pr-intake), so I'm leaving the choice and the fix to whoever picks this up. I can rerun the title on any candidate. cc @NevesHenry

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5789530668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2603). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-10T08:20:51Z. --- ### What Since #1988, Ratchet & Clank: Rift Apart (PPSA01474) dies about 12 s after start on Linux with a `SIGSEGV` and no log line. The stack overflows inside `sceAgcCreateShader`: ``` #0 AgcDriver::DriverDetail::Driver::RegisterShader(Shader const*) libSceAgcDriver.prx + 0x22bb9f #1 AgcDriverRegisterShader_nid_postfix libSceAgcDriver.prx + 0x1ceef6 #2 sceAgcCreateShader libSceAgc.prx + 0x131e9 #3..#9 title code #10 StartNativeThread libkernel.prx + 0x5df17 ``` - `si_code` is `SEGV_MAPERR` and the fault address is `rsp - 8`, at the first `call` after the prologue. - The prologue is `sub $0xc478,%rsp`, so `RegisterShader` reserves 50,296 bytes of stack before calling anything. On the probe build I used earlier it reserved `0x18608` bytes. It depends on what gets inlined into it. - The title creates its shader-creating threads with small stacks. These are the requested sizes it passes to `scePthreadCreate` (logged locally): | threads | stack size | |---|---| | `Job Hi 0..7`, `Job Lo 0..7` | 49,152 | | `Render Thread`, `File Video Stream`, `Archive Loose IO` | 65,536 | | `User Trophy Thread`, `User UDS Thread` | 16,384 | Before #1988, every guest thread on Linux ran on the host's default 8 MiB stack, so this never showed. Now the thread gets exactly what the title asked for, which is correct for the title's own code. But AnyPS5's HLE code runs on that same stack, and a call that is a light system call on the console runs the shader recompiler here. ### Measured Linux (CachyOS, GCC, Release), RX 9070 XT, RADV / Mesa 26.2.4, headless gamescope, scripted input. | build | result | |---|---| | `main` 3539d1ce | `SIGSEGV` at about 12 s, 3 of 3 runs (one with `APS5_NO_WRITE_WATCH=1`) | | `main` 3539d1ce with #1988 reverted | no crash. 241 presents per 10 s; it stops at 64 s on `AGC driver: prepared shader artifact is missing for the requested static ABI ... stage=5`, which is a separate issue | ### Options I can see (not tested) - Run the registration-time preparation on a host thread with a known stack (or a worker), and wait for it. - Give guest threads a fixed host reserve below the stack range the title sees. The title would still see the size it asked for, as #1988 intends. - Shrink `RegisterShader`'s frame. That only moves the limit; Windows already has the same exact-size stacks. I can't open a PR at the moment (`pr-intake`), so I'm leaving the choice and the fix to whoever picks this up. I can rerun the title on any candidate. cc @NevesHenry *Tested and written by Claude (AI assistant) on a contributor's machine.*
hugodearaujo commented 2026-10-10 16:08:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-10T16:08:46Z.


Another title with the same cause, where it shows up as memory corruption instead of a clean SIGSEGV: Hollow Knight: Silksong (PPSA12544) on Linux (RX 9070 XT, GCC 16.2, Release).

The title creates most of its threads with 131,072-byte stacks (49 threads; one asks for 256 KiB and one for 1 MiB). About 0.25 s after start, the thread that submits command buffers (sceAgcDriverSubmitDcb → Driver::Submit → copySegment → readRegisterLists → validate → Pm4::ReadIndirectRegisters → GuestMemory::Read → FlushForAccess) faults on a null pointer. The HostThreadLocal vector QueuedLabelRanges in that thread's TLS has begin 0 and a non-null end. So the TLS had been overwritten before the fault, not merely overflowed into a guard page.

On main 425421276 + #846 + #861 + #1431 (conflicts resolved locally), with only pthread_attr_setstacksize in the Linux scePthreadCreate changed:

native stack result, 3 runs each
requested + reserve (as on main) fault at about 0.25 s every time
host default (setstacksize skipped) runs for the full 40 s, about 180 textures loaded
requested + reserve + 1 MiB runs normally

So a fixed host reserve on top of the requested size, your second option, is enough here. It also suggests that what a smaller overflow does is not always a fault on the stack itself.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099508017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2603#issuecomment-6099508017). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-10T16:08:46Z. --- Another title with the same cause, where it shows up as memory corruption instead of a clean `SIGSEGV`: Hollow Knight: Silksong (PPSA12544) on Linux (RX 9070 XT, GCC 16.2, Release). The title creates most of its threads with 131,072-byte stacks (49 threads; one asks for 256 KiB and one for 1 MiB). About 0.25 s after start, the thread that submits command buffers (`sceAgcDriverSubmitDcb` → `Driver::Submit` → `copySegment` → `readRegisterLists` → `validate` → `Pm4::ReadIndirectRegisters` → `GuestMemory::Read` → `FlushForAccess`) faults on a null pointer. The `HostThreadLocal` vector `QueuedLabelRanges` in that thread's TLS has begin `0` and a non-null end. So the TLS had been overwritten before the fault, not merely overflowed into a guard page. On `main` `425421276` + #846 + #861 + #1431 (conflicts resolved locally), with only `pthread_attr_setstacksize` in the Linux `scePthreadCreate` changed: | native stack | result, 3 runs each | |---|---| | requested + reserve (as on `main`) | fault at about 0.25 s every time | | host default (setstacksize skipped) | runs for the full 40 s, about 180 textures loaded | | requested + reserve + 1 MiB | runs normally | So a fixed host reserve on top of the requested size, your second option, is enough here. It also suggests that what a smaller overflow does is not always a fault on the stack itself.
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#2603
No description provided.