Repository navigation
fix(libc): keep host diagnostics on stderr when a guest redirects it on Linux - #4792
Merged
oneandonlydean merged 1 commit intoOct 13, 2026
Merged
Conversation
…on Linux On Linux a guest stderr redirect also moves the host's: guest descriptors are host descriptors, and the guest stderr stream wraps the host stderr FILE. After dup2(fd, 2), or freopen(path, mode, stderr) with full buffering, the libc terminate report, the host fprintf(stderr) diagnostics and libstdc++'s terminate message go into the title's pipe or file, and abort() discards what is still buffered. RetroArch (PPSA99169) reopens stderr onto app0/trace.txt with full buffering, so its stop on main left no message anywhere. Before the first guest redirect of descriptor 2 (libkernel dup2, libc freopen of a stream on descriptor 2), keep a close-on-exec duplicate of the host descriptor 2 and point the host stderr at an unbuffered stream on it. The guest stream keeps its own FILE and follows the redirect. The libc terminate report writes to the kept descriptor with write() instead of the stderr stream, and libkernel's sceKernelDebugOutText uses the same kept descriptor.
Contributor
|
Tested on Linux (Arch, kernel 7.2.5, GCC 16.2.1, Release), this PR (438d410) merged onto
Only this title was checked; no change in where it stops. Tested with Claude Code assistance. |
10 tasks done
This was referenced Oct 14, 2026
YossiYad
added a commit
to YossiYad/AnyPS5
that referenced
this pull request
Oct 15, 2026
…andard error A guest dup2 onto descriptor 2 keeps a close-on-exec duplicate of the host's standard error (boykopovar#4792), so the runtime's own output stays on the console while the title's stderr goes where the title pointed it. The duplicate did not survive LoadExec's execv, and the next executable started with descriptor 2 still on the title's redirect: its runtime output, terminate report included, went there. RetroArch (PPSA99169) points stderr at app0/trace.txt and then starts its picker. The picker's [gpu] and sceKernelDebugOutText lines landed in trace.txt, and its abort on an unconverted es-de.bin showed up nowhere; the message was found only in the core dump. Before execv, the kept descriptor now goes back onto descriptor 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(fix(libkernel): keep sceKernelDebugOutText off a redirected guest stderr #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, onmainee49621.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)