fix(libc): report ELOOP from rename through a Windows symlink loop #8696

Merged
cadenasynyster merged 2 commits from upstream-pr/8696 into main 2026-10-26 07:36:43 +00:00
cadenasynyster commented 2026-10-20 21:19:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-20T21:19:45Z.


What

On Windows, sceKernelRename and POSIX rename do not report ELOOP when the source or the destination goes through a symbolic link that points to itself. FreeBSD returns ELOOP (62). Measured on main with loop -> loop:

Call Windows on main After this PR
sceKernelRename("loop/inside", "target") ENOTDIR (0x80020014) ELOOP (0x8002003e)
sceKernelRename("present.txt", "loop/inside") ENOTDIR (0x80020014) ELOOP
sceKernelRename("loop", ...) renames the link unchanged (FreeBSD renames the link too)
sceKernelRename("missing/x", "target") ENOENT unchanged

RenameGuestPath_nid_no_patch ends with ENOENT or ENOTDIR for these paths, because std::filesystem does not report the loop on Windows. When it does, the directory part of the source and of the destination is now opened the way sceKernelStat already tests for a loop (CreateFileW failing with ERROR_CANT_RESOLVE_FILENAME), and the result becomes ELOOP. It runs only on that failure result, so successful renames do no extra work.

Rename.cpp gets its own private copy of the check. libc does not include libkernel headers, and #8687 adds the same check to WindowsSymbolicLink.hpp. The two can be merged into one helper after both land.

Refs #6983. This does not touch the . and .. components (#8217) or open (#8640, #8655).

Tested

  • Windows 11 (NTFS, Developer Mode on), AMD Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, on main fetched today.
  • guest_filesystem has four new checks on a stat-loop -> stat-loop link: sceKernelRename and POSIX rename with the loop in the source path and in the destination path (POSIX: -1 and errno 62). It passes, and so does guest_rename_dot.
  • A local probe, not part of this PR, printed the kernel return values shown in the table, before and after.
  • ctest -R "rename|filesystem|path|realpath|file|stat|open|dir": 110 tests, 98 passed. The 12 others are all agc_* (10 stale executables with exit 0xc0000139, 2 not built), because a full build stops at an unrelated AGC test that does not compile with this MinGW (#8310 is the open fix).
  • Later full build: on a scratch branch of main plus #8687 and #8696, with the one-file build fix of #8310 applied locally (not part of this PR), the full Windows build completes and 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. The 10 stale executables were stale builds, not failures.
  • Not run: Linux and macOS (the change is under _WIN32), and merging this together with #8687, #8640, #8655 or #8217 (the hunks are in different functions and files).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (refs #6983)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4942645744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8696). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-20T21:19:45Z. --- ### What On Windows, `sceKernelRename` and POSIX `rename` do not report ELOOP when the source or the destination goes through a symbolic link that points to itself. FreeBSD returns ELOOP (62). Measured on main with `loop -> loop`: | Call | Windows on main | After this PR | |---|---|---| | `sceKernelRename("loop/inside", "target")` | ENOTDIR (`0x80020014`) | ELOOP (`0x8002003e`) | | `sceKernelRename("present.txt", "loop/inside")` | ENOTDIR (`0x80020014`) | ELOOP | | `sceKernelRename("loop", ...)` | renames the link | unchanged (FreeBSD renames the link too) | | `sceKernelRename("missing/x", "target")` | ENOENT | unchanged | `RenameGuestPath_nid_no_patch` ends with ENOENT or ENOTDIR for these paths, because `std::filesystem` does not report the loop on Windows. When it does, the directory part of the source and of the destination is now opened the way `sceKernelStat` already tests for a loop (`CreateFileW` failing with `ERROR_CANT_RESOLVE_FILENAME`), and the result becomes ELOOP. It runs only on that failure result, so successful renames do no extra work. `Rename.cpp` gets its own private copy of the check. libc does not include libkernel headers, and #8687 adds the same check to `WindowsSymbolicLink.hpp`. The two can be merged into one helper after both land. Refs #6983. This does not touch the `.` and `..` components (#8217) or `open` (#8640, #8655). ### Tested - Windows 11 (NTFS, Developer Mode on), AMD Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, on main fetched today. - `guest_filesystem` has four new checks on a `stat-loop -> stat-loop` link: `sceKernelRename` and POSIX `rename` with the loop in the source path and in the destination path (POSIX: -1 and errno 62). It passes, and so does `guest_rename_dot`. - A local probe, not part of this PR, printed the kernel return values shown in the table, before and after. - `ctest -R "rename|filesystem|path|realpath|file|stat|open|dir"`: 110 tests, 98 passed. The 12 others are all `agc_*` (10 stale executables with exit `0xc0000139`, 2 not built), because a full build stops at an unrelated AGC test that does not compile with this MinGW (#8310 is the open fix). - Later full build: on a scratch branch of main plus #8687 and #8696, with the one-file build fix of #8310 applied locally (not part of this PR), the full Windows build completes and `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. The 10 stale executables were stale builds, not failures. - Not run: Linux and macOS (the change is under `_WIN32`), and merging this together with #8687, #8640, #8655 or #8217 (the hunks are in different functions and files). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none (refs #6983) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 13:39:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:39:14Z.

Review: APPROVED


Checked against main 522e32e3b6 and FreeBSD 11.4 kern_renameat:

  • It still merges cleanly with current main, and main has no ELOOP mapping in RenameGuestPath yet.
  • The reordered check after 0a238f9 matches the source-first order: a loop under the source gives ELOOP, and a loop under the destination gives ELOOP only when SourceLookupError_nid_no_patch(source) is 0. Renaming the loop link itself to a path under the loop also ends in ELOOP from the destination probe.
  • #8687 has landed, and BelowSymbolicLinkLoop is identical to File::WindowsSymbolicLinkLoop in libkernel's WindowsSymbolicLink.hpp:125. libc doesn't include libkernel headers today, so the private copy is fine here; a shared header could be a small follow-up.
  • I couldn't run the Windows cases; this is from reading the code, and your Developer Mode run covers the rest. Looks good to me.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638441921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8696#pullrequestreview-5638441921). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T13:39:14Z. **Review:** APPROVED --- Checked against main 522e32e3b6 and FreeBSD 11.4 kern_renameat: - It still merges cleanly with current main, and main has no ELOOP mapping in `RenameGuestPath` yet. - The reordered check after 0a238f9 matches the source-first order: a loop under the source gives ELOOP, and a loop under the destination gives ELOOP only when `SourceLookupError_nid_no_patch(source)` is 0. Renaming the loop link itself to a path under the loop also ends in ELOOP from the destination probe. - #8687 has landed, and `BelowSymbolicLinkLoop` is identical to `File::WindowsSymbolicLinkLoop` in libkernel's WindowsSymbolicLink.hpp:125. libc doesn't include libkernel headers today, so the private copy is fine here; a shared header could be a small follow-up. - I couldn't run the Windows cases; this is from reading the code, and your Developer Mode run covers the rest. Looks good to me. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8696
No description provided.