fix(libkernel): pass the first module arguments block to zero-argument sceKernelLoadStartModule calls #4296

Closed
eliyarson wants to merge 3 commits from upstream-pr/4296 into main
eliyarson commented 2026-10-12 05:09:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliyarson on 2026-10-12T05:09:31Z.


What

sceKernelLoadStartModule called with args 0 and argp null now passes the first block that any call gave with a non-zero args and a non-null argp (same pointer and size, not a copy, from any thread). A block that lies on the calling thread's stack is not remembered. The behaviour is recorded in TechnicalDebt.

Three commits, kept separate for review (squash on merge is fine):

  1. the fix, with a test (guest_load_start_module_args) and a fixture module;
  2. test: drop explanatory comments;
  3. do not remember a block on the calling thread's stack.

Fixes #4225. Blasphemous 2 (PPSA13579) loads PSNCore.prx from its Il2CppUserAssemblies wrapper with hard-coded zeros. PSNCore's start reads a {0x10, 0x200, ptr} block, the one the engine passes when it loads Il2CppUserAssemblies, and without it prints "PSNCore is an old version that cannot be used by the current player runtime" and dereferences the null pointer. The engine fills the block only after the Il2CppUserAssemblies load, so a copy taken at that load is all zeros: PSNCore then still prints "found 0000" and runs without the engine's interface.

Related: #918 (same PSNCore validator; that title passes a block), #1102 and #3492 (pass a load's own args/argp on Linux and macOS). None covers (0, NULL) loads. Module.cpp is also edited by #4193 and #4219 (other functions; textual overlap only).

What the console passes to a module started with zeros is not verified; this is a heuristic that reproduces what the title needs, listed in TechnicalDebt. Known limits: every later zero-argument load in the process gets the block (including libfmod and libfmodstudio), and it assumes the block outlives the module loads (the engine callocs it once and keeps the pointer in a global).

Tested

Linux (CachyOS, Release, -j24), based on origin/main d146ec1b6:

  • python3 tools/check_conventions.py --base origin/main: all checks passed
  • python3 tools/check_test_registration.py build: 697 test executables, 0 built and not run as recorded
  • ctest -R 'guest_load_start_module_args|guest_module_args|guest_dynamic_loader|guest_module_info': 4/4 passed
  • ctest -R 'libkernel|kernel|guest_': 301 tests, 0 failed, 3 skipped (guest_video_out_*)
  • Blasphemous 2 (PPSA13579), with #3295 applied (title app.elf relinked by an earlier build; libraries from this branch): 3 runs of 240 s each, all ended by the timeout, no "old version" line, no SIGSEGV or abort, title screen ("Press ✕ to continue") at 59.94 FPS. Without #3295, 1 run passed the point where PSNCore starts (no "old version" line) and crashed after about 9 s during asset bundle loading, a separate bug (#4223, fixed by #3295).

Windows and macOS: not built or run here. The new test is registered only outside Windows (if(NOT WIN32) in core/libs/prx/libkernel/CMakeLists.txt): on Windows the fixture would have to link libkernel and export __aps5_get_pending_module_args_nid_no_patch, as guest_module_fixture does, and I could not build or verify that. The Windows CI run will compile the GetCurrentThreadStackLimits branch, but nothing here tests it. The macOS branch (pthread_get_stackaddr_np) is likewise unbuilt. The stack query duplicates the one in Pthread/src/Thread.cpp, and a failed query treats the block as not on the stack.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt (none added)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none added)
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title: no. The rule names no title and applies to every zero-argument load, but it comes from PPSA13579 alone and the console behaviour is unverified (recorded in TechnicalDebt).
  • Depends on: none (#3295 is needed separately for the title to reach its title screen)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4825181789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4296). Originally posted by [eliyarson](https://github.com/eliyarson) on 2026-10-12T05:09:31Z. --- ### What `sceKernelLoadStartModule` called with `args` 0 and `argp` null now passes the first block that any call gave with a non-zero `args` and a non-null `argp` (same pointer and size, not a copy, from any thread). A block that lies on the calling thread's stack is not remembered. The behaviour is recorded in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md). Three commits, kept separate for review (squash on merge is fine): 1. the fix, with a test (`guest_load_start_module_args`) and a fixture module; 2. test: drop explanatory comments; 3. do not remember a block on the calling thread's stack. Fixes #4225. Blasphemous 2 (PPSA13579) loads `PSNCore.prx` from its Il2CppUserAssemblies wrapper with hard-coded zeros. `PSNCore`'s start reads a `{0x10, 0x200, ptr}` block, the one the engine passes when it loads Il2CppUserAssemblies, and without it prints "PSNCore is an old version that cannot be used by the current player runtime" and dereferences the null pointer. The engine fills the block only after the Il2CppUserAssemblies load, so a copy taken at that load is all zeros: PSNCore then still prints "found 0000" and runs without the engine's interface. Related: #918 (same PSNCore validator; that title passes a block), #1102 and #3492 (pass a load's own `args`/`argp` on Linux and macOS). None covers `(0, NULL)` loads. Module.cpp is also edited by #4193 and #4219 (other functions; textual overlap only). What the console passes to a module started with zeros is not verified; this is a heuristic that reproduces what the title needs, listed in TechnicalDebt. Known limits: every later zero-argument load in the process gets the block (including `libfmod` and `libfmodstudio`), and it assumes the block outlives the module loads (the engine `calloc`s it once and keeps the pointer in a global). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> Linux (CachyOS, Release, `-j24`), based on `origin/main` d146ec1b6: - `python3 tools/check_conventions.py --base origin/main`: all checks passed - `python3 tools/check_test_registration.py build`: 697 test executables, 0 built and not run as recorded - `ctest -R 'guest_load_start_module_args|guest_module_args|guest_dynamic_loader|guest_module_info'`: 4/4 passed - `ctest -R 'libkernel|kernel|guest_'`: 301 tests, 0 failed, 3 skipped (`guest_video_out_*`) - Blasphemous 2 (PPSA13579), with #3295 applied (title `app.elf` relinked by an earlier build; libraries from this branch): 3 runs of 240 s each, all ended by the timeout, no "old version" line, no SIGSEGV or abort, title screen ("Press ✕ to continue") at 59.94 FPS. Without #3295, 1 run passed the point where PSNCore starts (no "old version" line) and crashed after about 9 s during asset bundle loading, a separate bug (#4223, fixed by #3295). Windows and macOS: not built or run here. The new test is registered only outside Windows (`if(NOT WIN32)` in `core/libs/prx/libkernel/CMakeLists.txt`): on Windows the fixture would have to link libkernel and export `__aps5_get_pending_module_args_nid_no_patch`, as `guest_module_fixture` does, and I could not build or verify that. The Windows CI run will compile the `GetCurrentThreadStackLimits` branch, but nothing here tests it. The macOS branch (`pthread_get_stackaddr_np`) is likewise unbuilt. The stack query duplicates the one in `Pthread/src/Thread.cpp`, and a failed query treats the block as not on the stack. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (none added) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (none added) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (none added) - [ ] Generic behaviour, not specific to one title: no. The rule names no title and applies to every zero-argument load, but it comes from PPSA13579 alone and the console behaviour is unverified (recorded in TechnicalDebt). - [x] Depends on: none (#3295 is needed separately for the title to reach its title screen) - [x] AI-assisted: yes
eliyarson commented 2026-10-12 05:13:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliyarson on 2026-10-12T05:13:19Z.


Converting to draft. The checklist item "Generic behaviour, not specific to one title" can't be ticked honestly: replaying an earlier call's block to zero-argument loads comes from PPSA13579 alone, and libkernel normally hands module_start only the caller's own args/argp.

There is a more likely root cause to check first. In PPSA28997 (#918) the Unity engine loads Plugins/*.prx itself with the 0x34 block right after Il2CppUserAssemblies. In PPSA13579 the engine never preloads any plugin, and our traces show no directory listing of /app0/Media/Plugins at all, so only the il2cpp wrapper's zero-argument PSNCore load is left. If the engine skips the preload because of something AnyPS5 answers differently from the console, the generic fix belongs there. I'll report back on #4225; the test and analysis here stay for reference.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118178836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4296#issuecomment-6118178836). Originally posted by [eliyarson](https://github.com/eliyarson) on 2026-10-12T05:13:19Z. --- Converting to draft. The checklist item "Generic behaviour, not specific to one title" can't be ticked honestly: replaying an earlier call's block to zero-argument loads comes from PPSA13579 alone, and libkernel normally hands `module_start` only the caller's own `args`/`argp`. There is a more likely root cause to check first. In PPSA28997 (#918) the Unity engine loads `Plugins/*.prx` itself with the 0x34 block right after `Il2CppUserAssemblies`. In PPSA13579 the engine never preloads any plugin, and our traces show no directory listing of `/app0/Media/Plugins` at all, so only the il2cpp wrapper's zero-argument `PSNCore` load is left. If the engine skips the preload because of something AnyPS5 answers differently from the console, the generic fix belongs there. I'll report back on #4225; the test and analysis here stay for reference.
MarcZX10 commented 2026-10-12 07:20:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T07:20:28Z.


I checked the current implementation at Module.cpp: each sceKernelLoadStartModule call sets pendingModuleArgs = {args, argp} immediately before dlopen, so module_start receives the current call’s arguments. This patch changes every subsequent (0, nullptr) load in the process to reuse the first earlier block, including unrelated modules, and the issue report says the console behavior is unknown. The title run demonstrates that this workaround reaches farther, but does not establish that the host should propagate arguments this way. I agree with keeping this draft until there is console/call-site evidence for the rule, or a narrower behavior supported by a general contract. The current test proves the proposed heuristic, not console compatibility.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119623968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4296#issuecomment-6119623968). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T07:20:28Z. --- I checked the current implementation at `Module.cpp`: each `sceKernelLoadStartModule` call sets `pendingModuleArgs = {args, argp}` immediately before `dlopen`, so `module_start` receives the current call’s arguments. This patch changes every subsequent `(0, nullptr)` load in the process to reuse the first earlier block, including unrelated modules, and the issue report says the console behavior is unknown. The title run demonstrates that this workaround reaches farther, but does not establish that the host should propagate arguments this way. I agree with keeping this draft until there is console/call-site evidence for the rule, or a narrower behavior supported by a general contract. The current test proves the proposed heuristic, not console compatibility.
blawesom commented 2026-10-12 15:41:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T15:41:45Z.


Rebase handoff — rebased onto current main, authorship unchanged (all three commits).

Two TechnicalDebt.md conflicts, resolved by keeping main's adjacent entries plus this PR's entry in its refined final form (the second commit's version, with the stack-block clarification sentence).

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 958/958 passed

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4296
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 2a5c6182c.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6127579309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4296#issuecomment-6127579309). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T15:41:45Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged (all three commits). Two `TechnicalDebt.md` conflicts, resolved by keeping main's adjacent entries plus this PR's entry in its **refined final form** (the second commit's version, with the stack-block clarification sentence). Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 958/958 passed** **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4296 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `2a5c6182c`.
ducloc080202 commented 2026-10-12 15:54:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ducloc080202 on 2026-10-12T15:54:48Z.


Windows verification of the fix (the first one, as far as I can tell).

Environment. Windows 11, RTX 3050 Laptop (driver 617.42), WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, a full local build. I applied only the Module.cpp change from this PR (ResolveModuleArgs + IsOnCurrentThreadStack, including the _WIN32 GetCurrentThreadStackLimits branch) onto current main, rebuilt libkernel, re-ran the NID patcher, and ran a relinked commercial Unity title.

Title. Cat Quest III (PPSA15065, Unity IL2CPP, contentVersion 01.000.001). Its bundled modules (sce_module/libc.prx, Media/Modules/*.prx, Media/Plugins/{PSN,SaveData,lib_burst_generated}.prx) were unwrapped from SELF/fSELF and relinked with --module-dir Media/Plugins --module-dir Media/Modules.

Before the change (current main): deterministic 0xC0000005 (read of 0x4) inside the title's own PSN.prx.guest.prx+0x13f37, immediately after it prints PSN is an old version that cannot be used by the current player runtime. — 2 of 2 runs.

After the change: the old version line is gone. The title gets past PSN init and runs further (shader-disk-cache 56 hits / 18 misses, sce::Agc::suspendPoint), then stops on a different, separate crash: 0xC0000005 (write of 0x0) on thread Loading.PreloadManager in app.exe+0x7dfecb. That is the shape of #3805 (Hotline Miami, Loading.PreloadManager, null data pointer) and is unrelated to module arguments.

Same mechanism as #4225 (the il2cpp wrapper loads the bundled PSN module with (0, NULL)); on this title the plugin is PSN.prx rather than PSNCore.prx, and, like PPSA13579, the engine never lists /app0/Media/Plugins. I left the same reproduction on #4225. This confirms the effect on Windows and exercises the GetCurrentThreadStackLimits branch, which the new test (registered only outside Windows) does not.

I did not port the unit test to Windows. I can try — linking the fixture to libkernel and exporting __aps5_get_pending_module_args_nid_no_patch the way guest_module_fixture does — if that would be useful here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6127794379 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4296#issuecomment-6127794379). Originally posted by [ducloc080202](https://github.com/ducloc080202) on 2026-10-12T15:54:48Z. --- Windows verification of the fix (the first one, as far as I can tell). **Environment.** Windows 11, RTX 3050 Laptop (driver 617.42), WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, a full local build. I applied only the `Module.cpp` change from this PR (`ResolveModuleArgs` + `IsOnCurrentThreadStack`, including the `_WIN32` `GetCurrentThreadStackLimits` branch) onto current `main`, rebuilt `libkernel`, re-ran the NID patcher, and ran a relinked commercial Unity title. **Title.** Cat Quest III (PPSA15065, Unity IL2CPP, `contentVersion` 01.000.001). Its bundled modules (`sce_module/libc.prx`, `Media/Modules/*.prx`, `Media/Plugins/{PSN,SaveData,lib_burst_generated}.prx`) were unwrapped from SELF/fSELF and relinked with `--module-dir Media/Plugins --module-dir Media/Modules`. **Before the change** (current `main`): deterministic `0xC0000005` (read of `0x4`) inside the title's own `PSN.prx.guest.prx+0x13f37`, immediately after it prints `PSN is an old version that cannot be used by the current player runtime.` — 2 of 2 runs. **After the change:** the `old version` line is gone. The title gets past PSN init and runs further (`shader-disk-cache` 56 hits / 18 misses, `sce::Agc::suspendPoint`), then stops on a different, separate crash: `0xC0000005` (write of `0x0`) on thread `Loading.PreloadManager` in `app.exe+0x7dfecb`. That is the shape of #3805 (Hotline Miami, `Loading.PreloadManager`, null data pointer) and is unrelated to module arguments. Same mechanism as #4225 (the il2cpp wrapper loads the bundled PSN module with `(0, NULL)`); on this title the plugin is `PSN.prx` rather than `PSNCore.prx`, and, like PPSA13579, the engine never lists `/app0/Media/Plugins`. I left the same reproduction on #4225. This confirms the effect on Windows and exercises the `GetCurrentThreadStackLimits` branch, which the new test (registered only outside Windows) does not. I did not port the unit test to Windows. I can try — linking the fixture to libkernel and exporting `__aps5_get_pending_module_args_nid_no_patch` the way `guest_module_fixture` does — if that would be useful here.

Pull request closed

Sign in to join this conversation.
No reviewers
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!4296
No description provided.