fix(libkernel_sys): answer raw __getcwd errors in FreeBSD's order and kinds #16370
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16370"
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 Ragbie on 2026-11-06T12:32:49Z.
What
The raw
__getcwdsyscall in libkernel_sys now answers the errors FreeBSD 11.4'skern___getcwdanswers, in the same order. Thelibkernel_sys.mddebt entry listed these differences as reviewed and not implemented; #10332's review asked for them to be mapped or listed, and they were listed.sys___getcwdpassesbuflenas au_intwithMAXPATHLENas the limit. A size below 2 answersEINVALbefore the buffer is looked at, so size 1 and a null buffer with size 0 now answerEINVAL(22), where they answeredERANGE(34) andEFAULT(14). The size is truncated to 32 bits first, as the kernel does.MAXPATHLEN(1024) is lowered to it; a path that does not fit answersENOMEM(12) fromvn_fullpath1, where it answeredERANGE.copyoutonly after the path is found, so a null or unwritable buffer answersEFAULT. The guest call now copies throughGuestCopyOut_nid_no_patch, so an unwritable buffer, or one that runs into an unmapped page, answersEFAULTinstead of faulting in the host. On success it still writes onlystrlen + 1bytes.getcwdmodel, with its errors (for exampleENOENTfor a removed directory) passed through. libcgetcwditself is unchanged.Tested
guest_kernel_sys:CheckRawGetcwdexpectsEINVALfor size 1. The newCheckRawGetcwdErrorsmoves into a fresh guest directory, so the path is at least 2 bytes long, and checksENOMEMfor a buffer one byte short with the buffer untouched, success with an exact fit,EINVALfor a null buffer with size 0 and 1 and for size2^32 + 1, andEFAULTfor an unmapped buffer and for one that crosses into an unmapped page.Kernel sys check failed at line 1229 (guest errno 34).libs: the 33 tests matching^guest_kernel_syspass, twice in a row; no directory is left behind. Fullctest:99% tests passed, 6 tests failed out of 4329. All six fail onmainon this machine too:test_registrationandselect_tests_MissingCommandTestsfail withWinError 1314, because this user cannot create symbolic links.agc_driver_direct_write_completion,agc_driver_image_plane_address_on_line,agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_laneare GPU tests on an NVIDIA card.check_skips.pyreports one skip,guest_fopen_errors, which skips itself here because this user cannot create symbolic links.^guest_kernel_syspass.GuestCopyOut_nid_no_patchhas its own macOS path.The full runs were on
main6185bdcfc4; after rebasing onto8b9958e681the^guest_kernel_systests were run again on Windows.Overlaps: #11031 and #16149 add functions next to
CheckRawGetcwdinGuestKernelSys.cpp; the new test function sits before it, so trial merges with both have no conflicts (git merge-tree). #15545 changes libcgetcwdfor size 1; this call checks the size before reaching libc, so the result does not depend on the order the two land in, and a trial merge has no conflicts.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 ahmadmuj on 2026-11-06T13:22:22Z.
Review: COMMENTED
Head:
c9708515bdeffcd9d6dc89bb154e5620f9d9abcd. PR base:921621976c52e841b3f88da29add24aa7bb27e8e. Compared with maine8b1bd3d7f1f639ff455b17d9bee1469bdeb4e9e.Could you add coverage for the internal path limit?
CheckRawGetcwdErrorsexercises the laterrequired > limitcheck. It does not reach the libcERANGEmapping.I checked the production libc and libkernel_sys modules with a separate Linux probe. Four 200-byte directory components, then sibling components of 218/219 bytes, give guest paths of 1023/1024 bytes. These lengths include the leading slash and exclude the NUL. Short relative guest
chdircalls enter each component. Libcgetcwd(..., 4096)first returns each exact path, so the fixture is verified.Fail(error == GuestErange ? GuestEnomem : error)withFail(error)leavesguest_kernel_syspassing. The new probe fails with errno 34 for both length-1024 calls.This agrees with FreeBSD 11.4's buffer cap and copyout order. This is a coverage suggestion; I found no defect in this boundary behavior.
Tested: Ubuntu 24.04 under WSL2, GCC 13.3, Release. Separate main/head builds use their exact project sources, plus the isolated probe and its registration, with shared dependency sources. Five configuration-only dependencies differ from their gitlinks; none appears in these targets' build commands. Commands:
cmake --build <build> --target guest_kernel_sys_tests raw_getcwd_cap_probe -j 16, thenctest --test-dir <build> -R '^(guest_kernel_sys|raw_getcwd_cap_probe)$' -V; each test finishes below one second.python3 tools/check_conventions.py --base origin/mainpasses. Full suite, Windows and console behavior are not tested here. GPUs tested: n/a.