feat(libkernel_sys): implement lchmod #9200
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9200"
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 KernelPanicNT on 2026-10-21T15:08:24Z.
What
lchmod(path, mode)in libkernel_sys now changes a file's mode without following a final symbolic link, as FreeBSD 11.4'ssys_lchmoddoes. Until now it was one of the throwing stubs that #8837 added toExport.Discovery.cpp.It forwards to the existing
fchmodatwithAT_FDCWDandAT_SYMLINK_NOFOLLOW, so the path lookup, the error codes (EFAULT,ENOENT,ELOOP,ENAMETOOLONG) and the07777mask arefchmodat's.Source of the behaviour.
8c639945:sys_lchmodis exactlykern_fchmodat(td, AT_FDCWD, path, UIO_USERSPACE, mode, AT_SYMLINK_NOFOLLOW).kern_fchmodatlooks the path up withNOFOLLOWand callssetfmode, which masks the mode withALLPERMS(07777). The prototype isint lchmod(char *path, mode_t mode), syscall 274.lchmodwith 2 arguments and a native handler, andnosys(compat.lchmod) in the PS4 SELF table, like the other path calls that only libkernel_sys exports.What is kept as a throw, and why.
fchmodatwithAT_SYMLINK_NOFOLLOWreturns success without a change here, which its debt entry lists as a silent stub.lchmodexists for this case, so it throws instead of adding a second silent stub. On macOSfchmodatchanges the link's mode, andlchmoddoes too.Changes:
Export.cpp:lchmod_nid_postfix(const char*, std::uint16_t). Outside macOS it resolves the path first and throws for a symbolic link (on Windows, any reparse point, asfchmodatdoes); then it callsfchmodat_nid_postfix(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW).Export.Discovery.cpp: thelchmodstub is removed.guest_kernel_sys:lchmodof a file by host path and by guest path (0600, then0100644masked to0644), a missing file (ENOENT), a null path (EFAULT) and an empty one (ENOENT); outside Windows, a lookup through a link loop (ELOOP), a 256-byte component (ENAMETOOLONG), and a symbolic link that throws on Linux (changes the link on macOS) while the file it points to keeps its mode.docs/dev/debt/libkernel_sys.md: a newlchmodentry for the symbolic link throw.Unblocks: none. No title is known to import
lchmod, and I found no homebrew port that calls it in source (Porpoise'stools/core-imports.pyroutes its cores'fchmodat, notlchmod).Since this has a FreeBSD source and a firmware syscall table reading, but no title that is known to call it, where is the line for the title rule? Would a sourced FreeBSD syscall like this be accepted, or only one seen in a relinked title's imports? If it is not acceptable, please close it, and I will resubmit it when a title needs it.
Tested
Linux (GitHub Codespace, 4 cores, native build of this branch on
maincecb540a6):guest_kernel_sys_tests: 5/5 runs pass.Export.cppandExport.Discovery.cppfrommain,guest_kernel_sys_testsaborts withwhat(): lchmod_nid_postfix not implemented. 5/5 pass again after restoring them.Not tested: Windows and macOS (the symbolic link case differs there and is not built here), a console, a title run.
Checks:
python3 tools/check_conventions.py --base origin/mainpasses.tools/progress.py: unchanged (4609/10947 done on base and head; the counter tracks the exported symbol, which is present as a stub onmainand as the implementation here).Duplicate and overlap check
Searches of open and closed pull requests for
lchmodfind none that implements it, and none of the open libkernel_sys or libkernel pull requests changes it in its diff. #9103 (chown, lchown, fchownat, linkat) removes the neighbouring stubs inExport.Discovery.cpp.python3 tools/pr_overlap.py --branch feat/libkernel-sys-lchmodreports text conflicts on neighbouring lines, none on the same export or the same new file:Export.Discovery.cppwhere thelchmodstub was.lchmodone indocs/dev/debt/libkernel_sys.md.Whichever lands second keeps both changes. It could not compare #5021, #5528, #6044 and #7201, which conflict with
mainonExport.cpporGuestKernelSys.cpp. Checked by hand: none of them toucheslchmod(#5528 is readlink path length, #6044 and #7201 are test and macOS build changes, #5021 is the AOT compiler).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)lchmod)Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T20:49:23Z.
Windows run of
0858e024fbmerged ontomain0c6a5bd593(8378a6fb3c, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.Built
libkernel_sysandguest_kernel_sys_testswith no errors or warnings.ctest --repeat until-fail:2onguest_kernel_sys: passes on both repeats. On Windows the extendedguest_kernel_sysblock callslchmodon a file by host and guest path, on a missing file, a null path and an empty one; the symbolic link case and the mode checks are built only outside Windows, so the reparse-point branch is not exercised here. Not run: a title.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T06:49:16Z.
#9442 removes the
lchflagsstub right next to thelchmodstub this PR removes inExport.Discovery.cpp, so the two deletions are adjacent; text only, whichever lands second rebases.