feat(libc): implement realpath #1692
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1692"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T16:42:00Z.
What
Adds
realpathto libc (imported fromlibSceLibcInternal), in a newsrc/RealPath.cpp. It follows FreeBSD 11'srealpath.con the guest side:EINVAL, an empty oneENOENT. A relative path starts from the guest working directory (getcwd); an absolute one from/..components are skipped;..drops the last resolved component and never climbs above/. Every other component must exist, and one that is not a directory with anything after it (file/x,file/,file/.,file/..) isENOTDIR. A missing component isENOENTeven when a later..would drop it. Backslashes are separators, as everywhere in the path layer.ENAMETOOLONGwhere FreeBSD gives it: 1024 bytes (PATH_MAX) or more in the input after the leading separator, in the working directory, in the result while a component remains, or in the result after appending one.ResolvePath_nid_no_patch, so a mount alias resolves and a blocked mount isENOENT; host symlinks are followed but not reflected in the result, since the guest filesystem exposes no symlinks.resolvedis aPATH_MAXbuffer from the application heap, which the title'sfreereleases (libcurl does,lib/vtls/vtls_scache.c). With a caller's buffer, a failure leaves the path that failed in it, as FreeBSD does.It does not depend on #1624 (
lstat) or #1627 (readlink): the resolution is lexical plus host existence checks, which is what the console's filesystem makes observable.Overlap: #1729 (
syslog) adds its source line to the same list inlibc/CMakeLists.txt; whichever merges second rebases one line.In the Linux audit of the homebrew catalog (#1578),
realpathwas absent for 17 of the 34 relinked titles. The callers are statically linked libraries: Mesa'sutil_dl_get_path_from_proc, libcurl's CA path keys and fontconfig'sFcStrRealPath; all of them accept a null return.Tested
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ONon this branch (based onmain4b005b22):ctest --repeat until-fail:3467/467;tools/check_test_registration.pyandtools/check_conventions.py --base upstream/mainpass.guest_realpathtest on a directory tree under the guest root:/, a directory with and without a trailing slash,..,., doubled slashes,..above the root, backslashes, an upper-cased directory name returned as typed, relative paths afterchdirincluding..back to/, a mount alias and a blocked mount, the allocated form freed withfree;EINVALfor null,ENOENTfor empty and for a missing component before..,ENOTDIRfor the four non-directory forms,ENAMETOOLONGfor an input of 1024 bytes and for/plus 1023 bytes (the append boundary),ENOENTfor a 1023-byte path of missing components, and the failing path left in the caller's buffer in each case. Written before the implementation; it failed on the unresolved export and passes with it.libc.prxexports the NID (vhtcIgZG-Lk).tools/import_audit.pyon five of the 17 catalog titles, absent imports before → after: PPSA59322 ccleste 50 → 49, PPSA99010 vkQuake 51 → 50, PPSA99505 Jelly5 30 → 29, PPSA99082 OpenNOW 36 → 35, PPSA99808 PICO-8 28 → 27. The before column is the #1578 audit (main4b005b22+ #1529, which changes binding, not which NIDs the built libraries export); the after column is this branch onmain4b005b22. None of them loads yet; the remaining imports are listed in #1578.main6b56175a), run 37822095572:guest_realpathpasses its three repeats, full suite 474/474. hikazey ran this commit merged ontomainb858fdc4on Windows 11 with MinGW-w64 GCC 15.2.0:guest_realpath5/5, the full suite 478/478, and the test fails 5/5 with themoreFollows && !is_directorycheck disabled, so theENOTDIR, backslash, case-insensitive andENAMETOOLONGcases hold against Win32's path normalisation (comment). The code is platform-neutral (std::filesystemover the resolver's native paths) and the test is registered on both platforms likeguest_working_directory.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T19:30:17Z.
Windows run, since the description lists Linux only: Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto
mainb858fdc4, which merges cleanly.guest_realpathmoreFollows && !is_directorycheck disabled, test keptI checked this one on Windows because Win32 path normalization drops trailing
.and separators, sofile/.orfile/could look likefileto the host. The component-by-component walk avoids that: theENOTDIRcases hold on Windows, as do the backslash, case-insensitive spelling andENAMETOOLONGcases in the test.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T19:39:39Z.
Thanks for the Windows run and the normalisation angle; the mutation check is the useful part. Added to the Tested section.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T20:17:53Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libc/CMakeLists.txtL35Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:29:38Z.
Closing:
realpathisn't a title's stop on main. In the PICO-8 (PPSA99808) run in #1578 it comes after nine other missing imports, one of them without a PR yet. Reopen when it's a title's next stop on main, with the log line.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-10T17:31:00Z.
Additional Windows validation of this proposal, without requesting reopening under the current first-stop rule.
Tested PR head
57f8d2390a1d968151fe71a0311c9a94445581d7applied locally to main57f96fd2b36563e8380c603a92b1ef0d9d3a6aa4, retaining main's libc source list. Windows 11 Enterprise 26200, WinLibs r7 MinGW-w64 GCC 15.2.0, Release, BUILD_TESTING=ON. Full system-library build passed;guest_realpathandguest_working_directorypassed 5/5 runs each. This is not a full-suite or Linux result.An additional host-symlink probe failed 5/5 runs. Under the guest filesystem root, create:
Create the file and directory links with
CreateSymbolicLinkW(Developer Mode enabled). Calling the proposal'srealpath_nid_postfixwith a 1024-byte output buffer gives:/fixture/link.txt/fixture/sub/target.txt/fixture/link.txt/fixture/linkdir/../marker.txt/fixture/sub/marker.txt/fixture/marker.txtBoth marker files exist, so the second result is successful resolution through the wrong parent, rather than just a missing-file error. The proposal already mentions that host links are followed without reflecting their targets in the returned path; the second case demonstrates an additional behavioral consequence of that limitation.
There is also a toolchain trap when guarding this case. On these native links, a standalone host-only probe reported:
The native attributes include FILE_ATTRIBUTE_REPARSE_POINT, but this MinGW standard-library path reports the target's ordinary file/directory type.
std::filesystem::create_symlinkalso returned ENOSYS here; native fixture creation worked.A local diagnostic guard using Windows reparse-point attributes, and
symlink_statuson other hosts, throws explicitly for these unsupported components rather than returning an unresolved or incorrectly normalized path. The expanded test checks both file links and directory-link/.., the exact exception, and that the output buffer is untouched. Full system libraries built; both tests passed 5/5. Removing the guard caused the new realpath test to fail, then restoring it returned both tests to 5/5. Conventions and test-registration checks passed. This guard rejects every Windows reparse point, does not implement guest link-target translation, requires link creation privileges or Developer Mode for its Windows fixture, and has not been tested on Linux.In our PPSA99902 investigation,
realpathappears only after a local stack of other import fixes/placeholders. It is not the title's next stop on unchanged main. No guest entry or gameplay was reached, and no realpath execution by the title has been observed. No new PR was created.AI-assisted investigation and local changes: Codex. All claims above are from local builds, behavioral probes, and controlled startup logs; console behavior remains unverified.
Fixture follow-up: the first diagnostic fixture used forward slashes in Windows reparse targets, which affected native lookup. I repeated the probe with native relative targets
sub\target.txtandsub\deep, verified that reading the file link returns the target contents and that resolving the directory link reachessub/deep, and obtained the same two realpath failures in all five runs. Expected..behavior is the guest/FreeBSD behavior: FreeBSD 11 realpath.c expands a link target back into the remaining component walk before processing subsequent components. Windows native lexical normalization oflinkdir/..is not used as the oracle.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T22:36:20Z.
@SleglJan with
gethostname(#2968) merged, XashPS5 (PPSA19111) now stops atrealpathonmainf38a036e(catalog build,sce_module/libc.prxunwrapped):app.elf: symbol lookup error: app.elf: undefined symbol: vhtcIgZG-Lk. Ruffle (PPSA68091) also reaches it after a few open fixes. That's the condition this was closed on, and the intake check is at 10 merged PRs, so it can go up again as a new PR.Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T23:14:30Z.
@babyhuey thanks, reopened as #3147, rebased onto
maine4045bbb. On thatmain, XashPS5 stops atvhtcIgZG-Lkas you reported. With the branch, its loader stops at the next import,cjt-4ySmYTs(libkernel_sys). The description also covers @Amoenus's symlink probe:..stays lexical, as foropen, and the difference from FreeBSD is listed in TechnicalDebt.AI-assisted: yes (Claude Code)
Pull request closed