libc: after a guest freopen of stdout or stderr, AnyPS5's own log goes into the title's file (Windows: both streams; Linux: stdout) #13328
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 medazizktata on 2026-10-30T12:54:41Z.
What happens
Once a title calls
freopen(path, "w", stdout)(or the same forstderr), AnyPS5's own log lines go into the title's file instead of the console. That includes the[present]lines fromAPS5_PROFILE_DRAW=1, the[src/...]traces and[pipeline-cache]. On Windows the console log ends atTransferring control to ELF entry point, so a run looks frozen although the title is drawing. The title's own output going to its file is expected; AnyPS5's diagnostics going there is not.Six catalog titles do this at start-up. All six log HUI start-up lines (
[HUI] entry); five write/download0/hui/dev/app.log. In Trophy Manager's source the HUI runtime (src/runtime/runtime_shims.c, lines 33-42) doesfreopen(HUI_LOG_PATH, "w", stdout)andfreopen(HUI_LOG_PATH, "a", stderr)withHUI_LOG_PATH=/download0/hui/dev/app.log. I did not read the other five's source.[present]lines in it (one per 10 s)[src/,[pipeline-cache]or[log]download0/hui/dev/app.logdata/ps5discord/app.logdownload0/hui/dev/app.logdownload0/hui/dev/app.logdownload0/hui/dev/app.logdownload0/hui/dev/app.logIn each, the console (
run.log) has 3 lines and nothing after the entry point, while the title wrote 17 to 39 pipeline-cache files. PSCord's and Trophy Manager's[present]lines report about 500 to 600 presents per 10 s. The other 18 catalog titles in the same run keep their AnyPS5 log on the console.#13024 documented the same symptom in
docs/dev/GAME_TESTING.mdfor CD Player, Afterglow and Surround Sound Studio ("run.logends atTransferring control to ELF entry pointwhile the title keeps running"). The title's own output belongs in that file; AnyPS5's own lines do not.ANYPS5_LOG_FILE(#12715) loses them too. With it set, Trophy Manager's and PSCord's copy files held 4 lines each after 120 s (the[log]header and the 3 lines before the entry point), while theirapp.logheld 11[present]lines and 45 and 142[src/...]lines.Why
AnyPS5's log writes to the C runtime's
stdout/stderr(LogMacros.hpp:99-100,AsyncLog.hpp:240), and the guest'sstdout/stderrwrap the sameFILE. A guestdup2onto descriptor 1 or 2 keeps the host streams first (Stdio.cpp, #7807), and so doessetvbuf(#10020).freopendoes not:FileStream::Reopen(FileStream.hpp) never keeps either stream. It moves the title's file onto descriptor 1 or 2 with_dup2, and AnyPS5's later lines follow it.Reopenkeeps descriptor 2 only (FileStream.hpp:236, from #4792), sostderris fine butstdoutlines follow the guest.#4640 (#4631) preserved the Win32 standard handles across
freopen, which covers the crash reports and[notification]lines that write throughGetStdHandle, not the CRT streams. I found nothing for routine logging afterfreopenin the code or indocs/dev/debt/libc.md.Title, test or build step
The six titles above, from the homebrew catalog (sha256 matching the catalog), relinked with
tools/audit_dump.py --windowsand run for 60 s. Also a minimal libc test, in the pull request that fixes this.AnyPS5 commit
Titles:
mainedb4e4e3c; Trophy Manager and PSCord again onmain66b8e907e(10 min) anda5939f10a(ANYPS5_LOG_FILE, 120 s). Minimal test:maina5939f10a.System
Windows 11 Pro 10.0.26200, i5-12600KF, NVIDIA GeForce RTX 4060, WinLibs GCC 15.2.0 r7, Release.
Linux: Pop!_OS 24.04 LTS, x86-64, GCC 13.3.0, Release.
Steps to reproduce
After 60 s,
run.logends at the entry point, andfindstr "[present]" download0\hui\dev\app.logshows the frame lines.Without a title: a test that points descriptors 1 and 2 at a file standing in for the console, has the guest
freopenitsstdoutandstderrto two files, then writes one host line to each stream. It fails 3/3 on Windows on all four checks (host stdout and stderr lines land in the guest files and miss the console), and 3/3 on Linux on stdout only.What was checked
src/runtime/runtime_shims.clines 33-42.ANYPS5_LOG_FILEon Windows, Trophy Manager and PSCord (above).Not checked
AI-assisted: yes (Claude Code)