Skip to content

fix(libkernel): resolve original .prx names to relinked .guest.prx in lstat - #9478

Merged
adriadam10 merged 4 commits into
boykopovar:mainfrom
EagleBearerYS:fix/libkernel-lstat-relinked-prx
Oct 25, 2026
Merged

adriadam10 merged 4 commits into
boykopovar:mainfrom
EagleBearerYS:fix/libkernel-lstat-relinked-prx

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

#4688 made stat, sceKernelStat, read-only sceKernelOpen and sceKernelCheckReachability find X.guest.prx when a title asks for X, the name the relinker replaced, and listed lstat as not covered. lstat still answers ENOENT for the same path, so code that checks for a plugin with lstat sees it missing while stat and dlopen find it.

lstat now resolves the path with the module lookup of ResolvePathError_nid_no_patch, which sceKernelStat also uses. An existing X, including a dangling symbolic link, is still reported as it is; only a missing X falls back to X.guest.prx. Since #5401 was opened, main moved that lookup from File::PathOrRelinkedModule into the resolver's module flag, so the change is now that flag.

No title is claimed.

Overlap: #7447 changes the same ResolvePathError_nid_no_patch call in lstat: it sets the resolver's archived flag and answers from File::FillArchivedStat first, where this PR sets its module flag. The two should compose as ResolvePathError_nid_no_patch(path, native, true, true), the call sceKernelCheckReachability makes on main. This PR proposed going first in #7447's thread (comment), with #7447 taking that call when it rebases. qpavyros agreed (comment): this PR first, and #7447 keeps both flags in lstat's call when it takes this PR in.

#9618 (xXPBSXx) reworks the same function: lstat fills a local FileStat and copies it out with GuestCopyOut_nid_no_patch, so it answers EFAULT when the output struct isn't writable guest memory. The two conflict only there, and compose as #9618's version of the function with this PR's module flag in its ResolvePathError_nid_no_patch call. xXPBSXx checked both orders and either works for #9618 (comment). #9618 goes first, merge order only, and this PR re-applies its one-line flag when it merges main after it.

The other PRs the overlap check lists don't touch lstat or its test, so the merge order doesn't matter for them:

Related: #4225

Tested

On GitHub's runners from my fork, merged with main at a6dcea9 (run), on both Linux and Windows:

  • TestRelinkedModuleNames in guest_filesystem gains two lstat checks: ENOENT while neither name exists, and the relinked file's size once X.guest.prx exists. With main's Stdio.cpp the test aborts on both. With the change it passes 10 runs in a row.
  • Every test registered under core/libs/prx/libc and core/libs/prx/libkernel passes: 115 and 197 on Linux, 142 and 207 on Windows.
  • After the merge with main at da54c65 (82bd36d, no conflicts, the PR's own diff unchanged; run): guest_filesystem fails with main's Stdio.cpp on both runners and passes 10 runs in a row with the change. The libc and libkernel suites pass on Windows (143, 207) and libkernel on Linux (197); in libc on Linux, the timing test precise_wait failed once.
  • After the merge with main at b91a6a6 (20ae347; run): fix(libkernel): fail the stat family with EFAULT when the output struct is not writable guest memory #9618 now has lstat fill a local FileStat and copy it out to the guest, in the lines this PR changes. The merge keeps that and this PR's module lookup in the same ResolvePathError_nid_no_patch call, so the PR's own lines are unchanged. guest_filesystem fails with main's Stdio.cpp on both runners and passes 10 runs in a row with the change. Linux: 1 run, 1 pass, 0 skip, 0 fail. Windows: 1 run, 1 pass, 0 skip, 0 fail. Suites: libc and libkernel pass on Linux (144 and 207) and on Windows (171 and 223). The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • tools/check_conventions.py --base origin/main passes.
  • Not tested: macOS, a console, any title.

Checklist

… lstat

boykopovar#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.
@MarcZX10

Copy link
Copy Markdown
Contributor

This change overlaps lstat_nid_postfix in #9423: that PR updates its PathError call to copy and validate the guest path, while this PR changes the same function’s ResolvePathError_nid_no_patch call. Please coordinate the order with #9423’s author and set Depends on if one needs to land first; after composition, keep both the checked path copy and relinked-module lookup.

@EagleBearerYS

Copy link
Copy Markdown
Contributor Author

Thanks, @MarcZX10. git merge-tree of this PR's head (6e9768f) with #9423's (4d7b47a) is clean. The merged lstat_nid_postfix keeps both: #9423 replaces path with its checked copy right after PathError, and ResolvePathError_nid_no_patch(path, native, true) then runs on that copy. Neither needs the other first, so this stays at Depends on: none, and whichever merges second needs no change. @AliZedan1A, for your awareness.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6936 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7121 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7201 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 8520 core/libs/prx/libkernel/File/src/Stdio.cpp
core/libs/tests/GuestFilesystem.cpp
PR 9284 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9293 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9297 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9302 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9371 core/libs/tests/GuestFilesystem.cpp
PR 9693 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9732 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9823 core/libs/prx/libkernel/File/src/Stdio.cpp

@MarcZX10 MarcZX10 left a comment

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.

The module=true change is technically consistent with the existing resolver: ResolvePathOrRelinkedModule_nid_no_patch handles the module fallback, while ordinary lstat still uses the non-module resolution path. The added missing-name and relinked-file size assertions cover the intended behavior, and the existing sceKernelCheckReachability call demonstrates how the module and archived flags compose.

The remaining blocker is merge coordination with #7447. Both PRs change this exact lstat_nid_postfix resolver call. Your description proposes this PR first, followed by #7447 updating the call to (path, native, true, true), but #7447's author has not confirmed that order, and this PR still says Depends on: none. Please agree the order with @qpavyros and record the dependency/order on the checklist. The overlap scan also reports shared paths with #5021, #6044, #6879, #6936 and #7201; please account for the relevant file/test changes before approval.

The current eligibility, conventions, intake, labels and report checks pass. The Linux and Windows product jobs are skipped. The focused Linux and Windows runs in the description are author-reported; I did not run them locally.

@EagleBearerYS

Copy link
Copy Markdown
Contributor Author

Thanks, @MarcZX10. The Overlap section now covers each PR the check lists. #5021, #6879, #6936 and #7201 change other parts of Stdio.cpp, not lstat, and none of their conflicts is on the lstat line. #6044 moves GuestFilesystem.cpp unchanged, so whichever merges second carries the two lstat checks to the moved file. For #7447 the order is proposed in its thread, and I'll record it under Depends on once qpavyros answers.

@MarcZX10 MarcZX10 left a comment

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.

The module fallback is correctly limited to a missing original .prx path, while an existing file or dangling symlink remains handled by lstat itself; the regression covers missing and relinked names. The earlier #9423 checked-path overlap was manually confirmed to compose. The remaining functional coordination is #7447: it changes the same resolver call to set archived, while this PR sets module; the combined call needs both flags, but #7447’s author has not confirmed the proposed order and this checklist still says Depends on: none. Please agree the order with @qpavyros and record it, then preserve both flags when rebasing. This branch and reported tests are based on a6dcea9, while current upstream main is ab347d1; rebase and rerun guest_filesystem, conventions and overlap on current main. Hosted product jobs are skipped; I did not run local tests.

@EagleBearerYS

Copy link
Copy Markdown
Contributor Author

Thanks, @MarcZX10. The branch now has main at da54c65 merged in (82bd36d), with the PR's own diff unchanged. On GitHub's runners (run) guest_filesystem passes 10 runs in a row on both and fails with main's Stdio.cpp; the libc and libkernel suites pass apart from libc's precise_wait timing test once on Linux, and conventions pass. Tested now says so. The order with #7447 still waits on qpavyros; it goes under Depends on once they answer, and both resolver flags stay in the combined call.

@EagleBearerYS

Copy link
Copy Markdown
Contributor Author

@MarcZX10 82bd36d merged main da54c65 with guest_filesystem 10 of 10, and qpavyros agreed that #9478 goes first with both resolver flags kept (in Depends on). Could you re-review?

Main's boykopovar#9618 has lstat fill a local FileStat and copy it out to the guest.
The merge keeps that and this branch's module lookup in the same call, so an
original .prx name still resolves to its relinked .guest.prx.
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 25, 2026
@adriadam10 adriadam10 self-assigned this Oct 25, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 25, 2026 14:47

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@adriadam10
adriadam10 merged commit 4da1237 into boykopovar:main Oct 25, 2026
12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the module flag against PathOrRelinkedModule (an existing X or dangling symlink is reported as is, only a missing X falls back to X.guest.prx), the same call sceKernelStat and sceKernelCheckReachability make, and that both new lstat checks in TestRelinkedModuleNames fail without the change; merge order with #9618 and #7447 is settled; merged.

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.

3 participants