fix(libkernel): resolve original .prx names to relinked .guest.prx in stat, open and reachability #4688

Merged
eliyarson merged 1 commit from upstream-pr/4688 into main 2026-10-13 04:48:42 +00:00
eliyarson commented 2026-10-12 19:03:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliyarson on 2026-10-12T19:03:03Z.


What

Refs #4225.

Titles that ship a plugin check for it with sceKernelStat before loading it. The relinker emits only <name>.prx.guest.prx, so sceKernelStat("/app0/Media/Plugins/PSNCore.prx") returned ENOENT, while dlopen already maps X to X.guest.prx. Blasphemous 2 (PPSA13579): the il2cpp find-plugin callback (eboot 0xa46860) stats the plugin and only on success takes the engine load path that passes the {0x10, 0x200, getInterface} block to sceKernelLoadStartModule. After the failed stat the title falls back to a bare sceKernelLoadStartModule(path, 0, NULL), PSNCore's module_start rejects the missing block ("PSNCore is an old version") and dereferences NULL.

This moves the X -> X.guest.prx rule out of dlopen into one helper, RelinkedModulePath_nid_no_patch (libc, next to ResolvePath_nid_no_patch). libkernel wraps it as File::PathOrRelinkedModule, which keeps X when it exists (including a dangling symlink) and otherwise returns X.guest.prx if that file exists. dlopen, sceKernelStat (and stat), read-only sceKernelOpen and sceKernelCheckReachability use it. Open with write or O_CREAT is unchanged. No module arguments are replayed.

Alternative to my draft #4296 (module-argument replay), which this makes unnecessary for PPSA13579; I will close #4296 once this is merged.

Not covered, behaviour unchanged: lstat, access, directory listings.

Tested

Linux x86-64 (Release), Blasphemous 2 PPSA13579 relinked with the stock relinker, app0/Media/Plugins holding only *.prx.guest.prx, no symlinks, #4296 not applied.

  • Unit test TestRelinkedModuleNames in GuestFilesystem.cpp fails without the change (aborts at the first relinked stat, GuestFilesystem.cpp:188) and passes with it.
  • Full ctest -j4 --timeout 120 on the branch rebased onto 1acfa7f78 (the final rebase onto a60f52e31 only adds workflow and CONTRIBUTING changes): 971 tests, 0 failures, 10 skipped (no display); check_skips.py (10 skips, all expected), check_test_registration.py (730 executables, none new) and check_conventions.py --base origin/main --head HEAD pass. Not run: Windows and macOS builds.
  • Title: stat of Plugins/PSNCore.prx now returns 0, the engine load site is reached, no "old version" message. On main plus this change alone the title then crashes with SIGSEGV (eboot 0x4430ae, core::string::reserve) while loading Addressables bundles, 2 of 2 runs: this is the guest sceKernelClose(0) / host fd 0 reuse fixed by #3295 (and also hit with #4296 alone). With #3295 added locally, 2 runs of 240 s hold the title screen at ~59.9 FPS with no crash. Only the title screen was checked, no input sent.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA13579 #4687 (past the PSNCore failure; the title also needs #3295 to survive bundle loading)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833798882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4688). Originally posted by [eliyarson](https://github.com/eliyarson) on 2026-10-12T19:03:03Z. --- ### What Refs #4225. Titles that ship a plugin check for it with `sceKernelStat` before loading it. The relinker emits only `<name>.prx.guest.prx`, so `sceKernelStat("/app0/Media/Plugins/PSNCore.prx")` returned ENOENT, while `dlopen` already maps `X` to `X.guest.prx`. Blasphemous 2 (PPSA13579): the il2cpp find-plugin callback (eboot 0xa46860) stats the plugin and only on success takes the engine load path that passes the `{0x10, 0x200, getInterface}` block to `sceKernelLoadStartModule`. After the failed stat the title falls back to a bare `sceKernelLoadStartModule(path, 0, NULL)`, PSNCore's `module_start` rejects the missing block ("PSNCore is an old version") and dereferences NULL. This moves the `X -> X.guest.prx` rule out of `dlopen` into one helper, `RelinkedModulePath_nid_no_patch` (libc, next to `ResolvePath_nid_no_patch`). libkernel wraps it as `File::PathOrRelinkedModule`, which keeps `X` when it exists (including a dangling symlink) and otherwise returns `X.guest.prx` if that file exists. `dlopen`, `sceKernelStat` (and `stat`), read-only `sceKernelOpen` and `sceKernelCheckReachability` use it. Open with write or `O_CREAT` is unchanged. No module arguments are replayed. Alternative to my draft #4296 (module-argument replay), which this makes unnecessary for PPSA13579; I will close #4296 once this is merged. Not covered, behaviour unchanged: `lstat`, `access`, directory listings. ### Tested Linux x86-64 (Release), Blasphemous 2 PPSA13579 relinked with the stock relinker, `app0/Media/Plugins` holding only `*.prx.guest.prx`, no symlinks, #4296 not applied. - Unit test `TestRelinkedModuleNames` in `GuestFilesystem.cpp` fails without the change (aborts at the first relinked stat, `GuestFilesystem.cpp:188`) and passes with it. - Full `ctest -j4 --timeout 120` on the branch rebased onto 1acfa7f78 (the final rebase onto a60f52e31 only adds workflow and CONTRIBUTING changes): 971 tests, 0 failures, 10 skipped (no display); `check_skips.py` (10 skips, all expected), `check_test_registration.py` (730 executables, none new) and `check_conventions.py --base origin/main --head HEAD` pass. Not run: Windows and macOS builds. - Title: stat of `Plugins/PSNCore.prx` now returns 0, the engine load site is reached, no "old version" message. On `main` plus this change alone the title then crashes with SIGSEGV (eboot 0x4430ae, `core::string::reserve`) while loading Addressables bundles, 2 of 2 runs: this is the guest `sceKernelClose(0)` / host fd 0 reuse fixed by #3295 (and also hit with #4296 alone). With #3295 added locally, 2 runs of 240 s hold the title screen at ~59.9 FPS with no crash. Only the title screen was checked, no input sent. ### Checklist - [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) - [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) - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA13579 #4687 (past the PSNCore failure; the title also needs #3295 to survive bundle loading) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-12 19:10:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:10:25Z.

Code review location: core/libs/prx/libkernel/File/src/NativeStat.cpp; line 131

@@ -125,6 +125,12 @@ static void CopyNativeStat(const NativeStat& st, FileStat* sb) {
 
 namespace File {
 
+std::filesystem::path PathOrRelinkedModule(const std::filesystem::path& nativePath) {
+    std::error_code error;
+    if (std::filesystem::exists(std::filesystem::symlink_status(nativePath, error))) return nativePath;
+    return RelinkedModulePath_nid_no_patch(nativePath);

std::filesystem::exists(file_status) is false when file_status is not_found, which is what symlink_status returns for a dangling symlink. That means a dangling original path is not preserved here as the PR description says; if a sibling <path>.guest.prx exists, stat/open/reachability will be redirected to it. Could this test the symlink_status type (or otherwise preserve every existing directory entry) and add a regression with a dangling original symlink plus a relinked sibling?

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251483585 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4688#discussion_r4251483585). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:10:25Z. **Code review location:** `core/libs/prx/libkernel/File/src/NativeStat.cpp`; line 131 ~~~~diff @@ -125,6 +125,12 @@ static void CopyNativeStat(const NativeStat& st, FileStat* sb) { namespace File { +std::filesystem::path PathOrRelinkedModule(const std::filesystem::path& nativePath) { + std::error_code error; + if (std::filesystem::exists(std::filesystem::symlink_status(nativePath, error))) return nativePath; + return RelinkedModulePath_nid_no_patch(nativePath); ~~~~ --- `std::filesystem::exists(file_status)` is false when `file_status` is `not_found`, which is what `symlink_status` returns for a dangling symlink. That means a dangling original path is not preserved here as the PR description says; if a sibling `<path>.guest.prx` exists, stat/open/reachability will be redirected to it. Could this test the `symlink_status` type (or otherwise preserve every existing directory entry) and add a regression with a dangling original symlink plus a relinked sibling?
xXPBSXx commented 2026-10-12 22:24:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T22:24:23Z.


Windows test of this PR.

Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON, -j2. Base: a60f52e31 (main before the libusb-cmake submodule), this PR's commit f80a2f553 on top (fast-forward, no conflict). git merge-tree against the current main is also conflict-free.

Result: guest_filesystem and guest_posix_filesystem pass (2 of 2), including the new TestRelinkedModuleNames (stat, reachability and open of Plugin.prx resolve to Plugin.prx.guest.prx; a missing file and another name still return 0x80020002).

Not checked: whether the new test fails without the change to the library code (I ran only the PR as submitted); no title run. I did not build on the current main because it needs the new libusb-cmake submodule, which is not available here; the result above is for the base named above.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6133743134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4688#issuecomment-6133743134). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T22:24:23Z. --- Windows test of this PR. Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `BUILD_TESTING=ON`, `-j2`. Base: `a60f52e31` (main before the `libusb-cmake` submodule), this PR's commit `f80a2f553` on top (fast-forward, no conflict). `git merge-tree` against the current `main` is also conflict-free. Result: `guest_filesystem` and `guest_posix_filesystem` pass (2 of 2), including the new `TestRelinkedModuleNames` (stat, reachability and open of `Plugin.prx` resolve to `Plugin.prx.guest.prx`; a missing file and another name still return `0x80020002`). Not checked: whether the new test fails without the change to the library code (I ran only the PR as submitted); no title run. I did not build on the current `main` because it needs the new `libusb-cmake` submodule, which is not available here; the result above is for the base named above. AI-assisted (Claude Code).
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!4688
No description provided.