fix(relinker): log Windows output when standard handles are missing #4062

Merged
danzaio merged 4 commits from upstream-pr/4062 into main 2026-10-13 12:11:42 +00:00
danzaio commented 2026-10-11 22:26:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by danzaio on 2026-10-11T22:26:56Z.


What

A Windows executable started without stdout or stderr handles had nowhere to send its startup and failure messages. The entry stub now checks both handles before loading host libraries. It sends each missing stream to anyps5.log beside the executable; both missing streams share the file. Existing handles are preserved, each run replaces the previous log, and a file-creation failure leaves startup unchanged.

The implementation commit retains Doston Abdullayev's authorship. The documentation note in docs/user/USAGE.md is under the Windows runtime launch instructions, separate from the controller input section. That placement also avoids the insertion overlap with #3998.

Closes #3282

Tested

Current branch HEAD: b390831a5808666b39f2899cc5b19575a0ee38d5 on pinned main 5fe4bebec60ae1295aea301be28def2019b332ae.

  • Host: Microsoft Windows 10 Pro 10.0.19045 (64-bit). Toolchain: MinGW-w64 GCC 15.2.0; CMake/CTest 3.31.6-msvc6; Release/Ninja.
  • Built relinker, windows_stdio_host_ucrt, and windows_stdio_host_msvcrt with cmake --build C:/Users/admin/anyps5-build-3282 --target relinker windows_stdio_host_ucrt windows_stdio_host_msvcrt --parallel 1, then completed the full build with cmake --build C:/Users/admin/anyps5-build-3282 --parallel 1.
  • ctest --test-dir C:/Users/admin/anyps5-build-3282 -R "^windows_import_modules$" -V: 1/1 passed. The test exercises actual UCRT and MSVCRT DLL fixtures, missing stdout and/or stderr, and both redirected handles; it validates MSVCRT imports __iob_func and fputs directly from msvcrt.dll and rejects API-set CRT imports.
  • ctest --test-dir C:/Users/admin/anyps5-build-3282 --output-on-failure: 121/121 passed, 0 failed, 0 skipped (53.12 seconds).
  • python -I tools/check_conventions.py --base 5fe4bebec60ae1295aea301be28def2019b332ae --head HEAD: passed. git diff --check 5fe4bebec60ae1295aea301be28def2019b332ae...HEAD: clean.
  • #3998 doc merge simulation: clean 3-way merge (exit 0); logging paragraph appears once and the controller timeline heading appears once. #3579 merge-tree composition: clean, tree 885fa1c0a43c0c7c6bdb3a8a9d2e6f87c28ccff8.

The red-green verification (failing without the logging code, passing with it restored) is historical, from the prior base 5aaf26bd325607f65bde28741a4e82ceaaf586c0; it was not rerun on this rebase. No Wine, Explorer launch, or full title/gameplay test. Upstream GitHub CI was not dispatched: our upstream permission is read-only (pull), while dispatch requires write, maintain, or admin permission.

Checklist

  • Rebased on the pinned upstream main snapshot used for review/build (5fe4bebec60ae1295aea301be28def2019b332ae). GitHub's current main has since advanced to d146ec1b667c3e34bebf817efcc094bdac393423; PR #4062 currently reports mergeable, and this branch was not rebased/tested against that later commit. No other open PR implements the missing-standard-handle fallback. #3786 captures output from processes its graphical launcher starts, using pipes and last_run.log; it does not provide this fallback for direct launches without handles. #3579 composes cleanly, and the #3998 documentation overlap is resolved.
  • One topic per PR; follow-ups go in a new pull request
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822859904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4062). Originally posted by [danzaio](https://github.com/danzaio) on 2026-10-11T22:26:56Z. --- ### What A Windows executable started without stdout or stderr handles had nowhere to send its startup and failure messages. The entry stub now checks both handles before loading host libraries. It sends each missing stream to `anyps5.log` beside the executable; both missing streams share the file. Existing handles are preserved, each run replaces the previous log, and a file-creation failure leaves startup unchanged. The implementation commit retains Doston Abdullayev's authorship. The documentation note in `docs/user/USAGE.md` is under the Windows runtime launch instructions, separate from the controller input section. That placement also avoids the insertion overlap with #3998. Closes #3282 ### Tested Current branch HEAD: `b390831a5808666b39f2899cc5b19575a0ee38d5` on pinned main `5fe4bebec60ae1295aea301be28def2019b332ae`. - Host: Microsoft Windows 10 Pro 10.0.19045 (64-bit). Toolchain: MinGW-w64 GCC 15.2.0; CMake/CTest 3.31.6-msvc6; Release/Ninja. - Built `relinker`, `windows_stdio_host_ucrt`, and `windows_stdio_host_msvcrt` with `cmake --build C:/Users/admin/anyps5-build-3282 --target relinker windows_stdio_host_ucrt windows_stdio_host_msvcrt --parallel 1`, then completed the full build with `cmake --build C:/Users/admin/anyps5-build-3282 --parallel 1`. - `ctest --test-dir C:/Users/admin/anyps5-build-3282 -R "^windows_import_modules$" -V`: **1/1 passed**. The test exercises actual UCRT and MSVCRT DLL fixtures, missing stdout and/or stderr, and both redirected handles; it validates MSVCRT imports `__iob_func` and `fputs` directly from `msvcrt.dll` and rejects API-set CRT imports. - `ctest --test-dir C:/Users/admin/anyps5-build-3282 --output-on-failure`: **121/121 passed, 0 failed, 0 skipped** (53.12 seconds). - `python -I tools/check_conventions.py --base 5fe4bebec60ae1295aea301be28def2019b332ae --head HEAD`: passed. `git diff --check 5fe4bebec60ae1295aea301be28def2019b332ae...HEAD`: clean. - #3998 doc merge simulation: clean 3-way merge (exit 0); logging paragraph appears once and the controller timeline heading appears once. #3579 merge-tree composition: clean, tree `885fa1c0a43c0c7c6bdb3a8a9d2e6f87c28ccff8`. The red-green verification (failing without the logging code, passing with it restored) is historical, from the prior base `5aaf26bd325607f65bde28741a4e82ceaaf586c0`; it was not rerun on this rebase. No Wine, Explorer launch, or full title/gameplay test. Upstream GitHub CI was not dispatched: our upstream permission is read-only (`pull`), while dispatch requires write, maintain, or admin permission. ### Checklist - [x] Rebased on the pinned upstream `main` snapshot used for review/build (`5fe4bebec60ae1295aea301be28def2019b332ae`). GitHub's current `main` has since advanced to `d146ec1b667c3e34bebf817efcc094bdac393423`; PR #4062 currently reports mergeable, and this branch was not rebased/tested against that later commit. No other open PR implements the missing-standard-handle fallback. #3786 captures output from processes its graphical launcher starts, using pipes and `last_run.log`; it does not provide this fallback for direct launches without handles. #3579 composes cleanly, and the #3998 documentation overlap is resolved. - [x] One topic per PR; follow-ups go in a new pull request - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes
danzaio commented 2026-10-12 03:55:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by danzaio on 2026-10-12T03:55:24Z.


Head b390831a5808666b39f2899cc5b19575a0ee38d5; the PR now targets main d146ec1b667c3e34bebf817efcc094bdac393423 (our local build/tests used pinned 5fe4bebec60ae1295aea301be28def2019b332ae). The #3998 docs overlap is resolved, and #3579 composes cleanly. windows_import_modules passed 1/1 and the full local CTest suite passed 121/121. The related #3786 launcher captures its own child output with pipes; it does not add the missing-handle fallback. Could an upstream collaborator run the required full build/CI for this head? I don't have dispatch permission.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117451903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4062#issuecomment-6117451903). Originally posted by [danzaio](https://github.com/danzaio) on 2026-10-12T03:55:24Z. --- Head `b390831a5808666b39f2899cc5b19575a0ee38d5`; the PR now targets main `d146ec1b667c3e34bebf817efcc094bdac393423` (our local build/tests used pinned `5fe4bebec60ae1295aea301be28def2019b332ae`). The `#3998` docs overlap is resolved, and `#3579` composes cleanly. `windows_import_modules` passed 1/1 and the full local CTest suite passed 121/121. The related `#3786` launcher captures its own child output with pipes; it does not add the missing-handle fallback. Could an upstream collaborator run the required full build/CI for this head? I don't have dispatch permission.
github-actions[bot] commented 2026-10-13 09:24:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T09:24:28Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4739 core/relinker/relinker/tests/test_windows_import_modules.py L79-85
#5083 core/relinker/elfpatcher/src/windows/WindowsImportBuilder.cpp L8
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142462042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4062#issuecomment-6142462042). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T09:24:28Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4739 | `core/relinker/relinker/tests/test_windows_import_modules.py` [L79-85](https://github.com/boykopovar/AnyPS5/blob/14036cb0e8aeddb686a6c745193610528bd8a9f0/core/relinker/relinker/tests/test_windows_import_modules.py#L79-L85) | | | | #5083 | `core/relinker/elfpatcher/src/windows/WindowsImportBuilder.cpp` [L8](https://github.com/boykopovar/AnyPS5/blob/14036cb0e8aeddb686a6c745193610528bd8a9f0/core/relinker/elfpatcher/src/windows/WindowsImportBuilder.cpp#L8) | | |
adriadam10 commented 2026-10-13 10:47:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:47:37Z.


Reviewed the entry stub change (WindowsEntryStubBuilder.cpp): the missing-handle check, the path-length bound against PathCapacity, the restored directory terminator and the shared log handle for the two streams are correct. The tests cover missing stdout/stderr/both, redirected handles, replacement of a stale log, unavailable log, and startup errors reaching anyps5.log, on UCRT and MSVCRT DLLs. Local Linux build and ctest in core/relinker pass; the Windows-only cases are covered by the full Build's windows job. Merging once it is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143854812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4062#issuecomment-6143854812). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T10:47:37Z. --- Reviewed the entry stub change (`WindowsEntryStubBuilder.cpp`): the missing-handle check, the path-length bound against `PathCapacity`, the restored directory terminator and the shared log handle for the two streams are correct. The tests cover missing stdout/stderr/both, redirected handles, replacement of a stale log, unavailable log, and startup errors reaching `anyps5.log`, on UCRT and MSVCRT DLLs. Local Linux build and ctest in `core/relinker` pass; the Windows-only cases are covered by the full Build's windows job. Merging once it is green.
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!4062
No description provided.