feat(libkernel_sys): export _openat #8701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8701"
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 nikowolf123 on 2026-10-20T21:31:48Z.
What
Exports
_openatfrom libkernel_sys. It forwards toopenat._openat(fd, path, flags, ...)reads the mode argument only whenO_CREAT(0x200) is set, asopenatand_opendo, and callsopenatwith the same descriptor, path, flags and mode. So it returns whatopenatreturns: a new descriptor, or -1 with errno set toEINVAL(22) for the access modeO_ACCMODE(3) or forO_CREAT | O_EXCL | O_DIRECTORY, before the path is looked at; thenEFAULT(14) for a null path andENOENT(2) for an empty one;AT_FDCWD(-100) or an absolute path, the errors ofopen, which it passes the path to;EBADF(9) for a descriptor that is not open,ENOTDIR(20) for one that is not a directory,EMLINK(31) forO_NOFOLLOWon a symbolic link, asopendoes, and otherwise the error of the host open, such asEEXIST(17) forO_CREAT | O_EXCLon an existing file.Sources:
_openat, NIDbGVEgWXy6dg(libkernel_sys.c#L527-L532, #L8830), as well asopenat(A8Yk5AhNDck, #L1808-L1813, #L9013).release/11.4.0, 8c639945a4): libc's own calls toopenatgo to_openat(namespace.h#L84)._openatis the system call stub thatPSEUDOgenerates for each interposed call (sys/Makefile.inc#L48, #L81, amd64/SYS.h#L46-L50). The publicopenatreads the mode only withO_CREATand calls through the interposing table (openat.c#L47-L62), where libthr installs__thr_openat(thr_syscalls.c#L657), which adds the cancellation point (#L297-L321).openathere is not a cancellation point (Thread cancellation indocs/dev/debt/libkernel.md: file and socket calls are not cancellation points), so forwarding to it leaves_openatwithout one, as in FreeBSD.Unverified: the console's
_openatis taken to be FreeBSD's and was not checked on a PS5. Theopenatentry ofdocs/dev/debt/libkernel_sys.mdnow names_openattoo, so its gaps and its closing "Console behaviour is unverified" cover_openat.The entry no longer says that
O_NOFOLLOWis ignored. Since9421484572(fix(libkernel): fail open with O_NOFOLLOW on a symbolic link),open, and soopenat, returnsEMLINKforO_NOFOLLOWon a symbolic link unlessO_CREATandO_EXCLare both set (Open.cpp#L219-L230).O_NONBLOCKis still ignored:MapFlagsdoes not pass it to the host open. The entry also says that PPSA99003 opens directory entries throughopenat, as it said before it named_openat.The 3.20 libkernel and libkernel_web export lists also have
_openat; this PR only adds the libkernel_sys export.Overlap: the open #9131 rewrites the
fchdirentry directly above theopenatentry this PR rewrites indocs/dev/debt/libkernel_sys.md, so whichever lands second needs a one-line rebase.Tested
BUILD_TESTING=ON, on this branch (d23dcf9e6) rebased ontomainca74ef217, and again at673ff23c5onmain2c4b116da. Built thelibkernel_sys,guest_kernel_sys_testsandpatched_libraries_teststargets;ctest -R '^(guest_kernel_sys|patched_libraries)$'runsguest_kernel_sysandpatched_libraries, which pass.GuestKernelSys.cppnow also calls_openatnext to theopenatchecks: it opensfile.txtthrough a directory descriptor and reads back its byte; it createsalias.binwithO_WRONLY | O_CREAT | O_EXCLand mode 0600 and, outside Windows, checks that the file has mode 0600, so the variadic mode reaches the host open; it reopensalias.binwithO_WRONLY, which on Windows fails if the mode lost its write bit, sinceNativeOpenthen creates the file read-only; then it checksEEXIST(17) for the same exclusive create,EINVAL(22) forO_ACCMODE,EBADF(9) for descriptor -1 andENOTDIR(20) for a file descriptor.main:mainhas no_openat_nid_postfix, so the updated test does not link there. An earlier revision of this test onmain9a97ac784failed to link withundefined reference to `_openat_nid_postfix'.tools/check_conventions.py --base origin/mainwith this title and description: all checks passed.tools/progress.py --module libkernel_sys: 14 of 546 functions done (13 of 545 onmain2c4b116da, whereExport.Discovery.cppdeclares 527 throwing exports);_openatis the new one.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:58:02Z.
Windows run of d23dcf9e6c merged onto
main1fd67185b6(51ebe7d931, clean). 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_tests;ctest -R "^guest_kernel_sys$" --repeat until-fail:3: passes every repeat (2.5 s a run), with the_openatchecks in it (the mode check sits outside Windows by the test's own#ifdef). Not run:patched_librarieson this branch.