fix(libkernel_sys): reach paths past MAX_PATH in mkdirat, unlinkat, renameat and readlink #24130
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24130"
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 XFlawless1 on 2026-11-20T07:08:00Z.
What
On Windows,
mkdirat,unlinkatandrenameaton a directory descriptor, andreadlink/readlinkat, fail withENOENTwhen the host path isMAX_PATHor longer. They join the descriptor's path (fromGetDirectoryDescriptorPath_nid_no_patch,\\?\stripped) or the resolved path with the name and pass the plain result toCreateDirectoryW,std::filesystem,_wunlinkand the like, which refuse it. A deeply nested directory, or one whose real path through a substituted drive, junction or symlink is that long, hits it.mkdir,openandchmodalready add the prefix.HostLongPathreturns the path fromNativeVerbatimPath_nid_no_patchonly when it carries the\\?\prefix, so short paths are passed on unchanged (not lexically normalized).mkdirat,unlinkat,renameat(source and destination) andReadNativeLinkuse it for their host calls. The paths given toRecordWrittenPath_nid_no_patchand the symbolic link limit walk keep the plain form: both work onlexically_normal/component iteration, which libstdc++ does not parse correctly for\\?\C:\paths.unlinkat(..., AT_REMOVEDIR)checked emptiness withstd::filesystem::is_empty. For a directory at a\\?\path pastMAX_PATH, MinGW's libstdc++ returns false with no error for an empty directory, so the call returnedENOTEMPTY. On Windows the check now lists the directory withFindFirstFileW, skipping.and..; other hosts keepis_empty.GuestKernelSys(Windows) opens a directory whose path exceedsMAX_PATHas a descriptor and checksmkdirat(andEEXIST),readlinkaton a regular file (EINVAL) and a missing name (ENOENT),renameat(andENOENT),unlinkatof a file (andENOENT) andunlinkat(AT_REMOVEDIR).Not changed, because the paths need symbolic links or hard links that this machine cannot create without the privilege, so they could not be tested:
linkat,symlinkat, andfchmodat'sAT_SYMLINK_NOFOLLOWreparse check. (fchmodatitself already reaches long paths throughChmodNative_nid_no_patch.)Overlaps, all mechanical: #23786 makes
ReadNativeLinkuse the path the link walk resolved, soHostLongPathwould apply to that path instead; #23799 moves the emptiness check inside#ifdef _WIN32, where it becomesDirectoryIsEmpty; #24114 adds a test case at the same place inGuestKernelSys. I will rebase this one onto whichever lands first.Tested
Windows 11, MinGW-w64 GCC (WinLibs UCRT), Ninja, Release, AMD Ryzen 7 9800X3D.
Export.cppfrommainand the new test, run from a short directory:guest_kernel_sysfails at the firstmkdiratwith errno 2. With the change, the whole executable passes. Before theDirectoryIsEmptychange it failed atunlinkat(AT_REMOVEDIR)with errno 66; a standalone check confirmedis_emptyreturning false for an empty directory at a\\?\path of 349 characters whileFindFirstFileWlists it.guest_kernel_sysrun from a build directory reached through asubstdrive (real path over 260 characters) gets from line 1118 to line 1818; the remaining stop is #24114's area (fchdiron a substituted drive), not this change.ctest -j16(6470 tests) onmainand with the change: the differences areagc_driver(timed out at 120 s under the parallel load; passes alone in 24 s),agc_driver_store_over_untracked(#22670, 3 of 4 reruns pass) andagc_storage_write_back_host_retile(#23708, passed this time). No AGC code calls the changed functions.tools/check_conventions.py --base origin/mainpasses.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 PrivacyOnion on 2026-11-20T07:09:59Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ca9d939541:tools/check_conventions.pypassed.guest_kernel_sys_testsbuilt cleanly.guest_kernel_sys):core/libs/prx/libkernel_sys/Export.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:23:51Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: fix the Windows directory emptiness helper so it reports enumeration errors instead of treating them as an empty directory.
What I ran
Reviewed head
ca9d939541f43408b84c9c9ceea51b1a5b3e0f65. I read the prepared description, commits, manifest, diff, and the full text of both changed files. I did not run commands or tests;repo_read.pywas not available as an executable tool in this review session.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel_sys/Export.cpp:223: IfFindNextFileWfails for a reason other than reaching the end of the listing, the loop exits withempty == true. Forunlinkat(..., AT_REMOVEDIR), that can allow removal to proceed after an incomplete enumeration. CheckGetLastError()after enumeration and propagate errors separately from the empty result.Not verified
core/libs/prx/libkernel_sys/Export.cppandcore/libs/tests/GuestKernelSys.cpp; both full files were read.files.jsonwas not available through the reader, so whether additional files were excluded is not verified.WindowsVerbatimPath.hppwas read around the implementation used by this change; its full file was not read.To get this to a good state
Nothing blocks this; the points below are optional.
FindNextFileWerrors separately from normal end of enumeration so an incomplete listing cannot be treated as empty.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T09:24:47Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d1c4f17ab6:tools/check_conventions.pypassed.guest_kernel_sys_testsbuilt cleanly.guest_kernel_sys):core/libs/prx/libkernel_sys/Export.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:45:46Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
d1c4f17ab6019a7a671033ec510a7f49b9be745d. No commands or tests were run. I readdescription.md,commits.md,manifest.json,diff.patch,core/libs/prx/libkernel_sys/Export.cpp,core/libs/prx/libc/include/WindowsVerbatimPath.hpp,core/libs/prx/libc/src/Rename.cpp, andcore/libs/tests/GuestKernelSys.cpp. Both changed files listed in the manifest were included and read. No files were excluded by the prepared manifest.Results
Findings
Blocking
None.
Non-blocking
DirectoryIsEmptyhelper returnsfalsefor both a non-empty directory and aFindNextFileWenumeration error. Callers then reportENOTEMPTYeven when enumeration failed for another reason. Consider checkingGetLastError()after enumeration ends and returning that error throughstatusError. Seecore/libs/prx/libkernel_sys/Export.cpp:223.Not verified
Windows execution, including the reported
GuestKernelSysand fullctestruns, was not reproduced.linkat,symlinkat, andfchmodatreparse behavior were not changed or verified in this review. The description's comparison with overlapping PRs was not checked.To get this to a good state
Nothing is required. The enumeration error distinction above is optional.