fix(libkernel_sys): create symlinks with CreateSymbolicLinkW on Windows #3510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3510"
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 babyhuey on 2026-10-11T12:04:07Z.
What
Follow-up to #3491, which merged at its first head. Windows changes in libkernel_sys:
symlinkcreates links withCreateSymbolicLinkWandSYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE(plusSYMBOLIC_LINK_FLAG_DIRECTORYwhen the target is an existing directory).ERROR_PRIVILEGE_NOT_HELDgivesEPERM,ERROR_ALREADY_EXISTS/ERROR_FILE_EXISTSgiveEEXIST,ERROR_PATH_NOT_FOUNDgivesENOENT, and any other error throws.symlinkchecks for an existing name withGetFileAttributesW, which also sees a dangling link.readlinkon a path withFILE_ATTRIBUTE_REPARSE_POINTthrows (NotImplemented), the waylstatdoes since #2898, instead of returningEINVALfor a real link.Linux is unchanged: it keeps
std::filesystem.Why
MinGW's libstdc++ (WinLibs GCC 15.2) can't create or read Windows symbolic links:
std::filesystem::create_symlinkandread_symlinkreturnENOSYS, andsymlink_statusreports a new link as a regular file. So onmaineverysymlinkcall on Windows throws andguest_kernel_sysaborts:The first head of this PR fixed creation only. With Developer Mode on, @screamm and @santhoshkumar-dev found the test still failed after a real link was created, because
symlink_statusandread_symlinkdon't see Windows links; @Amoenus confirmed it 5/5. This head follows screamm's suggestions. On Windows the test checks the new links throughFILE_ATTRIBUTE_REPARSE_POINTandEEXISTon a second create, withoutreadlink. Reading a Windows link's target back (FSCTL_GET_REPARSE_POINT) is left for a later change, soreadlinkthrows there for now.Tested
This head (
6aa0b4fb):guest_kernel_syspasses 5/5 (--repeat until-fail:5), including the full round trip throughreadlink.symlinkreturnsEPERMand the test skips the success cases (also run by @Silverash-i8).EEXISTand dangling-link cases.maina11c8f7f: 5/5 by @screamm, through the same cases.main1e8fff68,guest_kernel_sysaborts on Windows with the error above.check_conventions.pypasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T12:14:36Z.
Windows run without Developer Mode, the case screamm's machine didn't cover: Windows 11, WinLibs GCC 15.2.0 r7, Release,
b2dae2admerged ontomain2220effb(together with #3485 and #3518; #3485 also changeslibkernel_sys/Export.cpp, and they merged without conflicts), full build.guest_kernel_syspasses. Onmainit aborts withsymlink: Function not implemented; with this PR,symlinkreturns -1 with errno 1 (EPERM) here, so the test takes its "symbolic links unavailable: the symlink success cases not tested" branch, and the error cases (missing directory, null target, empty path) pass. The non-GPU suite is 460/462:windows_exceptions(#3411) as onmain, andguest_ampr_markersonce (passed 5/5 on rerun, #3371).AI-assisted (Claude Code); I ran all of this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T12:26:32Z.
Passing on a finding from @santhoshkumar-dev on #3485, since it's about this PR: with Developer Mode on,
CreateSymbolicLinkWsucceeds andguest_kernel_systhen stops at the success branch'sRequire(std::filesystem::is_symlink(std::filesystem::symlink_status(symbolic))). My run above passed only because without Developer Mode it took the EPERM branch.I checked the cause here without creating a link, on the built-in
C:\Users\All Users, which is a real symbolic link (fsutil reparsepoint querygives tag0xa000000c,IO_REPARSE_TAG_SYMLINK). A program built with WinLibs GCC 15.2.0 r7 getsis_symlink(symlink_status(...)) == false(type reported as directory) andread_symlinkfails withFunction not implemented.So it isn't only the test:
readlink_nid_postfixuses the samesymlink_status/read_symlink, so on Windows a link that this PR'ssymlinkcreates would read back as EINVAL fromreadlink, and the next assert (readlink(...) == 12) would fail too. CI wouldn't show it yet, since the Windows job is skipped whileconventionsfails onmain, and GitHub's Windows runners can normally create symlinks, so they'd take the success branch. Options I can see: read the reparse point directly on Windows (FSCTL_GET_REPARSE_POINT) inreadlinkand check the round trip with that, or skip the success cases on MinGW the way the existing readlink link cases already are.AI-assisted (Claude Code); I ran the
All Userscheck on my machine. I haven't run the success branch itself, since I can't create symlinks here.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T12:28:57Z.
Windows validation of the current head
b2dae2admerged ontomain1e8fff68, with Developer Mode on (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Release), which is the branch nobody had run yet:CreateSymbolicLinkWsucceeds here for both the file and the directory link, so theEPERMskip is not taken, andguest_kernel_systhen aborts at the next check:Kernel sys check failed at line 133 (guest errno 2)(exit0xc0000409). A probe built with the same toolchain shows why: on this libstdc++std::filesystem::symlink_statusreports the new link as a regular file (is_symlinkfalse) andstd::filesystem::read_symlinkfails with error 40 (Function not implemented). So on WindowsreadlinkreturnsEINVALfor a real link, the existing-link check follows the link (a dangling link looks missing and the second create fails withERROR_ALREADY_EXISTS, which this PR throws instead of returningEEXIST), andlstatstill throws on reparse points (#2898).Two suggestions for this PR so it is green with Developer Mode on: map
ERROR_ALREADY_EXISTS/ERROR_FILE_EXISTStoEEXIST(andERROR_PATH_NOT_FOUNDtoENOENT), and make the test's post-creation checks on Windows use what the host supports (GetFileAttributesWreportingFILE_ATTRIBUTE_REPARSE_POINT, asNativeStat.cppdoes since #2898) rather thanreadlink/symlink_status, until a Windowsreadlinkreading the reparse data (FSCTL_GET_REPARSE_POINT) exists. Happy to rerun.Validation run with Claude Code assistance.
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T12:32:33Z.
Thanks @screamm, @Silverash-i8 and @santhoshkumar-dev, that's the case I couldn't run. I have a rework on
babyhuey:test/verify-symfix2(6aa0b4fb, one commit onmain1e8fff68), following screamm's suggestions:symlinkchecks for an existing name withGetFileAttributesWon Windows, which sees a dangling link too, and mapsERROR_ALREADY_EXISTS/ERROR_FILE_EXISTStoEEXISTandERROR_PATH_NOT_FOUNDtoENOENT.readlinkon a path withFILE_ATTRIBUTE_REPARSE_POINTthrows on Windows, aslstatdoes since #2898, instead of returningEINVALfor a real link.FILE_ATTRIBUTE_REPARSE_POINTon the new links andEEXISTon a second create, withoutreadlinkorsymlink_status.guest_kernel_syspasses 5/5 on Linux. I'll move it onto this PR once it also passes on Windows. @screamm, if you're still up for a Developer Mode run, that branch is the one to try.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T12:35:29Z.
@babyhuey the other half for
test/verify-symfix2(6aa0b4fb, as is on1e8fff68), without Developer Mode: Windows 11, WinLibs GCC 15.2.0 r7, Release.guest_kernel_syspasses 5/5 (--repeat until-fail:5).symlinkstill gives EPERM here, so it takes the "symbolic links unavailable" branch, and the error cases after it (missing directory, null target, empty name) pass with the newGetFileAttributesWcheck in front. The Developer Mode branch still needs screamm's run; I can't create symlinks on this machine.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T12:39:49Z.
Independent Windows validation (2026-10-11, Amoenus)
Confirmed the positive Windows creation path independently on Windows 11 Enterprise build 26200, WinLibs GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON:
2220effbeplus our existing integration prerequisites:guest_kernel_sysaborts atsymlink: Function not implemented.b2dae2adf102a26b62f0e99ef695e3612cb2a1ba: creation succeeds, then the fixture aborts atRequire(is_symlink(symlink_status(symbolic)))(our integration line 144). 5/5 serial invocations fail there, exit0xc0000409. This confirms the success-path problem already reported above; it is not areadlinkassertion failure yet.test/verify-symfix2, commit6aa0b4fb22d1745755c6bba983503a8801a27f3f, carried into the same integration: guest_kernel_sys passes 5/5 serial verbose runs, in addition to 5/5 in our parallel relevant-suite run. The new symlink EPERM/success-skip message never appears. The Windows creation block therefore exercises a relative regular-file link, duplicate EEXIST, dangling link, and duplicate dangling-link EEXIST, plus the existing null/empty/missing-parent checks.A separate host-only probe, rebuilt with the same toolchain, confirms the limitation on newly created links in 5/5 runs:
This validates the rework's creation/error paths. It does not validate Windows target readback: the rework explicitly throws for readlink of a reparse point. The older fixture's host-std-created link block still prints
symbolic links unavailable: the link cases not tested; that is separate from the new successful guest-symlink block. No directory-link positive case or PS5 hardware behavior was measured. I have not queried Developer Mode/elevation; native creation is simply allowed on this machine.Full build and all 122 patched system libraries succeed; all 19 selected relevant groups pass five times each (95 passes), including both filesystem groups, guest math/CRT/locale, pthread groups and AGC groups.
check_conventions.py --base 2220effbepasses. This is a combined integration, not an unchanged-main or full-suite claim. The rework's exact authored 47-insertion/8-deletion delta is retained; the only cherry-pick conflict was the include block, resolved by preserving our existing string_view include and adding its Windows include, without importing its parent's unrelated Linux fchdir changes.Reproducible integration source (authors retained; fork only, no PR created). AI-assisted execution and report: Codex. Controlled PPSA99902 comparison completed: two runs before (29.774s, 28.48s) and two after (28.886s, 28.611s) reach the same unsupported multisampled descriptor-shape guard, exit0xc0000409/no timeout. The122-library profiles differ only in libkernel_sys (121 byte-identical); fixed guarded f609 title conversion/guest libc in both. No observed startup advance from this change. Full title-validation details.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T12:43:17Z.
Progress report (
a11c8f7→6aa0b4f)📉 System libraries: 85.78% (-0.03%, -1 reverted functions)
⚠️ 1 went back to stubs
readlink_nid_postfixImported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T12:43:17Z.
Moved
test/verify-symfix2(6aa0b4fb) onto this PR, since it now has a Windows run with link creation allowed (thanks @Amoenus) as well as without it (thanks @Silverash-i8). I updated the description.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T13:27:28Z.
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.
main)core/libs/prx/libkernel_sys/Export.cppL17-18, L72, L124-125core/libs/prx/libkernel_sys/Export.cppL18core/libs/prx/libkernel_sys/Export.cppL30-32core/libs/prx/libkernel_sys/Export.cppL29-32Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T14:57:51Z.
Developer Mode run of
6aa0b4fb(the branch @babyhuey asked for), merged ontomaina11c8f7f(clean merge): Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,BUILD_TESTING=ON, full build includinglibs.AllowDevelopmentWithoutDevLicenseis 1 on this machine, soCreateSymbolicLinkWsucceeds here.guest_kernel_sys: passes 5/5 (--repeat until-fail:5). The "symlink success cases not tested" line does not appear, so the Windows creation block ran: regular-file link withFILE_ATTRIBUTE_REPARSE_POINT,EEXISTon the second create, dangling link,EEXISTon the second dangling create, then the missing-parent, null-target and empty-name errors. The only skip line is the pre-existing "symbolic links unavailable: the link cases not tested" from thereadlinkblock, where the test itself usesstd::filesystem::create_symlinkand MinGW's libstdc++ returnsENOSYS.maina11c8f7fthe same test aborts here withsymlink: Function not implemented.check_conventions.py --base origin/mainis clean.Unrelated:
guest_filesystemfails on this machine atGuestFilesystem.cpp:286(restoring the working directory's write time, errno 13 / Win32 error 5), onmainas well as with this PR. That is what #3518 addresses.AI-assisted (Claude Code); run on my machine.