fix(libc): open long Windows host paths #7187
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7187"
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 Amoenus on 2026-10-17T15:29:51Z.
What
Fixes #7182. PPSA99902 (Sonic Unleashed Recompiled, #3036 / discussion #4443) repeatedly fails to open an existing
WorldMap.arlwhen its resolved Windows host path is 266 characters. The guest path itself is short.OpenNativepasses the host spelling toCreateFileW, so a converted process without long-path opt-in gets ENOENT for a file that exists.Use the extended Unicode drive/UNC spelling for resolved absolute host paths crossing MAX_PATH. Preserve existing namespace prefixes, access/share/disposition flags and error handling. Ten added production lines and one replaced argument; no retry, fallback, environment switch, manifest change or title-specific path. Microsoft documents this CreateFileW path form. #4618 covers the relinker process, explicitly leaving converted executables unchanged.
This changes
fopen's native open helper, including modes that use it. It does not make every Windows file API long-path independent. UNC spelling follows the documented namespace form; no live network-share result is claimed.Tested
Current head
cf84fc44a8f969bb39cc079c0e9b8c7abfc27207, rebased onto main66702f1cffd3646f2d674ed093fde0a85a70761fafter #7068 merged. Full local relinker/system-library builds pass on Windows 11 Enterprise 26200 / WinLibs GCC 15.2.0 r7 and Ubuntu 24.04 / GCC 13.3, Release.fopen mode rb failed: guest errno=2, resolved characters=328. This historical control remains pinned to main84, not the new base. The fixture checks ordinary and already-extended long-path read bytes, creation, exclusive-existing refusal, append/update, missing-file ENOENT and relative-host-alias reads.Z:substitution and temp files onC:, pre-correctione61af865fails 3/3 with the exact CI signatureguest errno=20, resolved characters=11. Currenta44455b740passes 3/3 in that same split-drive setup, as well as normal CTest runs. The relative case temporarily uses its fixture root as cwd, requires a nonempty relative path, restores the original cwd with a scope guard and verifies restoration. The temporary drive mapping is removed after both controls. Each invocation completes well under 30 s.libc.prxdiffers; the executable, guest module, other126 PRXs and dependencies match. Fresh original assets/user data, equal-length runtime roots, original configurations/protected hashes unchanged. Verified RTX5080 / driver32.0.16.1062, Khronos1.4.363 loaded, zero observed validation errors/warnings. Intact samples show69 failed opens of the existing266-character.arlbefore the change and none after; interleaved records are excluded. Libc reads increase from30,095,141 to32,599,419 bytes. Both runs still show initial NOW LOADING at the harness limit (exit1): no menu/gameplay/FPS or title-unblock claim, and no unchanged-main whole-title claim.cf84fc44a8without parser/configuration failures. Clang-tidy has no selected diagnostics. Cppcheck retains 3 previously reviewed advisories in unchanged ownership-transfer/nullability code; no static-clean claim or unrelated cleanup.Duplicate/overlap review: #7068 has merged its errno translation; this branch is based on it. Open #6287 changes append access, #6541 random-device streams and #5668 standard-stream reopen failure handling. None supplies this conversion. Wider test reorganization (#6044) and platform work (#5021/#6222) may still require mechanical rebases; no dependency on them is bundled.
Review follow-up
MarcZX100 identified the throwing path-resolution edge. The helper uses
absolute(path, error_code)and returnsnullptron resolution failure. Following #7068's merge, it preserves host errno for the outer fopen entry point to translate once; it no longer maps an error to guest errno inside the helper. The unavailable-CWD branch has source review only, without fault injection.oneandonlydean identified the split-drive fixture failure in full Windows CI. Commit a44455b740 corrects that fixture, with matching local failing/passing controls above. Prior head3811's Windows CI failed this relative-alias case; those checks are not evidence for the new head. All automatic checks that ran pass on cf84, including relinker Windows/Linux/macOS. Full Windows/Linux application lanes were skipped; a fresh maintainer-triggered full run remains requested.
Additional namespace control at cf84fc44a8: validating #7196 exposed this toolchain's
absoluterewriting an existing extended namespace into an invalid path. The new fixture case fails 3/3 before the correction (errno22, resolved332 characters). Checking existing namespace prefixes beforeabsolutepreserves them; the full36/18 Windows/Linux passes and3 split-drive passes above were repeated on cf84. UNC spelling remains source-reviewed, without a live-share claim.The independent overlap review confirms #5668 and #6287 address separate behaviors. The title component evidence above retains its5675 source pin. The exact-runtime short-directory control reaches the older DCC/device-loss stops; #7195 separately confirms the remaining long-host-path metadata failure in
sceKernelStat, outside this PR.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 MarcZX10 on 2026-10-17T15:31:29Z.
One edge case to consider:
std::filesystem::absolute(path)uses the throwing overload here, but this call is insideOpenNativeandfopen_nid_postfixdoes not catchstd::filesystem::filesystem_erroraroundOpenNative(the nearbyfreopenpath does). If resolving the current directory fails, that can escape the Cfopenentry point instead of returningnullptrwitherrno. Could you use theerror_codeoverload and preserve the originalCreateFileWpath/failure behavior when making it absolute, or catch/map that exception? The normal resolved guest path succeeds in ordinary operation; this is a contract edge case, not a blocker for the reported long-path fix.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T15:36:11Z.
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.
core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/FileAndHeap.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/FileAndHeap.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/FileAndHeap.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/FileAndHeap.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:36:29Z.
Manual follow-up to the overlap report: #5668 changes failed
freopenbehavior inFileStream::Reopen/freopen_nid_postfixand adds a later standard-stream CTest registration; #7187 does not touch those paths, and its Windows CTest registration is in a separate block. #6287 also editsFileAndHeap.cpp, but its changes are append-only access rights, descriptor handling, and append tests; #7187 changes only the path spelling passed toCreateFileWinOpenNative. These are separate behaviors; the sharedFileAndHeap.cppcontext may need a mechanical rebase if both land. I manually checked these two substantive overlaps; the bot also lists CMake-only shared files on older conflicting branches.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:37:33Z.
Hosted checks have completed on head
115b10ef47ef4218ac3a7d482c7dc873a433d9e2: relinker passes on macOS, Ubuntu and Windows; conventions, eligibility, intake, report, register-context and write-watch checks also pass. The broader Linux and Windows application jobs were skipped by path filters, so this is relinker plus the focused checks, not a full application build.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-17T15:46:08Z.
@MarcZX100 addressed, now rebased onto main66702f1c in
a44455b74084eef4a5d7843f53d67b86a721364f.absolute(path, error_code)returnsnullptron resolution failure; after #7068's merge, the helper preserves host errno and the outer fopen entry point translates it once. The unavailable-CWD branch remains source-reviewed only.Current-head local builds, tests and analysis are in the description. The relative-alias fixture was additionally corrected after @oneandonlydean caught its cross-drive assumption in full Windows CI; the previous head's Windows result was a failure, now reproduced and corrected locally. Thanks for the reviews and overlap checks.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T15:51:01Z.
Full CI on 3811293e7 (run 39046442206): Linux is green, but Windows fails
guest_fopen_long_host_pathwithfopen mode rb failed: guest errno=20, resolved characters=11/fopen rejected a valid mapped long host path.This looks like the new relative-alias case (GuestFopenLongHostPath.cpp:99-106), not the fix itself. On the Windows runner ctest runs under
D:\a\AnyPS5, whiletemp_directory_path()is most likely onC:. Across drive rootsstd::filesystem::relative(deep, current_path())returns an empty path, so the alias maps to the cwd and the open fails. A single-drive local run can't show it.Could you make that case same-drive? For example, set
current_pathto the temp directory for that case and restore it afterwards, orRequire(!relative.empty())and build the relative path from a base on the same drive. The production change itself looks good.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-17T16:00:37Z.
@oneandonlydean confirmed; thank you for catching the split-drive assumption. I reproduced the exact
errno=20, resolved characters=11failure 3/3 with cwd on a temporaryZ:substitution and temp files onC:.Fixed in a44455b740: the relative case temporarily changes cwd to its fixture root, rejects an empty relative path, and restores/verifies the original cwd. The same split-drive control now passes 3/3; the substitution is cleaned up. Normal Windows CTest also passes.
The branch is rebased onto main66702f1c, including #7068's errno handling. Current-head full local relinker/library builds pass on Windows and Linux, with 36/18 focused passes respectively. Conventions/registration pass; static analysis has no new findings. Description updated with exact pins and coverage limits. Could you rerun full CI on this head?
Additional correction now at
cf84fc44a8f969bb39cc079c0e9b8c7abfc27207: while validating #7196, an independent existing-namespace control found that this toolchain'sabsoluterewrites an already-extended path. The same new case failed3/3 in our opener. We now preserve namespace prefixes before that operation. Full local Windows/Linux builds and36/18 focused passes, plus3 split-drive passes, are repeated on cf84; static analysis remains at3 unchanged-code Cppcheck advisories and no selected clang-tidy diagnostics, without parser failures. Please use cf84 for the requested full CI rerun. The description retains the earlier controls and their pins.