sceKernelLoadStartModule discards the module parameter block, so modules that validate it fault at start-up #918

Closed
opened 2026-10-06 16:39:58 +00:00 by jeffrey12cali · 11 comments
jeffrey12cali commented 2026-10-06 16:39:58 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T16:39:58Z.


Symptom

On Linux a title's own module faults inside its start-up path immediately after being loaded. Measured on PPSA28997, in its PSN.prx:

Thread 1 SIGSEGV  rip = PSN.prx.guest.prx+0x3ee7     rbx = 0

The faulting helper is a parameter validator. Its own strings identify the handshake:

"\nERROR..."  "PSN"
" %s is an old version that cannot be used by the current player runtime.\n"
" Please update the %s native module and any associated managed assemblies to the latest versions\n"
"  Plugin args version, found %04x, expected %04x\n"

Disassembly of the entry (PSN+0x3e86):

7e87: mov  rsi, rbx                      ; rbx = the parameter struct
7e8a: test edi, 0xfffffff0
7e90: je   7eb2                          ; -> error path
7e92: cmp  dword [rbx], 0x10             ; struct size must be 16
7e97: cmp  dword [rbx+4], 0x200          ; version must be 0x200
7ea0: mov  rax, [rbx+8]                  ; the payload pointer
7ea4: mov  [rip+0x5037d], rax            ; store it
...
7eb2: <log the "old version" message>
7ee7: mov  esi, [rbx+4]                  ; CRASH - rbx is null on this path

So the module expects a 16-byte, version-0x200 parameter block at start-up, never receives one, and its error path then dereferences the missing block.

Cause

sceKernelLoadStartModule accepts the parameter block and throws it away (core/libs/prx/libkernel/Module/src/Module.cpp):

KernelModule APS5_VABI sceKernelLoadStartModule(const char* module_file_name, size_t args, const void* argp,
                                                uint32_t flags, const KernelLoadModuleOpt* opt, int* res) {
    (void)args;
    (void)argp;
    (void)flags;
    (void)opt;
    if (res) *res = 0;
    ...
    void* handle = dlopen_nid_postfix(module_file_name, kRtldNow);

sceKernelStopUnloadModule discards args/argp/flags/opt the same way. Nothing in the tree forwards a module parameter block to a guest module's start routine - the Windows .ginit lifecycle hook (DynamicLoader.cpp) invokes the lifecycle functions but passes no arguments either. On PS5 the module's entry receives (args, argp), so any title that hands its modules a parameter struct cannot work: the module sees a null block and, in this case, crashes in its own unchecked error path.

Expected

LoadStartModule should retain (args, argp) for the load it is performing and pass them to the module's start entry (the same entry the .ginit lifecycle runs on Windows), and StopUnloadModule should pass its pair to the stop entry. The flags/opt fields likely want at least validation, and res should carry the module's own result rather than being pinned to 0.

Notes

  • This is separate from #906 (the .native wrapper dependency edge), which is what prevents this module from loading at all; with that worked around, the module loads and then hits this.
  • The title's module is not the only possible consumer: any sceKernelLoadStartModule call site that passes a non-zero args is affected. In this title the parameter block is 16 bytes with a 0x200 version field, i.e. a versioned struct rather than a string or handle.
  • Happy to prototype the plumbing if you can point at where you would want the start entry invoked (the relinker's guest module writer emits the lifecycle information today, so the argument pair may need to travel from LoadStartModule through to that call rather than into dlopen).
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5732045010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T16:39:58Z. --- ### Symptom On Linux a title's own module faults inside its start-up path immediately after being loaded. Measured on PPSA28997, in its `PSN.prx`: ``` Thread 1 SIGSEGV rip = PSN.prx.guest.prx+0x3ee7 rbx = 0 ``` The faulting helper is a parameter validator. Its own strings identify the handshake: ``` "\nERROR..." "PSN" " %s is an old version that cannot be used by the current player runtime.\n" " Please update the %s native module and any associated managed assemblies to the latest versions\n" " Plugin args version, found %04x, expected %04x\n" ``` Disassembly of the entry (`PSN+0x3e86`): ``` 7e87: mov rsi, rbx ; rbx = the parameter struct 7e8a: test edi, 0xfffffff0 7e90: je 7eb2 ; -> error path 7e92: cmp dword [rbx], 0x10 ; struct size must be 16 7e97: cmp dword [rbx+4], 0x200 ; version must be 0x200 7ea0: mov rax, [rbx+8] ; the payload pointer 7ea4: mov [rip+0x5037d], rax ; store it ... 7eb2: <log the "old version" message> 7ee7: mov esi, [rbx+4] ; CRASH - rbx is null on this path ``` So the module expects a 16-byte, version-`0x200` parameter block at start-up, never receives one, and its error path then dereferences the missing block. ### Cause `sceKernelLoadStartModule` accepts the parameter block and throws it away (`core/libs/prx/libkernel/Module/src/Module.cpp`): ```c KernelModule APS5_VABI sceKernelLoadStartModule(const char* module_file_name, size_t args, const void* argp, uint32_t flags, const KernelLoadModuleOpt* opt, int* res) { (void)args; (void)argp; (void)flags; (void)opt; if (res) *res = 0; ... void* handle = dlopen_nid_postfix(module_file_name, kRtldNow); ``` `sceKernelStopUnloadModule` discards `args`/`argp`/`flags`/`opt` the same way. Nothing in the tree forwards a module parameter block to a guest module's start routine - the Windows `.ginit` lifecycle hook (`DynamicLoader.cpp`) invokes the lifecycle functions but passes no arguments either. On PS5 the module's entry receives `(args, argp)`, so any title that hands its modules a parameter struct cannot work: the module sees a null block and, in this case, crashes in its own unchecked error path. ### Expected `LoadStartModule` should retain `(args, argp)` for the load it is performing and pass them to the module's start entry (the same entry the `.ginit` lifecycle runs on Windows), and `StopUnloadModule` should pass its pair to the stop entry. The `flags`/`opt` fields likely want at least validation, and `res` should carry the module's own result rather than being pinned to 0. ### Notes - This is separate from #906 (the `.native` wrapper dependency edge), which is what prevents this module from *loading* at all; with that worked around, the module loads and then hits this. - The title's module is not the only possible consumer: any `sceKernelLoadStartModule` call site that passes a non-zero `args` is affected. In this title the parameter block is 16 bytes with a `0x200` version field, i.e. a versioned struct rather than a string or handle. - Happy to prototype the plumbing if you can point at where you would want the start entry invoked (the relinker's guest module writer emits the lifecycle information today, so the argument pair may need to travel from `LoadStartModule` through to that call rather than into `dlopen`).
jeffrey12cali commented 2026-10-06 16:48:32 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T16:48:32Z.


Adding the measurement, since it strengthens the case: the title really does pass a parameter block, and it passes it to exactly the modules that then misbehave. Breakpoint on libs/libkernel.prx+0x54a60 (sceKernelLoadStartModule), reading rsi/rdx at entry:

LOADSTART#1 name='/app0/Media/Modules/PS5Util.prx'              args=0x00  argp=0x0
LOADSTART#2 name='/app0/Media/Modules/Il2CppUserAssemblies.prx' args=0x34  argp=0x200022aa0
LOADSTART#3 name='/app0/Media/Plugins/lib_burst_generated.prx'  args=0x34  argp=0x200022aa0
LOADSTART#4 name='/app0/Media/Plugins/PSN.prx'                  args=0x34  argp=0x200022aa0

So the block is 0x34 bytes (not the 0x10 in my earlier note - that is a nested struct the module validates inside the payload, which is why the helper checks size == 0x10 and version == 0x200), it is the same block for all three modules, and sceKernelLoadStartModule drops it on the floor. The module's start entry therefore sees a null parameter pointer and takes its own "old version / plugin args version" error path, which dereferences it unchecked.

Two notes for whoever picks this up:

  • PS5Util.prx is loaded with args = 0, so the plumbing has to tolerate a genuinely empty parameter block as well - it is not simply "always pass the pointer".
  • I could not find a path in the tree that delivers (args, argp) to a module's start entry on either platform (the Windows .ginit lifecycle hook calls the entry with no arguments either), so this is likely latent on Windows too and only visible here because this title's module validates the block hard. Happy to test a Windows-side build if that helps confirm.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6021078126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6021078126). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T16:48:32Z. --- Adding the measurement, since it strengthens the case: the title really does pass a parameter block, and it passes it to exactly the modules that then misbehave. Breakpoint on `libs/libkernel.prx+0x54a60` (`sceKernelLoadStartModule`), reading `rsi`/`rdx` at entry: ``` LOADSTART#1 name='/app0/Media/Modules/PS5Util.prx' args=0x00 argp=0x0 LOADSTART#2 name='/app0/Media/Modules/Il2CppUserAssemblies.prx' args=0x34 argp=0x200022aa0 LOADSTART#3 name='/app0/Media/Plugins/lib_burst_generated.prx' args=0x34 argp=0x200022aa0 LOADSTART#4 name='/app0/Media/Plugins/PSN.prx' args=0x34 argp=0x200022aa0 ``` So the block is `0x34` bytes (not the `0x10` in my earlier note - that is a nested struct the module validates *inside* the payload, which is why the helper checks `size == 0x10` and `version == 0x200`), it is the same block for all three modules, and `sceKernelLoadStartModule` drops it on the floor. The module's start entry therefore sees a null parameter pointer and takes its own "old version / plugin args version" error path, which dereferences it unchecked. Two notes for whoever picks this up: - `PS5Util.prx` is loaded with `args = 0`, so the plumbing has to tolerate a genuinely empty parameter block as well - it is not simply "always pass the pointer". - I could not find a path in the tree that delivers `(args, argp)` to a module's start entry on either platform (the Windows `.ginit` lifecycle hook calls the entry with no arguments either), so this is likely latent on Windows too and only visible here because this title's module validates the block hard. Happy to test a Windows-side build if that helps confirm.
jeffrey12cali commented 2026-10-06 17:07:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T17:07:23Z.


Two questions, because the fix needs a piece that the conversion currently drops.

1. How should the PRX start entry be surfaced so LoadStartModule can call it with (args, argp)?

I tried to wire the parameter block through on our side and stopped at a hard blocker: the converted module exposes no callable start entry.

check on app0/sce_module/PSN.prx.guest.prx result
e_entry 0x0
section headers none (readelf -S yields nothing)
DT_INIT_ARRAY absent - only DT_INIT = 0xb24c8, DT_FINI = 0xb24d3
DT_INIT target inside the last PT_LOAD (vaddr 0x88000, file 0xb64c8), and disassembles as data, not a prologue

So there is no ELF lifecycle hook that could receive (args, argp) even if LoadStartModule kept them. The relinker clearly sees the real entry - analysis/CodeInstructionCollector.cpp parses PT_PRX (p_type 0x6100003b) and reads an entry field out of it - so the information exists at conversion time. Would you take a relinker change that preserves it (exported symbol at a known name, or a pointer in a section the loader can find), and then have LoadStartModule call it after dlopen? Or do you have a different place in mind for that handoff?

I would rather not guess the entry's calling convention: the module's validator checks a nested size == 0x10 / version == 0x200 struct, so a wrong register layout corrupts guest memory silently instead of failing loudly.

2. Is the discard latent on Windows too?

(void)args; (void)argp; is unconditional, and the Windows .ginit lifecycle path (RunDeferredLifecycle) invokes the lifecycle function with no arguments either - so I expect Windows to hit the same wall, and to be reaching PSN by a different route (its import table rather than LoadStartModule). I am testing that on the win64 build now and will report the result here either way; if Windows really does never reach the validator, then this is a Linux-only-visible bug with a shared cause, which changes how you might want to fix it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6021404049 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6021404049). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T17:07:23Z. --- Two questions, because the fix needs a piece that the conversion currently drops. **1. How should the PRX start entry be surfaced so `LoadStartModule` can call it with `(args, argp)`?** I tried to wire the parameter block through on our side and stopped at a hard blocker: the converted module exposes no callable start entry. | check on `app0/sce_module/PSN.prx.guest.prx` | result | | --- | --- | | `e_entry` | `0x0` | | section headers | none (`readelf -S` yields nothing) | | `DT_INIT_ARRAY` | absent - only `DT_INIT = 0xb24c8`, `DT_FINI = 0xb24d3` | | `DT_INIT` target | inside the last `PT_LOAD` (`vaddr 0x88000`, file `0xb64c8`), and disassembles as data, not a prologue | So there is no ELF lifecycle hook that could receive `(args, argp)` even if `LoadStartModule` kept them. The relinker clearly *sees* the real entry - `analysis/CodeInstructionCollector.cpp` parses `PT_PRX` (`p_type 0x6100003b`) and reads an entry field out of it - so the information exists at conversion time. Would you take a relinker change that preserves it (exported symbol at a known name, or a pointer in a section the loader can find), and then have `LoadStartModule` call it after `dlopen`? Or do you have a different place in mind for that handoff? I would rather not guess the entry's calling convention: the module's validator checks a nested `size == 0x10` / `version == 0x200` struct, so a wrong register layout corrupts guest memory silently instead of failing loudly. **2. Is the discard latent on Windows too?** `(void)args; (void)argp;` is unconditional, and the Windows `.ginit` lifecycle path (`RunDeferredLifecycle`) invokes the lifecycle function with no arguments either - so I expect Windows to hit the same wall, and to be reaching PSN by a different route (its import table rather than `LoadStartModule`). I am testing that on the win64 build now and will report the result here either way; if Windows really does never reach the validator, then this is a Linux-only-visible bug with a shared cause, which changes how you might want to fix it.
jeffrey12cali commented 2026-10-06 17:08:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T17:08:54Z.


Answering my own question 2 from the Windows build of this title (win64 release, same commit as our vendored tree), because it changes what the fix should be.

Windows hits the exact same missing-parameters condition and survives it. Its log:

Loading PRX: ...\app0\sce_module\PSN.prx.guest.prx -> OK
 PSN is an old version that cannot be used by the current player runtime.
 Please update the PSN native module and any associated managed assemblies to the latest versions
  Plugin args version, found 0000, expected 0200
 SaveData2 is an old version that cannot be used by the current player runtime.
  Plugin args version, found 0000, expected 0200
  Plugin args struct size, expected 88 or 16, found 0
[libSceSysmodule/Export.cpp:125 sceSysmoduleLoadModule] unknown id: 272
... continues to boot, reaches in-game

So the parameter block is missing on Windows too (the title's own validator reports found 0000 / found 0), and the game tolerates PSN being unusable - it prints the error and carries on. Nothing about NP has to be implemented to get past this.

The difference is when the validator runs.

Windows Linux
PSN load Loading PRX ... -> OK, returns dlopen never returns - the title faults at PSN+0x3e86 inside the load
validator runs later, with a readable (zeroed) descriptor → prints "found 0000" and returns runs at load time with rsi = 0 → error path dereferences rbx+4 → SIGSEGV

RunDeferredLifecycle calls the .ginit entry as fn(0, 0, 0), so Windows also passes no real arguments - but it reaches the validator through a path where the descriptor pointer is a valid zeroed block, whereas on Linux the same code is reached from the module's load-time init with a null rsi.

That reframes the ask: the problem is not only that LoadStartModule drops (args, argp), but that on Linux the PRX start appears to be wired into the ELF load-time init (DT_INIT), so it executes during dlopen with whatever registers ld.so left, instead of being called by LoadStartModule with the caller's block. Fixing the discard without fixing the timing would still leave the module running its entry with the wrong arguments.

So the question from (1) becomes sharper: where should the PRX entry live in the converted ELF - is it currently being emitted as DT_INIT, and would you rather it be exposed as a named symbol that LoadStartModule calls with (args, argp, flags, opt, res) after dlopen?

Meanwhile the practical consequence for us: this title does not need NP implemented to boot. It needs PSN's start entry to be invoked the way the platform invokes it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6021429729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6021429729). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T17:08:54Z. --- Answering my own question 2 from the Windows build of this title (win64 release, same commit as our vendored tree), because it changes what the fix should be. **Windows hits the exact same missing-parameters condition and survives it.** Its log: ``` Loading PRX: ...\app0\sce_module\PSN.prx.guest.prx -> OK PSN is an old version that cannot be used by the current player runtime. Please update the PSN native module and any associated managed assemblies to the latest versions Plugin args version, found 0000, expected 0200 SaveData2 is an old version that cannot be used by the current player runtime. Plugin args version, found 0000, expected 0200 Plugin args struct size, expected 88 or 16, found 0 [libSceSysmodule/Export.cpp:125 sceSysmoduleLoadModule] unknown id: 272 ... continues to boot, reaches in-game ``` So the parameter block is missing on Windows too (the title's own validator reports `found 0000` / `found 0`), and the game **tolerates PSN being unusable** - it prints the error and carries on. Nothing about NP has to be implemented to get past this. **The difference is when the validator runs.** | | Windows | Linux | | --- | --- | --- | | PSN load | `Loading PRX ... -> OK`, returns | `dlopen` never returns - the title faults at `PSN+0x3e86` *inside* the load | | validator | runs later, with a readable (zeroed) descriptor → prints "found 0000" and returns | runs at load time with `rsi = 0` → error path dereferences `rbx+4` → SIGSEGV | `RunDeferredLifecycle` calls the `.ginit` entry as `fn(0, 0, 0)`, so Windows also passes no real arguments - but it reaches the validator through a path where the descriptor pointer is a valid zeroed block, whereas on Linux the same code is reached from the module's load-time init with a null `rsi`. That reframes the ask: the problem is not only that `LoadStartModule` drops `(args, argp)`, but that on Linux the PRX start appears to be wired into the **ELF load-time init** (`DT_INIT`), so it executes during `dlopen` with whatever registers ld.so left, instead of being called by `LoadStartModule` with the caller's block. Fixing the discard without fixing the *timing* would still leave the module running its entry with the wrong arguments. So the question from (1) becomes sharper: where should the PRX entry live in the converted ELF - is it currently being emitted as `DT_INIT`, and would you rather it be exposed as a named symbol that `LoadStartModule` calls with `(args, argp, flags, opt, res)` after `dlopen`? Meanwhile the practical consequence for us: this title does not need NP implemented to boot. It needs PSN's start entry to be invoked the way the platform invokes it.
jeffrey12cali commented 2026-10-06 18:16:16 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T18:16:16Z.


Correction to my previous comment - I asserted that on Windows "the validator runs later with a readable zeroed descriptor" while Linux gets null. That was an inference from the log text, and it is wrong. Measured directly:

  • The Linux DT_INIT is a relinker-generated trampoline, not module code:
    31 ff 31 f6 31 d2 e9 <rel32> = xor edi,edi; xor esi,esi; xor edx,edx; jmp <start>, and the target is vaddr 0x10.
  • The Windows .ginit entry holds RVA 0x10010 - the same start function (the image base offset accounts for the difference).
  • RunDeferredLifecycle calls it as fn(0, 0, 0), so both platforms pass (0, 0, 0).
  • The first 48 bytes of the start function are byte-identical between the two builds (55 48 89 e5 41 57 41 56 41 55 41 54 53 50 4c 8d 3d ...), and its prologue keeps rdi -> r14, rsi -> rbx, rdx -> r13 - so both enter it with all three null.

So the difference is not the arguments. What I can still stand behind from that comment: LoadStartModule genuinely discards (args, argp) (measured: the title passes a shared 0x34-byte block to three modules), and on Linux the module's start executes inside _dl_init during dlopen (core-dump stack). The Windows-vs-Linux behavioural gap must come from something else - the log line "Plugin args version, found 0000" exists on Windows, so the same validator runs there and returns instead of faulting, which means the null-descriptor error path is not the whole story.

I tried passing a non-null zeroed descriptor by rewriting the 14-byte Linux trampoline in place (xor edi,edi; lea rsi,[rip+zero_block]; jmp start, with the block in the module's zero-filled RW slack). It changed the failure mode rather than fixing it - the run now stops earlier and PSN is not reached at all - so that is not the answer either, and I am dropping that experiment.

Leaving the core ask unchanged: LoadStartModule should deliver (args, argp) to the module start, and the start currently runs during dlopen where no caller arguments can reach it. Those are both real. My explanation of why Windows survives was not.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6022610134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6022610134). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T18:16:16Z. --- **Correction to my previous comment** - I asserted that on Windows "the validator runs later with a readable zeroed descriptor" while Linux gets null. That was an inference from the log text, and it is wrong. Measured directly: - The Linux `DT_INIT` is a relinker-generated trampoline, not module code: `31 ff 31 f6 31 d2 e9 <rel32>` = `xor edi,edi; xor esi,esi; xor edx,edx; jmp <start>`, and the target is vaddr `0x10`. - The Windows `.ginit` entry holds RVA `0x10010` - the **same** start function (the image base offset accounts for the difference). - `RunDeferredLifecycle` calls it as `fn(0, 0, 0)`, so **both platforms pass `(0, 0, 0)`**. - The first 48 bytes of the start function are byte-identical between the two builds (`55 48 89 e5 41 57 41 56 41 55 41 54 53 50 4c 8d 3d ...`), and its prologue keeps `rdi -> r14`, `rsi -> rbx`, `rdx -> r13` - so both enter it with all three null. So the difference is not the arguments. What I can still stand behind from that comment: `LoadStartModule` genuinely discards `(args, argp)` (measured: the title passes a shared `0x34`-byte block to three modules), and on Linux the module's start executes inside `_dl_init` during `dlopen` (core-dump stack). The Windows-vs-Linux behavioural gap must come from something else - the log line "Plugin args version, found 0000" exists on Windows, so the same validator runs there and returns instead of faulting, which means the null-descriptor error path is not the whole story. I tried passing a non-null zeroed descriptor by rewriting the 14-byte Linux trampoline in place (`xor edi,edi; lea rsi,[rip+zero_block]; jmp start`, with the block in the module's zero-filled RW slack). It changed the failure mode rather than fixing it - the run now stops earlier and PSN is not reached at all - so that is not the answer either, and I am dropping that experiment. Leaving the core ask unchanged: `LoadStartModule` should deliver `(args, argp)` to the module start, and the start currently runs during `dlopen` where no caller arguments can reach it. Those are both real. My explanation of *why Windows survives* was not.
jeffrey12cali commented 2026-10-06 18:16:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T18:16:17Z.


Adding the decisive evidence for the "why does Windows survive" part of my correction, since it comes from generated code rather than from log text.

WindowsGuestStartup::callLifecycle (core/relinker/elfpatcher/src/windows/WindowsGuestStartup.cpp) emits the lifecycle invocation as raw bytes:

mov  rax, [rip+handle]        ; module base
mov  rcx, rva                 ; .ginit target
add  rax, rcx
31 ff 31 f6 31 d2 ff d0       ; xor edi,edi ; xor esi,esi ; xor edx,edx ; call rax

That is the same argument setup the relinker emits for the Linux DT_INIT trampoline (31 ff 31 f6 31 d2 e9 rel32), so both platforms enter the module start with all three arguments null - and the start body is byte-identical between the two builds (first 48 bytes at the target match exactly).

So to be precise about what this issue is and is not:

  • Is a real gap: sceKernelLoadStartModule discards (args, argp) that the title demonstrably passes (a shared 0x34-byte block to Il2cppUserAssemblies, lib_burst_generated and PSN; none to PS5Util). Any module that reads its parameter block cannot work.
  • Is not the explanation for the Linux-only fault I was chasing. The difference is elsewhere: the module's start walks a table of function pointers (lea r15,[table] … add r15,8 … mov rax,[r15]; test rax,rax) and the faulting validator has zero direct call sites in the module - it is reachable only through that table. So what differs is the table's contents at the moment the start runs, not the arguments.

Keeping the ask as is: preserve the PRX start entry through conversion and deliver (args, argp) to it. Just not overselling it as the cause of this particular crash.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6022610626 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6022610626). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T18:16:17Z. --- Adding the decisive evidence for the "why does Windows survive" part of my correction, since it comes from generated code rather than from log text. `WindowsGuestStartup::callLifecycle` (`core/relinker/elfpatcher/src/windows/WindowsGuestStartup.cpp`) emits the lifecycle invocation as raw bytes: ``` mov rax, [rip+handle] ; module base mov rcx, rva ; .ginit target add rax, rcx 31 ff 31 f6 31 d2 ff d0 ; xor edi,edi ; xor esi,esi ; xor edx,edx ; call rax ``` That is the same argument setup the relinker emits for the Linux `DT_INIT` trampoline (`31 ff 31 f6 31 d2 e9 rel32`), so both platforms enter the module start with all three arguments null - and the start body is byte-identical between the two builds (first 48 bytes at the target match exactly). So to be precise about what this issue is and is not: - **Is** a real gap: `sceKernelLoadStartModule` discards `(args, argp)` that the title demonstrably passes (a shared `0x34`-byte block to `Il2cppUserAssemblies`, `lib_burst_generated` and `PSN`; none to `PS5Util`). Any module that reads its parameter block cannot work. - **Is not** the explanation for the Linux-only fault I was chasing. The difference is elsewhere: the module's start walks a table of function pointers (`lea r15,[table] … add r15,8 … mov rax,[r15]; test rax,rax`) and the faulting validator has **zero direct call sites** in the module - it is reachable only through that table. So what differs is the table's contents at the moment the start runs, not the arguments. Keeping the ask as is: preserve the PRX start entry through conversion and deliver `(args, argp)` to it. Just not overselling it as the cause of this particular crash.
Dextroid17 commented 2026-10-06 22:50:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-06T22:50:25Z.


Before investing in this: @jeffrey12cali you wrote that you could prototype the plumbing if pointed at the right place — are you still planning to send this as a PR? If so I will stay out. If not, I would like to take it.

For context, I opened #1001 for #948 (the heap finalization ordering). I will leave this one alone until you answer.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6026885222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6026885222). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-06T22:50:25Z. --- Before investing in this: @jeffrey12cali you wrote that you could prototype the plumbing if pointed at the right place — are you still planning to send this as a PR? If so I will stay out. If not, I would like to take it. For context, I opened #1001 for #948 (the heap finalization ordering). I will leave this one alone until you answer.
jeffrey12cali commented 2026-10-06 23:08:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T23:08:59Z.


Yes, I am taking this one — please don't spend your time on it, and thank you for asking before starting.

What I can hand over immediately, measured on PPSA28997 through the native Linux relink path:

  • The title calls sceKernelLoadStartModule with args=0x34 and argp=0x200022aa0 for three of its own modules (Il2cppUserAssemblies.prx, lib_burst_generated.prx, PSN.prx); the fourth (PS5Util.prx) gets args=0. All three share the one 0x34-byte block. Both args and argp are discarded today ((void)args; (void)argp;).
  • #846 already carries this plumbing on the Windows side — InitializeDeferredModule reads __aps5_guest_initialize with GetProcAddress and calls it with (args, argp, nullptr). That half is Windows-only (HMODULE, GetProcAddress), so the Linux half is genuinely free, and I would rather converge on the same exported name than invent a second one.

The shape I plan to send: the relinker's Linux writer exports the module's initialisation entry as __aps5_guest_initialize and stops letting DT_INIT run it, so the loader can pass arguments; sceKernelLoadStartModule looks the symbol up, calls it with args/argp and stores the result in *res, falling back to the current DT_INIT behaviour when the symbol is absent so modules that only ever used DT_INIT keep working.

Why it matters for this title: its PSN module validates that parameter block in its start-up path and, with nothing delivered, faults on a null descriptor (rip = PSN+0x3ee7, rbx = 0). The Windows target of the same toolchain prints Plugin args version, found 0000, expected 0200 from the same code and continues — so delivering the block is what turns a fault into a handled error. I do not need the online subsystem to work, only to fail the way the reference does.

I will post the PR here with a test that fails on main. If you have already started, say so and I will rebase onto yours instead.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027105360 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6027105360). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T23:08:59Z. --- Yes, I am taking this one — please don't spend your time on it, and thank you for asking before starting. What I can hand over immediately, measured on PPSA28997 through the native Linux relink path: - The title calls `sceKernelLoadStartModule` with `args=0x34` and `argp=0x200022aa0` for three of its own modules (`Il2cppUserAssemblies.prx`, `lib_burst_generated.prx`, `PSN.prx`); the fourth (`PS5Util.prx`) gets `args=0`. All three share the one 0x34-byte block. Both `args` and `argp` are discarded today (`(void)args; (void)argp;`). - #846 already carries this plumbing on the Windows side — `InitializeDeferredModule` reads `__aps5_guest_initialize` with `GetProcAddress` and calls it with `(args, argp, nullptr)`. That half is Windows-only (`HMODULE`, `GetProcAddress`), so the Linux half is genuinely free, and I would rather converge on the same exported name than invent a second one. The shape I plan to send: the relinker's Linux writer exports the module's initialisation entry as `__aps5_guest_initialize` and stops letting `DT_INIT` run it, so the loader can pass arguments; `sceKernelLoadStartModule` looks the symbol up, calls it with `args`/`argp` and stores the result in `*res`, falling back to the current `DT_INIT` behaviour when the symbol is absent so modules that only ever used `DT_INIT` keep working. Why it matters for this title: its `PSN` module validates that parameter block in its start-up path and, with nothing delivered, faults on a null descriptor (`rip = PSN+0x3ee7`, `rbx = 0`). The Windows target of the same toolchain prints `Plugin args version, found 0000, expected 0200` from the same code and continues — so delivering the block is what turns a fault into a handled error. I do not need the online subsystem to work, only to fail the way the reference does. I will post the PR here with a test that fails on `main`. If you have already started, say so and I will rebase onto yours instead.
jeffrey12cali commented 2026-10-07 09:35:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T09:35:06Z.


Progress note on the PR I said I would send, plus proof that the missing arguments are fatal rather than cosmetic - on a second, independent module.

Making the three deferred modules start-up dependencies here produced a one-second, pre-main segfault instead of a slow stall. From the core, with the PC attributed through the core's own mappings:

#0  SaveData.prx.guest.prx+0xd0a      rdi=0  rsi=0  rdx=<inside SaveData>  rbx=<unmapped>  rax=-1

4d0a:  mov (%rsi),%eax     ; the block's own size field - rsi is argp, which is NULL
4d0c:  cmp $0x10,%edi      ; args >= 0x10 ?
4d18:  cmp $0x10,%eax      ; *argp == 0x10 ?

So SaveData dereferences argp as the first thing its start-up path does, with the same size >= 0x10 / *argp == 0x10 validation I had already mapped inside PSN (PSN+0x3ee7, rbx = 0). Two modules, same contract.

The zeroing is ours, not the title's. core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp synthesizes the initialisation trampoline:

const auto lifecycle = [&](std::uint64_t target) {
    if (target == 0) return std::uint64_t{};
    bytes.insert(bytes.end(), {0x31, 0xff, 0x31, 0xf6, 0x31, 0xd2, 0xe9});   // xor edi, esi, edx; jmp
    ...displacement to target...
};
const auto init = lifecycle(image.Init);

so on Linux DT_INIT is built to clear args/argp before jumping to the guest entry point. WindowsGuestStartup.cpp has the counterpart, and #846 turns that one into an exported __aps5_guest_initialize called with the arguments - Windows only.

The plan for the Linux half, which I would like to keep naming-compatible with #846:

  1. libkernel holds a pending (args, argp) pair; sceKernelLoadStartModule sets it under a lock before dlopen, clears it after, and writes the module's returned status to *res.
  2. One accessor exported from libkernel returning that pair, added to the NID patcher's exclusion list so the rename step leaves the plain name alone.
  3. lifecycle() above emits call <accessor> then mov rdi,rax / mov rsi,rdx / xor edx,edx before the existing jmp - one extra undefined symbol and one R_X86_64_JUMP_SLOT, inside the .dynsym/.hash/RelaData machinery the writer already builds.
  4. Startup loads (modules in the executable's own DT_NEEDED) keep getting (0,0), because that is what both platforms already do for them and it is demonstrably survivable there.

Two notes for anyone reading before the PR lands. First, eager loading is not a workaround: with these modules in DT_NEEDED nobody has called sceKernelLoadStartModule yet, so there is no pending pair to deliver and the same trampoline faults - which is why the launcher's defer list exists. Second, on this title the practical stakes are large: the game blocks retrying PSN's load, so until args/argp arrive (or the module can be made to fail cleanly the way the Windows branch does), the title never reaches its controller or save-data work.

@Dextroid17 if #846 introduces a name for the pending-arguments accessor, tell me and I will use it instead of inventing one, so the two platforms converge on one convention rather than two.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6035175628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6035175628). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T09:35:06Z. --- Progress note on the PR I said I would send, plus proof that the missing arguments are fatal rather than cosmetic - on a second, independent module. Making the three deferred modules start-up dependencies here produced a one-second, pre-`main` segfault instead of a slow stall. From the core, with the PC attributed through the core's own mappings: ``` #0 SaveData.prx.guest.prx+0xd0a rdi=0 rsi=0 rdx=<inside SaveData> rbx=<unmapped> rax=-1 4d0a: mov (%rsi),%eax ; the block's own size field - rsi is argp, which is NULL 4d0c: cmp $0x10,%edi ; args >= 0x10 ? 4d18: cmp $0x10,%eax ; *argp == 0x10 ? ``` So `SaveData` dereferences `argp` as the first thing its start-up path does, with the same `size >= 0x10` / `*argp == 0x10` validation I had already mapped inside `PSN` (`PSN+0x3ee7`, `rbx = 0`). Two modules, same contract. The zeroing is ours, not the title's. `core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp` synthesizes the initialisation trampoline: ```cpp const auto lifecycle = [&](std::uint64_t target) { if (target == 0) return std::uint64_t{}; bytes.insert(bytes.end(), {0x31, 0xff, 0x31, 0xf6, 0x31, 0xd2, 0xe9}); // xor edi, esi, edx; jmp ...displacement to target... }; const auto init = lifecycle(image.Init); ``` so on Linux `DT_INIT` is *built* to clear `args`/`argp` before jumping to the guest entry point. `WindowsGuestStartup.cpp` has the counterpart, and #846 turns that one into an exported `__aps5_guest_initialize` called with the arguments - Windows only. The plan for the Linux half, which I would like to keep naming-compatible with #846: 1. `libkernel` holds a pending `(args, argp)` pair; `sceKernelLoadStartModule` sets it under a lock before `dlopen`, clears it after, and writes the module's returned status to `*res`. 2. One accessor exported from `libkernel` returning that pair, added to the NID patcher's exclusion list so the rename step leaves the plain name alone. 3. `lifecycle()` above emits `call <accessor>` then `mov rdi,rax` / `mov rsi,rdx` / `xor edx,edx` before the existing `jmp` - one extra undefined symbol and one `R_X86_64_JUMP_SLOT`, inside the `.dynsym`/`.hash`/`RelaData` machinery the writer already builds. 4. Startup loads (modules in the executable's own `DT_NEEDED`) keep getting `(0,0)`, because that is what both platforms already do for them and it is demonstrably survivable there. Two notes for anyone reading before the PR lands. First, *eager loading is not a workaround*: with these modules in `DT_NEEDED` nobody has called `sceKernelLoadStartModule` yet, so there is no pending pair to deliver and the same trampoline faults - which is why the launcher's defer list exists. Second, on this title the practical stakes are large: the game blocks retrying `PSN`'s load, so until `args`/`argp` arrive (or the module can be made to fail cleanly the way the Windows branch does), the title never reaches its controller or save-data work. @Dextroid17 if #846 introduces a name for the pending-arguments accessor, tell me and I will use it instead of inventing one, so the two platforms converge on one convention rather than two.
jeffrey12cali commented 2026-10-07 11:24:53 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T11:24:53Z.


Sent as #1102 with the measurements from this thread. Summary of the shape (my previous comment lost its code formatting to the shell, so restating it properly):

  • sceKernelLoadStartModule parks {args, argp} under a mutex before dlopen and clears it afterwards, and reports the initializer's return value through *res instead of leaving it at 0.
  • The Linux guest writer's DT_INIT/DT_FINI stub no longer clears edi/esi/edx. It reads the parked pair through two accessors exported by libkernel, then calls the module's real initializer so its return value is observable.
  • Startup-loaded modules keep receiving (0, 0), which is what both platforms do for them today.
  • The accessor names carry _nid_no_patch, as CONTRIBUTING.md prescribes for helper symbols that must not become NIDs - without the suffix ResolveNids hashes the export into a NID name and the guest's plain-name import cannot resolve. That is what happened on the first attempt here.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6036903441 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6036903441). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T11:24:53Z. --- Sent as [#1102](https://github.com/boykopovar/AnyPS5/pull/1102) with the measurements from this thread. Summary of the shape (my previous comment lost its code formatting to the shell, so restating it properly): - `sceKernelLoadStartModule` parks `{args, argp}` under a mutex before `dlopen` and clears it afterwards, and reports the initializer's return value through `*res` instead of leaving it at 0. - The Linux guest writer's `DT_INIT`/`DT_FINI` stub no longer clears `edi`/`esi`/`edx`. It reads the parked pair through two accessors exported by libkernel, then `call`s the module's real initializer so its return value is observable. - Startup-loaded modules keep receiving `(0, 0)`, which is what both platforms do for them today. - The accessor names carry `_nid_no_patch`, as `CONTRIBUTING.md` prescribes for helper symbols that must not become NIDs - without the suffix `ResolveNids` hashes the export into a NID name and the guest's plain-name import cannot resolve. That is what happened on the first attempt here.
oneandonlydean commented 2026-10-10 03:07:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:07:41Z.


Fixed by #1102: sceKernelLoadStartModule now hands args/argp to the module initialiser on Linux and returns its result in res. sceKernelStopUnloadModule still drops its pair; open a new issue if a title needs that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093144289 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6093144289). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:07:41Z. --- Fixed by #1102: `sceKernelLoadStartModule` now hands `args`/`argp` to the module initialiser on Linux and returns its result in `res`. `sceKernelStopUnloadModule` still drops its pair; open a new issue if a title needs that.
jeffrey12cali commented 2026-10-10 11:02:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-10T11:02:57Z.


Confirming the load side for a second title: PPSA28997 reaches its main menu with the parameter block
passed, and the guest_module_args test in #1102 is the regression we were missing.

On sceKernelStopUnloadModule, I have to be explicit that we have not measured it. I looked for the call in
our run log first, found nothing, and discarded that result: sceKernelLoadStartModule is equally absent from
the same log, and this title certainly calls it. The module lifecycle entry points are not traced in our
build, and the guest modules import by NID rather than by name, so a string scan of the module binaries does
not answer it either. We therefore cannot say whether this title needs the stop side, and I am not opening an
issue on that basis. If a title is ever observed unloading a module, we will file it with the call evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096820268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/918#issuecomment-6096820268). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-10T11:02:57Z. --- Confirming the load side for a second title: `PPSA28997` reaches its main menu with the parameter block passed, and the `guest_module_args` test in #1102 is the regression we were missing. On `sceKernelStopUnloadModule`, I have to be explicit that we have not measured it. I looked for the call in our run log first, found nothing, and discarded that result: `sceKernelLoadStartModule` is equally absent from the same log, and this title certainly calls it. The module lifecycle entry points are not traced in our build, and the guest modules import by NID rather than by name, so a string scan of the module binaries does not answer it either. We therefore cannot say whether this title needs the stop side, and I am not opening an issue on that basis. If a title is ever observed unloading a module, we will file it with the call evidence.
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#918
No description provided.