Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
eliyarson:fix/kernel-stat-relinked-prx
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
eliyarson:fix/kernel-stat-relinked-prx

Conversation

@eliyarson

Copy link
Copy Markdown
Contributor

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.

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 Blasphemous 2 (PPSA13579) #4687 (past the PSNCore failure; the title also needs fix(libkernel): keep host standard streams open on guest close #3295 to survive bundle loading)
  • AI-assisted: yes

… stat, open and reachability

Titles check for a plugin with sceKernelStat before loading it through the engine path. The relinker emits only X.prx.guest.prx, so the check failed and PSNCore started with the raw (0, NULL) arguments. Share the dlopen mapping with sceKernelStat, read-only sceKernelOpen and sceKernelCheckReachability when the original name is absent.
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

xXPBSXx commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

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).

@oneandonlydean oneandonlydean self-assigned this Oct 13, 2026
@oneandonlydean
oneandonlydean merged commit 88f48fd into boykopovar:main Oct 13, 2026
13 checks passed
adriadam10 pushed a commit that referenced this pull request Oct 25, 2026
… lstat

#4688 made stat, sceKernelStat, read-only open and
sceKernelCheckReachability find X.guest.prx when a title asks for X,
the name the relinker replaced. lstat still answered ENOENT for the same
path, so a title that stats a plugin with lstat saw it missing while
stat and dlopen found it. lstat now resolves the name the same way;
an existing X, including a dangling symlink, is still reported as is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants