fix(libkernel): report ELOOP from unlink, mkdir, rmdir, truncate on Windows #8687
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8687"
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 cadenasynyster on 2026-10-20T21:04:07Z.
What
On Windows,
sceKernelUnlink,sceKernelMkdir,sceKernelRmdirandsceKernelTruncate(and their POSIX wrappers) do not report ELOOP for a path that goes through a symbolic link that points to itself. FreeBSD returns ELOOP (62). Measured on main withloop -> loop:unlink("loop/inside")0x80020016)mkdir("loop/inside")rmdir("loop/inside")truncate("loop")rmdir("loop")PathLookupFailure(#6942) only reports a loop whenstd::filesystemreturns an error code for it, which Linux does and Windows does not.sceKernelStatalready usesNativeSymbolicLinkLoopfor this. That check moves intoWindowsSymbolicLink.hppasFile::WindowsSymbolicLinkLoop(Open.cppnow calls it) and the four calls use it on their failure paths only, so successful calls do no extra work. Forunlink,mkdirandrmdirthe check is on the parent directory, since the final component is not followed. Fortruncateit is on the path itself, sincetruncatefollows the link.Refs #6983. Not covered here:
open(#8640, #8655) andrenamethrough a loop (#8696). #8217 is about the.and..components of a rename, which this PR does not touch.Tested
c6145997e.guest_filesystemhas nine new checks on astat-loop -> stat-looplink:unlink,mkdir,rmdirofstat-loop\inside(kernel and POSIX calls),truncateof the link (both calls), andrmdirof the link staying ENOTDIR. It passes.guest_path_errorsand printed every mismatch. Theunlink,mkdir,rmdirandtruncaterows above were mismatches before and are not after. The 300-character-name rows already passed on main. The 6 mismatches left are theopenandrenamerows.ctest -R "file|stat|open|path|dir|link|trunc|mkdir|unlink|libc|errno": 120 tests, 108 passed. Of the 12 others,guest_libc_threadsandguest_directory_entrieswere stale or unbuilt executables and pass after rebuilding. The other 10 areagc_*tests that showed exit0xc0000139(stale executables) because a full build stops at an unrelated AGC test target that does not compile with this MinGW (ImageArrayWindowPastLayerLimit.cpp:33: requested alignment 65536 exceeds the object file maximum of 8192).ctest -R "^agc_"runs 882 tests on an RTX 5070 Ti (driver 617.42): 876 pass, 3 are skipped and 3 fail (agc_driver_sample_order,agc_driver_sample_order_grid_reference,agc_driver_sample_order_recipe_depth_locations). The same 3 fail the same way with this PR's production files reverted to main and the libraries rebuilt, so they are not caused by this change.python tools\check_conventions.py --base origin/mainpasses._WIN32),rename,open, and merging this together with #8640, #8655 or #8696 (the hunks are in different functions).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 DavidSamir on 2026-10-22T03:14:06Z.
A Windows measurement that backs this PR up.
guest_path_errors(core/libs/tests/GuestPathErrors.cpp) is registered only underif(UNIX)on main (libkernel/CMakeLists.txt:332), so it never runs on Windows. I built it on Windows to see what it would report.Setup: main
6ef5a1c4c, WinLibs GCC 15.2, Windows 11. The test was moved out of the guard on a scratch branch. Its three::symlinkcalls were replaced withCreateSymbolicLinkW(unprivileged create).Requirewas made non-fatal, so every failing check is listed.Result: every
open/stat/lstatELOOP and ENAMETOOLONG check passes. Exactly these checks fail (main line numbers):sceKernelUnlink("loop/inside") == SceEloopsceKernelMkdir("loop/inside", 0755) == SceEloopmkdir_nid_postfix("loop/inside")setsGuestEloopsceKernelRmdir("loop/inside") == SceEloopsceKernelRename("loop/inside", "target.txt") == SceEloopsceKernelRename("plain.txt", "loop/inside") == SceEloopsceKernelTruncate_nid_postfix("loop", 0) == SceElooptruncate_nid_postfix("loop", 0)setsGuestEloopLines 79, 101-104 and 124-126 are the unlink/mkdir/rmdir/truncate paths this PR fixes. 115 and 117 are the rename path that #8696 fixes. With both merged, the existing test could run on Windows as the proof for both. The port it needs is
CreateSymbolicLinkWplus the usual skip when the account lacks symlink rights. I haven't run this PR's branch; these results are from main only.AI-assisted: yes