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

Closed
opened 2026-10-30 12:54:41 +00:00 by medazizktata · 0 comments
medazizktata commented 2026-10-30 12:54:41 +00:00 (Migrated from github.com)
Contributor

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 for stderr), AnyPS5's own log lines go into the title's file instead of the console. That includes the [present] lines from APS5_PROFILE_DRAW=1, the [src/...] traces and [pipeline-cache]. On Windows the console log ends at Transferring 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) does freopen(HUI_LOG_PATH, "w", stdout) and freopen(HUI_LOG_PATH, "a", stderr) with HUI_LOG_PATH = /download0/hui/dev/app.log. I did not read the other five's source.

Title Catalog version File that receives AnyPS5's log [present] lines in it (one per 10 s) lines starting [src/, [pipeline-cache] or [log]
ORION Media Center (PPSA99062) 01.105.000 download0/hui/dev/app.log 5 354
PSCord (PPSA99190) 01.000.010 data/ps5discord/app.log 5 227
Alembic (PPSA99594) 0.3.2 download0/hui/dev/app.log 5 78
MacheteSaveGameManager (PPSA99700) 1.3.11 download0/hui/dev/app.log 5 229
Estante (PPSA99841) 0.5.5 download0/hui/dev/app.log 5 49
Trophy Manager (PPSA99842) 0.1.1 download0/hui/dev/app.log 5 49

In 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.md for CD Player, Afterglow and Surround Sound Studio ("run.log ends at Transferring control to ELF entry point while 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 their app.log held 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's stdout/stderr wrap the same FILE. A guest dup2 onto descriptor 1 or 2 keeps the host streams first (Stdio.cpp, #7807), and so does setvbuf (#10020). freopen does not:

  • Windows: the Windows branch of 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.
  • Linux: Reopen keeps descriptor 2 only (FileStream.hpp:236, from #4792), so stderr is fine but stdout lines follow the guest.

#4640 (#4631) preserved the Win32 standard handles across freopen, which covers the crash reports and [notification] lines that write through GetStdHandle, not the CRT streams. I found nothing for routine logging after freopen in the code or in docs/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 --windows and run for 60 s. Also a minimal libc test, in the pull request that fixes this.

AnyPS5 commit

Titles: main edb4e4e3c; Trophy Manager and PSCord again on main 66b8e907e (10 min) and a5939f10a (ANYPS5_LOG_FILE, 120 s). Minimal test: main a5939f10a.

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

relinker --windows --registry eboot.elf app.exe      (via tools/audit_dump.py --windows)
set APS5_PROFILE_DRAW=1
set APS5_NO_PAD_INPUT=1
app.exe > run.log 2>&1

After 60 s, run.log ends at the entry point, and findstr "[present]" download0\hui\dev\app.log shows 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 freopen its stdout and stderr to 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

  • The redirect: Trophy Manager's source, src/runtime/runtime_shims.c lines 33-42.
  • AnyPS5's lines are inside the title files for all six (counts above).
  • The minimal test, on Windows and Linux (above).
  • ANYPS5_LOG_FILE on Windows, Trophy Manager and PSCord (above).

Not checked

  • A real title on Linux (no desktop session on my Linux machine).
  • macOS.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6119447332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/13328). Originally posted by [medazizktata](https://github.com/medazizktata) on 2026-10-30T12:54:41Z. --- ### What happens Once a title calls `freopen(path, "w", stdout)` (or the same for `stderr`), AnyPS5's own log lines go into the title's file instead of the console. That includes the `[present]` lines from `APS5_PROFILE_DRAW=1`, the `[src/...]` traces and `[pipeline-cache]`. On Windows the console log ends at `Transferring 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) does `freopen(HUI_LOG_PATH, "w", stdout)` and `freopen(HUI_LOG_PATH, "a", stderr)` with `HUI_LOG_PATH` = `/download0/hui/dev/app.log`. I did not read the other five's source. | Title | Catalog version | File that receives AnyPS5's log | `[present]` lines in it (one per 10 s) | lines starting `[src/`, `[pipeline-cache]` or `[log]` | |---|---|---|---|---| | ORION Media Center (PPSA99062) | 01.105.000 | `download0/hui/dev/app.log` | 5 | 354 | | PSCord (PPSA99190) | 01.000.010 | `data/ps5discord/app.log` | 5 | 227 | | Alembic (PPSA99594) | 0.3.2 | `download0/hui/dev/app.log` | 5 | 78 | | MacheteSaveGameManager (PPSA99700) | 1.3.11 | `download0/hui/dev/app.log` | 5 | 229 | | Estante (PPSA99841) | 0.5.5 | `download0/hui/dev/app.log` | 5 | 49 | | Trophy Manager (PPSA99842) | 0.1.1 | `download0/hui/dev/app.log` | 5 | 49 | In 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.md` for CD Player, Afterglow and Surround Sound Studio ("`run.log` ends at `Transferring control to ELF entry point` while 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 their `app.log` held 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's `stdout`/`stderr` wrap the same `FILE`. A guest `dup2` onto descriptor 1 or 2 keeps the host streams first (`Stdio.cpp`, #7807), and so does `setvbuf` (#10020). `freopen` does not: - **Windows:** the Windows branch of `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. - **Linux:** `Reopen` keeps descriptor 2 only (`FileStream.hpp:236`, from #4792), so `stderr` is fine but `stdout` lines follow the guest. #4640 (#4631) preserved the Win32 standard handles across `freopen`, which covers the crash reports and `[notification]` lines that write through `GetStdHandle`, not the CRT streams. I found nothing for routine logging after `freopen` in the code or in `docs/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 --windows` and run for 60 s. Also a minimal libc test, in the pull request that fixes this. ### AnyPS5 commit Titles: `main` `edb4e4e3c`; Trophy Manager and PSCord again on `main` `66b8e907e` (10 min) and `a5939f10a` (`ANYPS5_LOG_FILE`, 120 s). Minimal test: `main` `a5939f10a`. ### 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 ``` relinker --windows --registry eboot.elf app.exe (via tools/audit_dump.py --windows) set APS5_PROFILE_DRAW=1 set APS5_NO_PAD_INPUT=1 app.exe > run.log 2>&1 ``` After 60 s, `run.log` ends at the entry point, and `findstr "[present]" download0\hui\dev\app.log` shows 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 `freopen` its `stdout` and `stderr` to 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 - The redirect: Trophy Manager's source, `src/runtime/runtime_shims.c` lines 33-42. - AnyPS5's lines are inside the title files for all six (counts above). - The minimal test, on Windows and Linux (above). - `ANYPS5_LOG_FILE` on Windows, Trophy Manager and PSCord (above). ### Not checked - A real title on Linux (no desktop session on my Linux machine). - macOS. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#13328
No description provided.