fix(libc): preserve host standard handles on Windows redirects #4640
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4640"
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 MarcZX10 on 2026-10-12T17:24:52Z.
What
Carries David's offered fix, preserving his original commit author. On Windows, before guest
dup2or_wfreopenreplaces descriptor 0, 1 or 2, the code preserves the corresponding Win32 standard handle if it aliases that CRT descriptor, then restores the standard handle after the redirect. Guest writes still go to the redirected descriptor; host writes throughGetStdHandlecontinue to reach the original host stream. This prevents crash and termination reports from being lost or redirected into title files.This is complementary to open PR #4536: that change keeps
sceKernelDebugOutTexton host stderr; this change protects Win32GetStdHandleconsumers and coversfreopen. The changes touch adjacentdup2logic andGuestFilesystem.cpp, but neither depends on the other; a small integration rebase may be needed whichever lands second.Tested
guest_filesystemandguest_duppass three runs; a full CTest rerun passed 971/971 after removingPYTHONHOME. A transientguest_audio_in_capturefailure passed six follow-up runs. The four reproduced titles now emit their stop reports instead of losing them; further catalog results are in issue #4631.guest_filesystemandguest_standard_streamspass 3/3.d592d54e; the rebase onto current main2a5eca11is patch-identical. I did not rerun builds or tests after rebasing.--windows-gui, or with a commercial title.Checklist
main; no other open PR implements the same behaviorNotImplemented_nid_no_patchImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:41:45Z.
The Windows results in the description are from the offered commit on
d592d54e; the rebased PR head was not rebuilt, and the current PR checks skip the Windows job. Could you runguest_filesystem(including the newdup2/freopencases) on this head and add the result? That would verify the Windows-only path against the currentmainbefore merge.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-12T20:48:42Z.
Ran it on Windows, and it was worth asking: the head as it is fails.
Head 44a5ebfc4 merged onto
main0428328b7(clean merge), Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release, full build:guest_filesystemfails,Filesystem check failed at line 279. That line is the[debug:1] keptcheck that #4536 added, not one of this PR's.Cause: a test-order clash, not the fix. #4536 keeps the host's standard error once per process, at the first
dup2_nid_postfix(..., 2)(PreserveHostStandardError). After the rebase this PR's block runs before that check and makes the first such call while descriptor 2 is on its own temporary file, so the latersceKernelDebugOutTextgoes to that file instead of the one #4536's check reads.Fixed commit:
DavidSamir:fix/libkernel-keep-host-stderr-handle-windowsis now a7fea811e, your 44a5ebfc4 cherry-picked ontomain0428328b7with one change: the Windows block inGuestFilesystem.cppis moved below the[debug:1] keptcheck. The changes to the four source files are the same as in 44a5ebfc4.With a7fea811e on
main0428328b7, same machine, full build each time:guest_filesystempasses 5/5 (--repeat until-fail:5).guest_standard_streams,file_streams,guest_dup,guest_fiopen,guest_poll,windows_exceptionsandguest_kernel_fcntlpass 3/3.FileStream.hpp,General.hpp,General.cppandStdio.cppas onmainand the test kept,guest_filesystemfails at this PR's check (Filesystem check failed at line 267, thecaptured && redirected && separate && written && restoredline); restored, it passes again.Not rerun for this comment: the title runs and the full
ctestfrom #4631, which were ond592d54e1.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:00:45Z.
Thanks for running the rebased Windows head and isolating the ordering issue. The failure is from #4536 capturing stderr before its check, because this PR reaches
dup2(..., 2)first; your a7fea811e commit moves the block after that check and the repeatedguest_filesystemruns support the fix. I’m going to carry that corrected source onto the current main and validate the Linux path, then update this PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:23:12Z.
Update: after the first rebase, upstream advanced again, so I am rebasing once more and rerunning the focused Linux tests. GitHub conventions pass. The eligibility check failed because the workflow hit GitHub API rate limiting (403 fetching PR metadata); this was not a code/build failure. I will update with the final head and test result.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:26:23Z.
Final rebase update: head
c22654102b5c7d981602fd1a1b22d25722ca807fis based on current upstream main584cc4c5716b02210ca031593d1a6b0b4ce049cb. After this rebase, Linux Releaseguest_filesystemandguest_duppassed (2/2), conventions passed, andgit diff --checkpassed. The earlier eligibility workflow run remains failed due GitHub API rate limiting (403), not a source check.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:40:12Z.
The refreshed hosted checks for head
c22654102have completed: conventions, eligibility, report, relinker on Ubuntu/macOS/Windows, register-context on Ubuntu/macOS, and write-watch on macOS passed. Linux, Windows, and some platform-specific jobs were skipped by the PR path filters. The PR is currently reported mergeable/clean.