fix(libkernel): report ELOOP from sceKernelStat for Windows symbolic link loops #8149

Merged
JJenkx merged 1 commit from upstream-pr/8149 into main 2026-10-20 06:32:02 +00:00
JJenkx commented 2026-10-20 00:23:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-20T00:23:49Z.


What

On Windows, sceKernelStat of a symbolic link that resolves to itself returned 0x80020002 (ENOENT) instead of SCE_KERNEL_ERROR_ELOOP (0x8002003E), which the Linux build returns. std::filesystem::status reports such a link as not found, because the CRT maps ERROR_CANT_RESOLVE_FILENAME (1921) to ENOENT. When the status says the path does not exist, sceKernelStat now opens it once following links (CreateFileW, FILE_READ_ATTRIBUTES, FILE_FLAG_BACKUP_SEMANTICS) and returns ELOOP when Windows fails with ERROR_CANT_RESOLVE_FILENAME. Other failures still return ENOENT as before.

guest_filesystem already checks this case (line 899, added in #6992). It only runs where the user can create symbolic links (Developer Mode or administrator), so CI skips it. On such a machine main aborts there:

Filesystem check failed at line 899 (guest errno 2, Win32 error 1921)
FATAL: abort() (SIGABRT)

Tested

Windows 11 Enterprise 22621 (Developer Mode, so symbolic links can be created), WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, AMD Ryzen 9 5950X.

  • main 5907b297a: guest_filesystem fails with exit code 0xc0000409 at line 899 (above). The files involved are unchanged between 5907b297a and 34b1b77ab.
  • This branch on 34b1b77ab: guest_filesystem passes. ctest -R "guest_|libkernel|path|stat|file": 563 of 563 pass.
  • tools/check_conventions.py --base origin/main: passed. tools/pr_overlap.py: #5021, #7121, #7201 and #7332 also change Open.cpp and could not be compared automatically. Checked by hand: they change OpenNative, sceKernelClose and sceKernelRead, not sceKernelStat or the Windows helpers.

Rebased onto main a98590dec2 (2026-10-20), preserving its new NotFoundError_nid_no_patch ENOTDIR handling after the Windows loop check. No merge commits; refreshed head afec282b0f.

Retested on the same Windows machine and toolchain above, rebuilding guest_filesystem_tests for both revisions:

  • Current main a98590dec2: guest_filesystem fails at line 916, the self-referencing stat-loop ELOOP assertion (guest errno 2).
  • Rebased candidate afec282b0f: guest_filesystem passes (1/1, 0.28 s). This exercises symbolic-link creation; the loop case was not skipped.
  • tools/check_conventions.py --base origin/main and git diff --check: passed.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4929211600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8149). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-20T00:23:49Z. --- ### What On Windows, `sceKernelStat` of a symbolic link that resolves to itself returned `0x80020002` (ENOENT) instead of `SCE_KERNEL_ERROR_ELOOP` (`0x8002003E`), which the Linux build returns. `std::filesystem::status` reports such a link as not found, because the CRT maps `ERROR_CANT_RESOLVE_FILENAME` (1921) to ENOENT. When the status says the path does not exist, `sceKernelStat` now opens it once following links (`CreateFileW`, `FILE_READ_ATTRIBUTES`, `FILE_FLAG_BACKUP_SEMANTICS`) and returns ELOOP when Windows fails with `ERROR_CANT_RESOLVE_FILENAME`. Other failures still return ENOENT as before. `guest_filesystem` already checks this case (line 899, added in #6992). It only runs where the user can create symbolic links (Developer Mode or administrator), so CI skips it. On such a machine `main` aborts there: ``` Filesystem check failed at line 899 (guest errno 2, Win32 error 1921) FATAL: abort() (SIGABRT) ``` ### Tested Windows 11 Enterprise 22621 (Developer Mode, so symbolic links can be created), WinLibs GCC 15.2.0 r7 UCRT, Release, `BUILD_TESTING=ON`, AMD Ryzen 9 5950X. - `main` 5907b297a: `guest_filesystem` fails with exit code 0xc0000409 at line 899 (above). The files involved are unchanged between 5907b297a and 34b1b77ab. - This branch on 34b1b77ab: `guest_filesystem` passes. `ctest -R "guest_|libkernel|path|stat|file"`: 563 of 563 pass. - `tools/check_conventions.py --base origin/main`: passed. `tools/pr_overlap.py`: #5021, #7121, #7201 and #7332 also change `Open.cpp` and could not be compared automatically. Checked by hand: they change `OpenNative`, `sceKernelClose` and `sceKernelRead`, not `sceKernelStat` or the Windows helpers. Rebased onto `main` a98590dec250a754efd5eefd6a83b348e4b2a805 (2026-10-20), preserving its new `NotFoundError_nid_no_patch` ENOTDIR handling after the Windows loop check. No merge commits; refreshed head afec282b0f. Retested on the same Windows machine and toolchain above, rebuilding `guest_filesystem_tests` for both revisions: - Current main a98590dec2: `guest_filesystem` fails at line 916, the self-referencing `stat-loop` ELOOP assertion (`guest errno 2`). - Rebased candidate afec282b0f: `guest_filesystem` passes (1/1, 0.28 s). This exercises symbolic-link creation; the loop case was not skipped. - `tools/check_conventions.py --base origin/main` and `git diff --check`: passed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 00:34:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T00:34:25Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/File/src/Open.cpp
PR 7121 core/libs/prx/libkernel/File/src/Open.cpp
PR 7201 core/libs/prx/libkernel/File/src/Open.cpp
PR 7332 core/libs/prx/libkernel/File/src/Open.cpp
PR 7437 core/libs/prx/libkernel/File/src/Open.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6280492644 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8149#issuecomment-6280492644). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T00:34:25Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7437](https://www.github.com/boykopovar/AnyPS5/pull/7437) | `core/libs/prx/libkernel/File/src/Open.cpp` |
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!8149
No description provided.