Repository navigation
feat(libc): implement realpath - #3147
Merged
Merged
Conversation
Resolves a guest path the way FreeBSD 11's realpath does: a relative path starts from the guest working directory, "." and empty components are skipped, ".." drops the last component and never climbs above "/", every other component must exist, and one that is not a directory with anything after it is ENOTDIR. Backslashes separate components as in the rest of the path layer. The result is the guest path; the host is consulted only for existence and type, so host symlinks are followed but not expanded, and ".." is lexical, as in the rest of the path layer. A null buffer is PATH_MAX bytes from the application heap, a null path is EINVAL, an empty one ENOENT, and 1024 bytes or more in the input or the result is ENAMETOOLONG. On failure the caller's buffer holds the path that failed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fnrk5Dazjb2tLooVSpdRQq
9 tasks done
Collaborator
|
Checked on Linux (merged onto current |
Contributor
|
Windows title run to go with the Linux one above: e1f168a merged onto
|
9 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 result while a component remains, or in the result after appending one. A working directory that long already fails ingetcwd.ResolvePath_nid_no_patch, so a mount alias resolves and a blocked mount isENOENT; a host symlink is followed for existence and type but not expanded (see below).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.Symlinks: the console's guest filesystem has none, but a host directory under the guest root can. This
realpathdoes not expand a host link, and it drops..lexically. That is how the path layer resolves every guest path foropenandstat(Resolveinlibc/src/General.cppuseslexically_normal), so the result names the same file the title opens with the input. @Amoenus's probe on #1692 shows the difference from FreeBSD: throughlinkdir -> sub/deep,/fixture/linkdir/../marker.txtgives/fixture/marker.txt, where FreeBSD gives/fixture/sub/marker.txt. It is listed in TechnicalDebt. #1624 (lstat) and #1627 (readlink), merged since #1692, report host links to the guest on Linux. Expanding them here would makerealpathoflinkdir/../xname a different file thanopenof it.This is XashPS5's stop on
mainnow that #2968 (gethostname) is merged, as @babyhuey reported on #1692. #1692 was closed becauserealpathwas not a title's stop then; this is the same change rebased onto currentmain.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=ON, this branch onmaine4045bb:ctest: of 739 tests, 733 pass and fourvideo_out_flip_*tests skip under the offscreen SDL driver. Two fail:agc_driver_dcc_keys_first_write(agc_driver_dcc_keys_first_write fails where host imports stay write-watched (NVIDIA, Linux): cause and patch #2767);guest_avplayer, the intermittent failure in test(avplayer): guest_avplayer fails intermittently in full builds (Linux and Windows) #2709. It passes 5 of 5 repeats on its own.guest_realpathpasses 3 repeats.tools/check_conventions.py --base upstream/main,tools/check_test_registration.pyandgit diff --checkpass.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 longer than 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 the missing-component cases, forfile/andfile/x, and at the append boundary. Written before the implementation; it failed on the unresolved export and passes with it.RealPath.cppand test, oldermain):guest_realpathpassing 3 repeats and the full suite 474/474;guest_realpath5/5, and 5/5 failing with theENOTDIRcheck disabled;guest_realpathandguest_working_directory5/5 each.sce_module/libc.prxunwrapped) in a bubblewrap sandbox:maine4045bb (Release, tests and SPIRV-Tools off) the loader stops withsymbol lookup error: app.elf: undefined symbol: vhtcIgZG-Lk(exit 127). The import audit lists 18 absent imports.cjt-4ySmYTs(libkernel_sys).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
https://claude.ai/code/session_01Fnrk5Dazjb2tLooVSpdRQq