fix(libkernel): leave out directory entries removed while getdents lists them on Windows #12139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12139"
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 dantdmdarealguy on 2026-10-27T23:26:53Z.
What
On Windows,
sceKernelGetdents,getdirentriesandreaddiron a host directory fail withENOENTorEACCESif another thread or process removes an entry while the listing is being read.Since #8520, the directory snapshot in
DirectoryDescriptor.cppLoadlists the directory and thenlstats each entry. When an entry is gone by the time of itslstat, the whole read fails with that error. FreeBSDgetdentsnever fails this way: an entry removed during the read is either listed or not.Two cases cause it:
FillLinkStatfails withENOENT, andLoadthrew. It now leaves the entry out, as if it had been removed before the read._wstat64already reportsENOENTfor such a file, butDoStat/DoLstatthen open it withCreateFileW. That open fails withERROR_ACCESS_DENIED, andRtlGetLastNtStatusreportsSTATUS_DELETE_PENDING. That path returnedEACCES. It now returnsENOENT, the same answer_wstat64gives. Sostat/lstatof a file being deleted no longer reportEACCESin that window.Errors other than a removed entry still fail the read as before.
This is the
guest_filesystemabort on Windows CI in job 122249163051 (maine2a5118+ #10616). The abort is atGuestFilesystem.cpp:1379Require(read > 0), aftersceKernelOpen(".", O_DIRECTORY). Symbolized from the same test source and toolchain:Checkreturns toguest_filesystem_tests.exe+0x19fe, and the caller's return address+0x2643efollowsCheck(…, 1379). Both offsets match the CI log. Theopen failed path=…/missing/../present.txtlines before the abort are expected failures logged byTestParentTraversal, not the cause. The test lists the working directory that the other libkernel tests share, while ctest runs them in parallel and they delete their temporary directories there.Linux host directories use
getdents64inStdio.cpp, which already tolerates removed entries. On Linux,Loadonly serves directories that the app archive also covers.New test
guest_directory_removed_entries:sceKernelStatandlstatreturnENOENTand thatgetdentslists only.and...getdentsreads the directory. The read must succeed, list every file that is not removed, and list no name twice.Tested
Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0, Release.
guest_directory_removed_entries:main100/100 abort at itsgetdentscheck. With this change, 0/100, about 1.6 s per run.main100/100 abort with getdents0x80020002(ENOENT). With theENOENTpart of the fix alone, 6/20 still aborted with0x8002000d(EACCES) from the pending-delete window. With the whole change, 0/100.guest_filesystemwith two processes creating and removing directories in its working directory:main68/100 abort, all at+0x19fe/+0x2643eas in CI. With this change, 0/100.guest_directory_removed_entriespasses 100/100 on bothmainand this change, since host directories there usegetdents64.ctest -R "^guest_directory|^guest_filesystem$|^guest_truncate|^guest_stat|^guest_fdopendir|patched_libraries" --parallel 2passes 13/13;patched_librariesreports 368 patched libraries loaded, 0 failed.ctest -R "stat|file|dir|link|rename|unlink|open|path|chmod|utime|access|kqueue|aio|mkdir" --parallel 2passes 197/198. The one failure isconventions_env_reference_test_a_check_from_a_subdirectory_reports_the_same_findings, a Python tools test whosegit tag basefails here because this machine's global git config signs tags; it fails the same way without this change.cmake --buildand--target libssucceed with no warnings in the touched files.check_test_registration.pyandcheck_conventions.py --base origin/mainpass.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)