fix(libc): keep host diagnostics on stderr when a guest redirects it on Linux #4792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4792"
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 marshmll on 2026-10-12T22:05:16Z.
What
The Linux side of #4631. On Linux a guest stderr redirect also moves the host's: guest descriptors are host descriptors, and the guest
stderrstream wraps the hoststderrFILE(_Stderr_nid_postfix{stderr}, andFileStream::Reopenrunsstd::freopenon it). After a guestdup2(fd, 2), orfreopen(path, mode, stderr)followed bysetvbufwith full buffering, the libc terminate report (RawWriteusesfwrite(..., stderr)on Linux), the hostfprintf(stderr, ...)diagnostics and libstdc++'s terminate message go into the title's pipe or file, andabort()drops what is still buffered.RetroArch (PPSA99169) does exactly this: its trace says
stderr is the trace file (buffered, flushed every 250 ms). Onmainit aborts with nothing on the console and nothing inapp0/trace.txt; the stop was only found with gdb. With this change the console shows:The same happened with ps5-opengl (PPSA99005): with write watch unavailable, its
FATAL: an address-based build copies 328 MiB ...landed in its owndownload0/ps5-opengl.loginstead of the console.libc(General.cpp, Linux only):KeepHostStandardError_nid_no_patch()keeps a close-on-exec duplicate of host descriptor 2 once, before the first guest redirect, and points the hoststderrat an unbuffered stream on it. The guest stream keeps its ownFILEand follows its redirect as on FreeBSD. If descriptor 2 is closed there is nothing to keep.libc(FileStream::Reopen, Linux branch): keeps it before reopening a stream on descriptor 2.libkernel(dup2, Linux branch):PreserveHostStandardErrortakes the same kept descriptor instead of its owndup(2), sosceKernelDebugOutText(#4536) and the rest of the host output share it.libc(RawWrite, Linux branch): writes the terminate report to the kept descriptor withwrite(), without the stream lock or buffering, as its comment already asks.guest_host_standard_errortest (Unix): in forked children, a guestdup2and a guestfreopen+ full buffering, each with a hostfputs(stderr)and with an uncaught exception. The host output and thewhat():line must reach the original stderr, and the guest output its redirect.Windows code is unchanged; #4640 covers it there. The two touch neighbouring lines in
FileStream.hpp,General.hpp,General.cppandStdio.cppbut no hunk overlaps; whichever lands second may need a trivial rebase.Tested
Fedora 44, GCC 16.2.1, Release with
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON, AMD RX 9060 XT (RADV) and lavapipe, onmainee4962190.guest_host_standard_errorfails without the library changes (the hostfputsafter a guestdup2never reaches the original stderr) and passes with them.guest_host_standard_error,guest_filesystem,guest_dup,exception_runtime,guest_standard_streams,file_streams,guest_fiopen,guest_syslog,guest_formattingpass.cteston lavapipe before the rebase: 994/995.agc_compute_pipeline_replayfails on Mesa 26.2.4 lavapipe (replay did not export a pipeline cache header) and passes on RADV; it does not use stderr.guest_video_out_high_frame_rateskips because the local display has no 120 Hz mode.python3 tools/check_conventions.py --base origin/mainpasses.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 nicolasfalesy on 2026-10-13T02:09:41Z.
Tested on Linux (Arch, kernel 7.2.5, GCC 16.2.1, Release), this PR (
438d41082) merged ontomain37dd48308, with ProsperoLight (PPSA99002, catalog release, relinked with--to-intel):main: the title aborts (exit 134) and the log has nowhat()line; the throw is only visible ingdb(File::Fcntl→Classify).Only this title was checked; no change in where it stops.
Tested with Claude Code assistance.