Windows: after a guest dup2 onto descriptor 2, host stderr logging fills the guest's 4 KiB pipe; Eternal Darkness (PPSA99314) stalls at start-up #7791

Closed
opened 2026-10-19 07:46:51 +00:00 by babyhuey · 0 comments
babyhuey commented 2026-10-19 07:46:51 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-19T07:46:51Z.


Eternal Darkness (PPSA99314, homebrew catalog) sometimes stops drawing at start-up on Windows: the window title stays at FPS: 0.00 (17) for the whole run. On main 64a9caa62 (Windows 11, RTX 3080, WinLibs GCC 15.2, Release) that happened in 5 of 28 runs of 30 s (an earlier build, 4ffb0cd12, stalled in 1 of 5 runs of 60 s); the other runs reach about 14 fps. In every stall the log ends after two RunThread lines, where normal runs print the first StorageTexture line next.

The title moves its standard error into a pipe and forwards what it reads to the kernel log: it logs starts (standard error to klog: yes), and it imports pipe, dup2, fdopen and read. Guest descriptors are host CRT descriptors, so its dup2 replaces the host's descriptor 2 as well. In one stall descriptor 1 was also a pipe although stdout had been redirected to a disk file at launch, so the title appears to replace standard output the same way.

2585eeb7e already keeps a copy of the host's standard error so sceKernelDebugOutText does not write into the guest's pipe (there, to stop a title from reading its own debug output back and logging it again). Since 438d41082, on Linux PreserveHostStandardError goes through KeepHostStandardError_nid_no_patch, which also points the process's stderr at that copy. On Windows it only takes _dup(2): c22654102 restores the Win32 standard handle with SetStdHandle, but the CRT's stderr stream still writes through descriptor 2. So the host's own fprintf(stderr, ...) calls keep writing into the guest's pipe, and pipe_nid_postfix creates that pipe with a 4096-byte buffer (_pipe(native, 4096, _O_BINARY)).

What two stalled processes showed. In the first I used gdb, including inferior calls for _get_osfhandle and GetFileType, which killed the process afterwards. In the second I only read registers and stacks, and used a separate probe process that duplicates the process's handles and queries each pipe with a timeout.

  • A thread in AgcDriver::Graphics::StorageTexture::Refresh() is blocked in ZwWriteFile under fwrite and __mingw_fprintf. Every direct print in Refresh() is an fprintf(stderr, ...) (the [upload], [dcc-keys] and [gpu] lines). In the first stall its handle was _get_osfhandle(2), a pipe (GetFileType = 3).
  • The process's standard handles in its PEB are not pipes, as expected since dup2_nid_postfix restores them with SetStdHandle; the redirection lives in the CRT descriptor table.
  • Of the six 4096-byte anonymous pipe ends in the second stall, one read end has 4097 bytes waiting and no read pending on it. The pipe names are empty, so the write end to read end pairing is inferred, but the other two read ends each have a sceKernelRead blocked on them, so the blocked write is almost certainly on the full pipe.
  • Three more threads are waiting in RtlEnterCriticalSection under fwrite, consistent with the stderr stream lock the writer holds: a guest vfprintf (vfprintf_nid_postfix), AgcDriver::AsyncLog::Housekeeping() (the async logger thread, so the stdout lines such as StorageTexture ... stop too) and ShaderDiskCache::DiskStore::report.

So host log lines fill the guest's pipe and nothing drains it. Guest frames have no symbols, so I could not show which thread the title uses to drain it. If it is the guest vfprintf thread waiting for the lock, the wait never ends; if not, the drainer is stuck elsewhere. Either way the host's own logging is what fills the pipe. In a separate, earlier stall capture the main thread and one other thread were spinning at 100% CPU in TimedWait code, presumably waiting for work behind this.

From the code, Linux should not be affected the same way: there the process's stderr points at the kept copy once the guest replaces descriptor 2, and the pipe holds 64 KiB. I could not test this; Linux headless runs stop earlier for an unrelated Vulkan reason.

Possible directions:

  • The Windows equivalent of what Linux does: when the guest replaces descriptor 2, send host logging to a stream opened on the kept copy rather than to the CRT's stderr. Keeping only descriptor 2 would still leave host stdout lines in a guest pipe when the title replaces descriptor 1 too.
  • Give _pipe a larger buffer (FreeBSD pipes grow to 64 KiB). That makes the stall rarer but leaves the host's log lines in the title's kernel log.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5919938059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7791). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-19T07:46:51Z. --- Eternal Darkness (PPSA99314, homebrew catalog) sometimes stops drawing at start-up on Windows: the window title stays at `FPS: 0.00 (17)` for the whole run. On `main` `64a9caa62` (Windows 11, RTX 3080, WinLibs GCC 15.2, Release) that happened in 5 of 28 runs of 30 s (an earlier build, `4ffb0cd12`, stalled in 1 of 5 runs of 60 s); the other runs reach about 14 fps. In every stall the log ends after two `RunThread` lines, where normal runs print the first `StorageTexture` line next. The title moves its standard error into a pipe and forwards what it reads to the kernel log: it logs `starts (standard error to klog: yes)`, and it imports `pipe`, `dup2`, `fdopen` and `read`. Guest descriptors are host CRT descriptors, so its `dup2` replaces the host's descriptor 2 as well. In one stall descriptor 1 was also a pipe although stdout had been redirected to a disk file at launch, so the title appears to replace standard output the same way. 2585eeb7e already keeps a copy of the host's standard error so `sceKernelDebugOutText` does not write into the guest's pipe (there, to stop a title from reading its own debug output back and logging it again). Since 438d41082, on Linux `PreserveHostStandardError` goes through `KeepHostStandardError_nid_no_patch`, which also points the process's `stderr` at that copy. On Windows it only takes `_dup(2)`: c22654102 restores the Win32 standard handle with `SetStdHandle`, but the CRT's `stderr` stream still writes through descriptor 2. So the host's own `fprintf(stderr, ...)` calls keep writing into the guest's pipe, and `pipe_nid_postfix` creates that pipe with a 4096-byte buffer (`_pipe(native, 4096, _O_BINARY)`). What two stalled processes showed. In the first I used gdb, including inferior calls for `_get_osfhandle` and `GetFileType`, which killed the process afterwards. In the second I only read registers and stacks, and used a separate probe process that duplicates the process's handles and queries each pipe with a timeout. - A thread in `AgcDriver::Graphics::StorageTexture::Refresh()` is blocked in `ZwWriteFile` under `fwrite` and `__mingw_fprintf`. Every direct print in `Refresh()` is an `fprintf(stderr, ...)` (the `[upload]`, `[dcc-keys]` and `[gpu]` lines). In the first stall its handle was `_get_osfhandle(2)`, a pipe (`GetFileType` = 3). - The process's standard handles in its PEB are not pipes, as expected since `dup2_nid_postfix` restores them with `SetStdHandle`; the redirection lives in the CRT descriptor table. - Of the six 4096-byte anonymous pipe ends in the second stall, one read end has 4097 bytes waiting and no read pending on it. The pipe names are empty, so the write end to read end pairing is inferred, but the other two read ends each have a `sceKernelRead` blocked on them, so the blocked write is almost certainly on the full pipe. - Three more threads are waiting in `RtlEnterCriticalSection` under `fwrite`, consistent with the stderr stream lock the writer holds: a guest `vfprintf` (`vfprintf_nid_postfix`), `AgcDriver::AsyncLog::Housekeeping()` (the async logger thread, so the stdout lines such as `StorageTexture ...` stop too) and `ShaderDiskCache::DiskStore::report`. So host log lines fill the guest's pipe and nothing drains it. Guest frames have no symbols, so I could not show which thread the title uses to drain it. If it is the guest `vfprintf` thread waiting for the lock, the wait never ends; if not, the drainer is stuck elsewhere. Either way the host's own logging is what fills the pipe. In a separate, earlier stall capture the main thread and one other thread were spinning at 100% CPU in `TimedWait` code, presumably waiting for work behind this. From the code, Linux should not be affected the same way: there the process's `stderr` points at the kept copy once the guest replaces descriptor 2, and the pipe holds 64 KiB. I could not test this; Linux headless runs stop earlier for an unrelated Vulkan reason. Possible directions: - The Windows equivalent of what Linux does: when the guest replaces descriptor 2, send host logging to a stream opened on the kept copy rather than to the CRT's `stderr`. Keeping only descriptor 2 would still leave host stdout lines in a guest pipe when the title replaces descriptor 1 too. - Give `_pipe` a larger buffer (FreeBSD pipes grow to 64 KiB). That makes the stall rarer but leaves the host's log lines in the title's kernel log. AI-assisted: yes
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#7791
No description provided.