Windows: crash reports are lost or land in a title's own file after the guest moves descriptor 2 (dup2, freopen); four catalog titles abort with no message; fix branch ready #4631
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 DavidSamir on 2026-10-12T17:03:39Z.
On Windows, once a title moves descriptor 2 with
dup2(fd, 2)orfreopen(..., stderr), the crash report and the terminate message of the process are lost, or are written into one of the title's own files. Four catalog titles abort this way onmainwith nothing on stderr, so their real stop cannot be read from a log. #4536 names this for SwanStationPS5 ("aborts ... with no report ... This PR does not change that"); this is a fix for that part.What happens.
CrashReport.cpp, the exception runtime (Runtime.cpp) and the[notification]writer inNotification.cppwrite throughGetStdHandle(STD_ERROR_HANDLE). The C runtime's_dup2and_wfreopenclose the handle behind descriptor 2, and in a relinked executable the Win32 standard handle keeps the closed value. Watched with gdb onmaind592d54e1, with a breakpoint onNtClosefor the valueGetStdHandle(STD_ERROR_HANDLE)had at start:dup2_nid_postfix→_dup2. At the abortGetStdHandle(STD_ERROR_HANDLE)still returns that value andGetFileTypeof it is 0, so the report goes nowhere.freopen_nid_postfix→_wfreopen. By the abort the same handle value belongs to another file, and the whole report (terminate lines,FATAL: abort(), the stacks of all threads) is in the title'sdownload0/profiles/10000000/logs/app.log.In a test executable, which has the C runtime start-up, the same
_dup2instead movesSTD_ERROR_HANDLEto the guest's new handle, the pipe. I did not look into why the two differ; the fix covers both.Titles, relinked once, run with the libraries of
maind592d54e1and of the branch:mainwhat(): poll: descriptor 3 is not a socket,FATAL: abort() (SIGABRT)and the stackswhat(): poll: descriptor 6 is not a socketwhat(): poll: descriptor 7 is not a socketwhat(): fcntl: record locks are not implemented on Windows, command=12, fd=3and the stacksThe
pollstop is what #3644 is about. The ProsperoRadio stop was not visible in any log before. SwanStationPS5 and ProsperoRadio abort at a time that varies: in one 35 s run each was still running with both sets of libraries, and SwanStationPS5 once ran 45 s withmain's.Fix, ready to cherry-pick.
DavidSamir:fix/libkernel-keep-host-stderr-handle-windows(7f1188186, one commit onmaind592d54e1, five files, +63/-1). I can't open it as a PR while #4532 is open (one open PR without a merged one).Windows only. Before
_dup2replaces descriptor 0, 1 or 2, and before_wfreopenreopens a stream on one of them,HostStandardHandle_nid_no_patchtakes the Win32 standard handle of that descriptor: a duplicate when it is still the handle the descriptor owns, the handle itself when it was already kept. After the callKeepStandardHandle_nid_no_patchsets it as the standard handle again. The host's reports keep going where the process's standard error went at start, the guest's descriptor goes where the guest moved it, and the two no longer share a handle that the other side can close. A process started without standard handles is left alone. Later moves of the same descriptor reuse the kept handle, so nothing accumulates.This is the same direction as #4536, which keeps
sceKernelDebugOutTexton the host's standard error after the guest'sdup2; it does not depend on it. The two touch the samedup2lines inStdio.cppand both add adup2_nid_postfixdeclaration toGuestFilesystem.cpp, so whichever lands second needs a small rebase, which I can do.Not covered: a guest that closes descriptor 2 and opens another file onto it, and
fclose(stderr). Linux is not changed.guest_filesystemgains a Windows check for both paths: with the host's descriptor 2 on a temporary file, the guest moves descriptor 2 onto a pipe withdup2, or onto a file withfreopen; a write throughGetStdHandle(STD_ERROR_HANDLE)must reach the temporary file, the standard handle must not be the guest's new handle, and a guestwrite(2, ...)must reach the pipe or the file.Checked on Windows (7f1188186 on
maind592d54e1, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release):mainand the new check kept,guest_filesystemfails at it (Filesystem check failed at line 231). With the fix it passes 5/5 (--repeat until-fail:5);guest_standard_streams,file_streams,guest_dup,guest_fiopen,guest_pollandwindows_exceptionspass.download0holds no file with a crash report in it.pollstop in both.ctest --parallel 4: 971 tests. 109 failed in my first run, in a shell that still had this machine'sPYTHONHOMEset, which breaks the Python-driven tests; rerun without it, all 109 pass. One of the 109 is not Python-driven:guest_audio_in_captureexited 0xc0000409 once in the parallel run and passed 6 of 6 afterwards; I did not find the cause.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchlists #3872, #4391, #4516 and #4536 for neighbouring lines inStdio.cppandFileStream.hpp; none of them changes the standard handles.Checked on Linux (same commit, WSL2 Ubuntu 24.04, GCC 13.3.0, Release):
guest_filesystemandguest_standard_streamspass 3/3. Only those targets andlibswere built there; the new check is Windows only.Not checked on a console, with a
--windows-guibuild, or with a commercial title.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:43:40Z.
The ready branch behavior is now carried by open PR #4640, which preserves the host standard handles across guest
dup2andfreopen; its current head is clean and has passing hosted build/conventions checks. I checked the file list and implementation: this issue is covered by that PR, so I am not opening a duplicate.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T07:37:59Z.
Closing: fixed by #4640 (Windows) and #4792 (Linux). Reopen with the title if a crash report is still lost on current main.