feat(libkernel_sys): implement __getcwd #10332
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10332"
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 MarcZX10 on 2026-10-23T18:11:33Z.
What
Add the missing
libkernel_sysraw__getcwdexport (Qsxbb+aty0U). It reuses the guest-root-aware cwd implementation, requires caller-provided storage (EFAULTfor null), returns 0 on success, and returns -1 with the guest errno on failure. The raw syscall signature isint __getcwd(char *buf, size_t buflen); the FreeBSD syscall table defines it as syscall 326. A PS5 port report notes that PS5 libcgetcwdcalls thislibkernel_sysexport.Tested
-Wall -Wextra -Werror) passed forExport.cppandGuestKernelSys.cpp.python3 tools/check_conventions.py --base upstream/mainandgit diff --checkpassed.python3 tools/pr_overlap.py --branch codex/libkernel-sys-getcwdreported no confirmed overlap. Conflicted legacy PRs were checked manually; no open PR adds this export or NID.guest_kernel_sys_teststarget was not run: CMake configuration stops because several pinned third-party submodules are absent (includingffmpeg-core,freetype,glslang, andLibAtrac9). No PS5 hardware test was run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T01:04:23Z.
Review: COMMENTED
Checked against main
11d6efa06cand FreeBSD 11.4sys/kern/vfs_cache.c(sys___getcwd,kern___getcwd,vn_fullpath1) andlib/libc/gen/getcwd.c:getcwd_nid_postfix.getcwd, not the syscall. FreeBSD'skern___getcwdstarts withif (buflen < 2) return (EINVAL), so__getcwd(buf, 1)should fail withEINVAL, not theERANGEthatGuestKernelSys.cpp:191asserts. Size 1 → ERANGE is done by libc'sgetcwd.cbefore it calls__getcwd./app0, buflen 3), FreeBSD'svn_fullpath1returnsENOMEM. This PR returnsERANGE, because main'sgetcwduses 34 for any short buffer (General.cpp:770).__getcwd(NULL, 0)hits thebuflen < 2check first in FreeBSD and givesEINVAL. Here it returnsEFAULT.__getcwd_nid_postfixitself (< 2→ EINVAL, too short → ENOMEM), with the test updated? Otherwise, could the debt entry say which errors differ, since it currently says it followssys___getcwd?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:55:31Z.
Review: APPROVED
Reviewed — approved
__getcwdmerges cleanly onto currentmain, builds, its new test passes on Linux and fails when the null-buffer check is removed, and the remaining errno differences from FreeBSD are recorded in the debt file as agreed in the earlier review thread.What I ran
Head
a2e7b248ae589f2c804d0767e9731aeab1de8c2c, merged with--no-ffontomainba5b5330b37724bca4b99f30faab504653635a04in a clean worktree. Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja,BUILD_TESTING=ON, Intel Core i9-14900KF.Results
mainApi.hppauto-merged)git diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.libstargetguest_kernel_sys*(23 tests) andpublic_headers*(65 tests)guest_kernel_sysafter restoring the merged filesctest tail
Negative control
Export.cppandApi.hpptaken frommain,GuestKernelSys.cppdoes not compile (__getcwd_nid_postfixwas not declared in this scope). As expected, but that only shows that the test uses the new export.if (buffer == nullptr) return ... Fail(GuestEfault)line.guest_kernel_systhen fails (Subprocess aborted): with that line gone,getcwd_nid_postfixallocates a buffer and the call returns 0 whereCheckRawGetcwdexpectsEFAULT. With the line restored, it passes again.Findings
Blocking
None.
Non-blocking
sys___getcwd/kern___getcwd,buflen < 2returnsEINVALbefore any other check. That source also shows a difference the new entry atdocs/dev/debt/libkernel_sys.md:18does not list:sys___getcwdpassesMAXPATHLENaspath_max, andbuflenis clamped to it, so a working directory of 1024 bytes or more fails withENOMEMhowever large the buffer is. Here__getcwd_nid_postfix(core/libs/prx/libkernel_sys/Export.cpp:710-713) passes the caller's size togetcwd_nid_postfix, which succeeds for any length. Paths that long are unlikely under the guest root, but the entry presents its list as the reviewed differences, so this one belongs there too. You could add it to the list, or clampsizeto 1024 in the wrapper.size < 2→EINVALfirst, then the null check. Ifgetcwd_nid_postfixfails with 34,ERANGE, rewrite it to 12,ENOMEM. A short buffer is the only case where the libc helper sets 34 (core/libs/prx/libc/src/General.cpp:932). TheError() == 34assertion atcore/libs/tests/GuestKernelSys.cpp:912would then expect 22. The debt entry could then be cut down to the remaining "unverified on hardware" note. This is optional; a collaborator already chose recording over mapping.sys___getcwdwithout a link. The neighbouring entries (kenv,lchmod) link the FreeBSD 11.4 source at a fixed revision. The link above would do.Not verified
__getcwd(errno values, path format,MAXPATHLENclamp). No hardware was available.Qsxbb+aty0Uresolves to this export at relink time. I only know that the progress-report bot counts it as a newly implementedlibkernel_sysexport; I did not relink a title.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:13Z.
Review: COMMENTED
Reviewed — three non-blocking points checked, one still open
The errno differences are recorded in the debt entry as oneandonlydean said, but the entry omits the MAXPATHLEN difference raised in review and has no FreeBSD source link.
What I ran
Head
a2e7b248ae589f2c804d0767e9731aeab1de8c2c(live, OPEN). Read-only:gh pr view,gh apiGET on comments and reviews,git grepandgit showat the head, includinglibc/src/General.cpp. Nothing was built or run.Results
docs/dev/debt/libkernel_sys.md:18sys___getcwdwithout a linksizethroughFindings
__getcwd_nid_postfixatExport.cpp:710-713checks null first, then passessizetogetcwd_nid_postfixwith no 1024-byte clamp. The debt entry does not mention a clamp. The FreeBSD 11.4 source reading the reviewer cites was not fetched, so the clamp itself is not verified.General.cpp:932sets errno 34 for a short buffer, which the entry describes.Sources
github.com/boykopovar/AnyPS5@a2e7b248ae/docs/dev/debt/libkernel_sys.md (L18)github.com/boykopovar/AnyPS5@a2e7b248ae/core/libs/prx/libkernel_sys/Export.cpp (L710-L713)github.com/boykopovar/AnyPS5@a2e7b248ae/core/libs/prx/libc/src/General.cpp (L932)Not verified
sys___getcwdbehavior, including the MAXPATHLEN clamp and the EINVAL order.__getcwd.Error() == 34assertion the reviewer cites atGuestKernelSys.cpp:912.Qsxbb+aty0Uresolves at relink.