fix(libc): isolate host diagnostics from guest buffering #10020

Merged
Queuse merged 3 commits from upstream-pr/10020 into main 2026-10-24 02:22:02 +00:00
Queuse commented 2026-10-23 04:27:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-23T04:27:17Z.


What

On Windows, guest setvbuf(stderr, ..., _IOFBF, ...) also buffers host diagnostics until the guest flushes the stream. The same sharing affects stdout through setbuf.

Preserve a separate, unbuffered host stream before changing the guest standard stream's buffering. Reuse that retained descriptor when a later guest dup2 preserves the host destination. Guest output keeps its requested buffering and redirection. Preserve the native stream lock before taking the cache mutex, including calls made under guest flockfile.

The title logs discussed in #9941 were found in redirected files. This fix addresses the independently reproduced buffering defect; it is not evidence of the cause of those titles' missing runner output.

Tested

Windows 11 x86-64, WinLibs MinGW-w64 GCC 15.2.0-r7, Ninja, Release. Head d43043b6e5 includes main 097a9514a0.

  • Rebuilt the affected libraries and focused test targets. guest_standard_streams, guest_standard_streams_closed_stdout, guest_standard_streams_exclusive_stdout, file_streams, guest_host_standard_error_windows, guest_host_standard_buffering_windows, guest_host_streams: 7/7 pass, with no skips.
  • Conventions and whitespace checks pass. Trial integration with consulted main a23f8fc9fb is clean; runtime results remain tied to the included base 097a9514a0.

The existing regression fails on main 9d6adeb550 because the host marker remains buffered. This revision retains the stdout/stderr, guest-flush, dup2 and lock-held buffering coverage. Fresh overlap analysis has 29 shared-file comparisons blocked by other PRs' base conflicts; their inspected patches add neither these preservation helpers nor this buffering fixture. #9945 is a separate stream-initialization fix. #6044 changes test organization. The standalone head was not retested on Linux/macOS; no full product build, title or console run was performed.

Additional integration run: tree 5e44964f85 combines this buffering fix with the #9945 stream-initialization follow-ups on main 85f2f2d478. Rebuilt the affected libraries and tests: 10/10 Windows, 8/8 Ubuntu 26.04.1 under WSL2 (GCC 15.2.0), no skips. This includes closed/missing standard descriptors, an already rebound CRT stream, host buffering/redirection and guest_freopen_host_standard. The buffering implementation and fixture match head d43043b6e5; the combined tree additionally changes standard-stream initialization. A trial merge of the combined tree with consulted main d1fc16348e is clean. No game or full-suite run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4977806594 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10020). Originally posted by [Queuse](https://github.com/Queuse) on 2026-10-23T04:27:17Z. --- ### What On Windows, guest `setvbuf(stderr, ..., _IOFBF, ...)` also buffers host diagnostics until the guest flushes the stream. The same sharing affects `stdout` through `setbuf`. Preserve a separate, unbuffered host stream before changing the guest standard stream's buffering. Reuse that retained descriptor when a later guest `dup2` preserves the host destination. Guest output keeps its requested buffering and redirection. Preserve the native stream lock before taking the cache mutex, including calls made under guest `flockfile`. The title logs discussed in #9941 were found in redirected files. This fix addresses the independently reproduced buffering defect; it is not evidence of the cause of those titles' missing runner output. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 x86-64, WinLibs MinGW-w64 GCC 15.2.0-r7, Ninja, Release. Head `d43043b6e5` includes main `097a9514a0`. - Rebuilt the affected libraries and focused test targets. `guest_standard_streams`, `guest_standard_streams_closed_stdout`, `guest_standard_streams_exclusive_stdout`, `file_streams`, `guest_host_standard_error_windows`, `guest_host_standard_buffering_windows`, `guest_host_streams`: 7/7 pass, with no skips. - Conventions and whitespace checks pass. Trial integration with consulted main `a23f8fc9fb` is clean; runtime results remain tied to the included base `097a9514a0`. The existing regression fails on main 9d6adeb550 because the host marker remains buffered. This revision retains the stdout/stderr, guest-flush, dup2 and lock-held buffering coverage. Fresh overlap analysis has 29 shared-file comparisons blocked by other PRs' base conflicts; their inspected patches add neither these preservation helpers nor this buffering fixture. #9945 is a separate stream-initialization fix. #6044 changes test organization. The standalone head was not retested on Linux/macOS; no full product build, title or console run was performed. Additional integration run: [tree 5e44964f85](https://github.com/Queuse/AnyPS5/commit/5e44964f85d200f34b83d92d01b93e70839c702f) combines this buffering fix with the #9945 stream-initialization follow-ups on main `85f2f2d478`. Rebuilt the affected libraries and tests: **10/10 Windows**, **8/8 Ubuntu 26.04.1 under WSL2** (GCC 15.2.0), no skips. This includes closed/missing standard descriptors, an already rebound CRT stream, host buffering/redirection and `guest_freopen_host_standard`. The buffering implementation and fixture match head `d43043b6e5`; the combined tree additionally changes standard-stream initialization. A trial merge of the combined tree with consulted main `d1fc16348e` is clean. No game or full-suite run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-23 04:31:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:31:56Z.

Review: COMMENTED


Reviewed the current Windows stream-preservation diff and the submitted test evidence. The focused Windows matrix is valuable, and its scope is clear. I did not find a concrete blocking issue in this pass; hosted Linux and Windows product jobs are currently pending/skipped as reported, so I am not treating those as additional verification. The locking path is subtle: the new helper locks the native FILE before the cache mutex and the test exercises setvbuf while the guest stream lock is held, matching the deadlock concern described. Please keep the Windows jobs visible through completion.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623916429 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10020#pullrequestreview-5623916429). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T04:31:56Z. **Review:** COMMENTED --- Reviewed the current Windows stream-preservation diff and the submitted test evidence. The focused Windows matrix is valuable, and its scope is clear. I did not find a concrete blocking issue in this pass; hosted Linux and Windows product jobs are currently pending/skipped as reported, so I am not treating those as additional verification. The locking path is subtle: the new helper locks the native FILE before the cache mutex and the test exercises `setvbuf` while the guest stream lock is held, matching the deadlock concern described. Please keep the Windows jobs visible through completion.
MarcZX10 commented 2026-10-23 04:31:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:31:57Z.

Review: APPROVED


Reviewed the current exact head and the Windows/WSL focused test report. The change preserves the original host standard stream before guest buffering changes, and the tests cover immediate host output, delayed guest output, redirection, stdout/stderr, and lock-held buffering changes. CI convention, intake, labels, relinker, ASAN, register-context, and write-watch checks pass; Linux and Windows product jobs are skipped by current workflow policy. The report explicitly says full native-library builds and game runs were not performed. No blocking issue found in the reviewed scope.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623916538 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10020#pullrequestreview-5623916538). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T04:31:57Z. **Review:** APPROVED --- Reviewed the current exact head and the Windows/WSL focused test report. The change preserves the original host standard stream before guest buffering changes, and the tests cover immediate host output, delayed guest output, redirection, stdout/stderr, and lock-held buffering changes. CI convention, intake, labels, relinker, ASAN, register-context, and write-watch checks pass; Linux and Windows product jobs are skipped by current workflow policy. The report explicitly says full native-library builds and game runs were not performed. No blocking issue found in the reviewed scope.
Sign in to join this conversation.
No reviewers
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!10020
No description provided.