fix(libkernel): report absolute Windows symbolic links #7111

Merged
mazen320 merged 3 commits from upstream-pr/7111 into main 2026-10-18 09:22:57 +00:00
mazen320 commented 2026-10-17 12:04:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-17T12:04:38Z.


What

lstat and readlink aborted when a Windows symbolic link was absolute, because only a relative reparse point was accepted. An absolute link now reports the text Windows stored for it. A reparse point that is not a symbolic link still throws.

Tested

Windows 11, WinLibs GCC 15.2.0, Release. guest_filesystem and guest_kernel_sys passed. Those tests create an absolute symbolic link and check lstat and readlink.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4899900142 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7111). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-17T12:04:38Z. --- ### What `lstat` and `readlink` aborted when a Windows symbolic link was absolute, because only a relative reparse point was accepted. An absolute link now reports the text Windows stored for it. A reparse point that is not a symbolic link still throws. ### Tested Windows 11, WinLibs GCC 15.2.0, Release. `guest_filesystem` and `guest_kernel_sys` passed. Those tests create an absolute symbolic link and check `lstat` and `readlink`. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 12:17:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T12:17:01Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7202 core/libs/prx/libkernel/File/src/NativeStat.cpp L54-56

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/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 6044 core/libs/tests/GuestFilesystem.cpp
core/libs/tests/GuestKernelSys.cpp
PR 6222 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 6447 core/libs/prx/libkernel_sys/Export.cpp
PR 6879 core/libs/prx/libkernel/File/src/NativeStat.cpp
PR 7201 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 7332 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
core/libs/tests/GuestKernelSys.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233779239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7111#issuecomment-6233779239). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T12:17:01Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7202](https://www.github.com/boykopovar/AnyPS5/pull/7202) | `core/libs/prx/libkernel/File/src/NativeStat.cpp` [L54-56](https://github.com/boykopovar/AnyPS5/blob/1c523bdb48f724c06d0f526ddfbcd4c3a22bbea0/core/libs/prx/libkernel/File/src/NativeStat.cpp#L54-L56) | | | 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/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp`<br>`core/libs/tests/GuestKernelSys.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/File/src/NativeStat.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp`<br>`core/libs/tests/GuestKernelSys.cpp` |
oneandonlydean commented 2026-10-17 12:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T12:29:02Z.


@mazen320 the code reads well, but full CI on 6ad392dad fails the new Windows check in guest_kernel_sys. Linux skips these cases, so the Windows job is the only one that exercises them. Main passes the same test.

From the Windows job (run 39031823008):

symbolic links unavailable: the link cases not tested
...
Kernel sys check failed at line 294 (guest errno 0)
FATAL: abort() (SIGABRT)

Line 294 is the new absolute-link length check: readlink_nid_postfix(root / "absolute") == absoluteTarget.size(). So CreateSymbolicLinkW succeeded, but readlink returned a different length than std::filesystem::absolute(original).generic_string().

One guess, unconfirmed: the runner's temp directory is an 8.3 short path (C:\Users\RUNNER~1\...). std::filesystem::absolute keeps the short form, while the target you return may be the expanded long form, or vice versa (a \\?\ prefix or drive-letter case would also do it). Printing both strings on failure would show which one it is. Comparing against the canonical/long path of the target, or the exact string you passed to CreateSymbolicLinkW, should make the check stable.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233884140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7111#issuecomment-6233884140). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T12:29:02Z. --- @mazen320 the code reads well, but full CI on 6ad392dad fails the new Windows check in `guest_kernel_sys`. Linux skips these cases, so the Windows job is the only one that exercises them. Main passes the same test. From the Windows job (run 39031823008): ``` symbolic links unavailable: the link cases not tested ... Kernel sys check failed at line 294 (guest errno 0) FATAL: abort() (SIGABRT) ``` Line 294 is the new absolute-link length check: `readlink_nid_postfix(root / "absolute") == absoluteTarget.size()`. So `CreateSymbolicLinkW` succeeded, but `readlink` returned a different length than `std::filesystem::absolute(original).generic_string()`. One guess, unconfirmed: the runner's temp directory is an 8.3 short path (`C:\Users\RUNNER~1\...`). `std::filesystem::absolute` keeps the short form, while the target you return may be the expanded long form, or vice versa (a `\\?\` prefix or drive-letter case would also do it). Printing both strings on failure would show which one it is. Comparing against the canonical/long path of the target, or the exact string you passed to `CreateSymbolicLinkW`, should make the check stable.
MarcZX10 commented 2026-10-17 16:17:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T16:17:25Z.


I opened #7202 to prepare Windows native paths for lstat when the host path exceeds MAX_PATH. It touches the same DoLstat call sites as this PR, while your change broadens the reparse-point reader to absolute symlinks. The behavior is compatible, but the patches overlap in NativeStat.cpp. Are you comfortable with #7111 merging first? I can rebase #7202 on it afterward; neither change depends semantically on the other.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6236476563 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7111#issuecomment-6236476563). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T16:17:25Z. --- I opened #7202 to prepare Windows native paths for `lstat` when the host path exceeds `MAX_PATH`. It touches the same `DoLstat` call sites as this PR, while your change broadens the reparse-point reader to absolute symlinks. The behavior is compatible, but the patches overlap in `NativeStat.cpp`. Are you comfortable with #7111 merging first? I can rebase #7202 on it afterward; neither change depends semantically on the other.
MarcZX10 commented 2026-10-17 16:21:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T16:21:51Z.


I see the follow-up commits now compare the absolute target by the file it names and use a larger sentinel buffer, which removes the exact-length assumption that failed in the earlier Windows run. The remaining absoluteTarget.find('?') check will also expose an NT namespace prefix if the reparse print name contains one; if the rerun still fails, printing the returned target alongside the input passed to CreateSymbolicLinkW should distinguish that from a short-name/canonicalization difference. I haven't run this on Windows, so this is source review rather than a new runtime result.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6236539754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7111#issuecomment-6236539754). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T16:21:51Z. --- I see the follow-up commits now compare the absolute target by the file it names and use a larger sentinel buffer, which removes the exact-length assumption that failed in the earlier Windows run. The remaining `absoluteTarget.find('?')` check will also expose an NT namespace prefix if the reparse print name contains one; if the rerun still fails, printing the returned target alongside the input passed to `CreateSymbolicLinkW` should distinguish that from a short-name/canonicalization difference. I haven't run this on Windows, so this is source review rather than a new runtime result.
mazen320 commented 2026-10-18 09:00:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-18T09:00:10Z.


Yes. #7273 now depends on this and uses these helpers for directory junctions. Merging this first is what we want.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6247975274 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7111#issuecomment-6247975274). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-18T09:00:10Z. --- Yes. #7273 now depends on this and uses these helpers for directory junctions. Merging this first is what we want.
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!7111
No description provided.