Windows: keep the output of an executable started without standard handles in anyps5.log #3282

Closed
opened 2026-10-11 05:07:39 +00:00 by justdoston · 3 comments
justdoston commented 2026-10-11 05:07:39 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by justdoston on 2026-10-11T05:07:39Z.


Summary

A Windows executable started without a standard output or error handle loses everything it prints. This mostly affects a --windows-gui build started from Explorer, but any start without handles does the same. The lost output includes the entry stub's own messages (FAIL: unresolved ELF import …, Failed to load module: …), the libraries' stdout/stderr, uncaught exception messages and the crash reports from CrashReport.cpp. All that is left is an exit code such as 0xc0000135.

Proposal

Before the entry stub enters its directory or loads a library, it checks the standard output and error handles. It gives each missing one anyps5.log beside the executable (CreateFileW, CREATE_ALWAYS, FILE_SHARE_READ | FILE_SHARE_WRITE, then SetStdHandle). The executable imports only KERNEL32.dll, so the C runtime of the libraries the stub loads afterwards starts up with the file as its stdout/stderr.

  • Executables started with handles (console runs, redirected runs, CI) are unchanged and create no file.
  • If the file cannot be created, for example in a read-only directory, the executable starts exactly as before.
  • Each run replaces the previous run's file.

Branch

justdoston/AnyPS5 feat/windows-log-without-standard-handles (262e38fd, on main 961b25fe):

  • WindowsEntryStubBuilder.cpp: the check and the anyps5.log file, written for the standard output and error handles.
  • WindowsImportBuilder.cpp: imports CreateFileW and SetStdHandle.
  • test_windows_import_modules.py: the two GUI start-up failure cases that run without handles now also check that anyps5.log holds the failure message. The console case checks that no log is created.
  • docs/user/USAGE.md: one sentence.

Verification

  • Relinker ctest on Linux: 105/105.
  • MinGW -fsyntax-only for both changed files.
  • Wine 10.0, started through CreateProcessW with STARTF_USESTDHANDLES and no handles:
    • A GUI build that runs logs the stub output.
    • A missing ELF import logs FAIL: unresolved ELF import absent from a.prx (exit 0xc0000139).
    • A missing library logs Failed to load module: … (exit 0xc0000135).
    • A host library built against msvcrt, and one built against UCRT, both have their printf/fprintf(stderr) lines in the log.
    • A read-only directory gives no log, and the program still runs.
    • A console build started from a console creates no log.

I have not tested it on native Windows yet. A run from Explorer on real Windows would be welcome.

AI-assisted: yes. Claude (Anthropic) did most of the design, code and testing. I reviewed it and ran it.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5798168203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3282). Originally posted by [justdoston](https://github.com/justdoston) on 2026-10-11T05:07:39Z. --- ## Summary A Windows executable started without a standard output or error handle loses everything it prints. This mostly affects a `--windows-gui` build started from Explorer, but any start without handles does the same. The lost output includes the entry stub's own messages (`FAIL: unresolved ELF import …`, `Failed to load module: …`), the libraries' `stdout`/`stderr`, uncaught exception messages and the crash reports from `CrashReport.cpp`. All that is left is an exit code such as `0xc0000135`. ## Proposal Before the entry stub enters its directory or loads a library, it checks the standard output and error handles. It gives each missing one `anyps5.log` beside the executable (`CreateFileW`, `CREATE_ALWAYS`, `FILE_SHARE_READ | FILE_SHARE_WRITE`, then `SetStdHandle`). The executable imports only `KERNEL32.dll`, so the C runtime of the libraries the stub loads afterwards starts up with the file as its `stdout`/`stderr`. - Executables started with handles (console runs, redirected runs, CI) are unchanged and create no file. - If the file cannot be created, for example in a read-only directory, the executable starts exactly as before. - Each run replaces the previous run's file. ## Branch justdoston/AnyPS5 [`feat/windows-log-without-standard-handles`](https://github.com/justdoston/AnyPS5/commits/feat/windows-log-without-standard-handles) (262e38fd, on `main` 961b25fe): - `WindowsEntryStubBuilder.cpp`: the check and the `anyps5.log` file, written for the standard output and error handles. - `WindowsImportBuilder.cpp`: imports `CreateFileW` and `SetStdHandle`. - `test_windows_import_modules.py`: the two GUI start-up failure cases that run without handles now also check that `anyps5.log` holds the failure message. The console case checks that no log is created. - `docs/user/USAGE.md`: one sentence. ## Verification - Relinker ctest on Linux: 105/105. - MinGW `-fsyntax-only` for both changed files. - Wine 10.0, started through `CreateProcessW` with `STARTF_USESTDHANDLES` and no handles: - A GUI build that runs logs the stub output. - A missing ELF import logs `FAIL: unresolved ELF import absent from a.prx` (exit `0xc0000139`). - A missing library logs `Failed to load module: …` (exit `0xc0000135`). - A host library built against msvcrt, and one built against UCRT, both have their `printf`/`fprintf(stderr)` lines in the log. - A read-only directory gives no log, and the program still runs. - A console build started from a console creates no log. I have not tested it on native Windows yet. A run from Explorer on real Windows would be welcome. AI-assisted: yes. Claude (Anthropic) did most of the design, code and testing. I reviewed it and ran it.
reyani-dev commented 2026-10-11 05:27:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T05:27:02Z.


Native Windows run of 262e38fd merged onto main 961b25fe: Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, relinker-only build (ANYPS5_RELINKER_ONLY=ON), Python 3.12 (os.name == 'nt', so the Windows-only cases run).

  • Relinker ctest: 100/100, including windows_import_modules. It builds without warnings.
  • The new assertions really run here. The branch's test_windows_import_modules.py run against a relinker built from main fails at the new check (AssertionError: ('missing-symbol-gui', False), no anyps5.log). With the branch's relinker it passes.

I also converted three --windows-gui cases with the test's own provider/executable helpers. I started each one through the test's exit_code_without_standard_handles (CreateProcessW, STARTF_USESTDHANDLES, no handles). I did not start them from Explorer itself.

Case Exit anyps5.log
missing ELF import 0xc0000139 FAIL: unresolved ELF import absent from a.prx, the searched libraries, GetLastError: 127
missing library 0xc0000135 Failed to load module: …\libs\missing.prx, GetLastError: 126
runs 0xb (11) Transferring control to ELF entry point

So on native Windows the stub output reaches the log in all three cases, and a successful GUI start also writes one. In the console runs of the test, no log is created.

One small thing, not from this branch: the missing-library log begins with a bare -> FAILED line. Without dependency diagnostics, the Loading … prefix isn't printed. A console run of the same case on main prints the same orphan line, so it's existing behaviour, but it's more visible now that it's the first line of a file.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105825426 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3282#issuecomment-6105825426). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T05:27:02Z. --- Native Windows run of `262e38fd` merged onto `main` `961b25fe`: Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, relinker-only build (`ANYPS5_RELINKER_ONLY=ON`), Python 3.12 (`os.name == 'nt'`, so the Windows-only cases run). - Relinker `ctest`: 100/100, including `windows_import_modules`. It builds without warnings. - The new assertions really run here. The branch's `test_windows_import_modules.py` run against a relinker built from `main` fails at the new check (`AssertionError: ('missing-symbol-gui', False)`, no `anyps5.log`). With the branch's relinker it passes. I also converted three `--windows-gui` cases with the test's own `provider`/`executable` helpers. I started each one through the test's `exit_code_without_standard_handles` (`CreateProcessW`, `STARTF_USESTDHANDLES`, no handles). I did not start them from Explorer itself. | Case | Exit | `anyps5.log` | |---|---|---| | missing ELF import | `0xc0000139` | `FAIL: unresolved ELF import absent from a.prx`, the searched libraries, `GetLastError: 127` | | missing library | `0xc0000135` | `Failed to load module: …\libs\missing.prx`, `GetLastError: 126` | | runs | `0xb` (11) | `Transferring control to ELF entry point` | So on native Windows the stub output reaches the log in all three cases, and a successful GUI start also writes one. In the console runs of the test, no log is created. One small thing, not from this branch: the missing-library log begins with a bare ` -> FAILED` line. Without dependency diagnostics, the `Loading …` prefix isn't printed. A console run of the same case on `main` prints the same orphan line, so it's existing behaviour, but it's more visible now that it's the first line of a file.
Jnbla6 commented 2026-10-11 07:07:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Jnbla6 on 2026-10-11T07:07:02Z.


Regarding the bare -> FAILED line @AchrafReyani noted on the missing-library path: WindowsEntryStubBuilder::Build guards writeString(loading) and writeString(loaded) behind if (dependencyDiagnostics), but emits writeString(loadFailed, true) unconditionally.

I opened #3307 with a branch ready (Jnbla6/AnyPS5 fix/windows-stub-orphan-failed-line, 3f85c8e4ec695dfe458e78a4b303c5981fcedd35) that guards writeString(loadFailed, true) behind if (dependencyDiagnostics) as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106518525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3282#issuecomment-6106518525). Originally posted by [Jnbla6](https://github.com/Jnbla6) on 2026-10-11T07:07:02Z. --- Regarding the bare ` -> FAILED` line @AchrafReyani noted on the missing-library path: `WindowsEntryStubBuilder::Build` guards `writeString(loading)` and `writeString(loaded)` behind `if (dependencyDiagnostics)`, but emits `writeString(loadFailed, true)` unconditionally. I opened #3307 with a branch ready (`Jnbla6/AnyPS5` `fix/windows-stub-orphan-failed-line`, `3f85c8e4ec695dfe458e78a4b303c5981fcedd35`) that guards `writeString(loadFailed, true)` behind `if (dependencyDiagnostics)` as well.
Zurisen commented 2026-10-11 09:00:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-11T09:00:52Z.


Native Windows run of @thedrowned925's fix/3282-windows-logging (619a1d46), merged into current main 1c75f4d2 (clean merge): Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, full build with the system libraries.

End to end, the #1127 scenario. The test_windows_import_modules.py executable (exit 22 once its guest entry runs) converted as --windows-gui and as console, each started through ShellExecute (Start-Process, as Explorer does, so no standard handles), plus the GUI build again with handles captured:

case main main + branch
GUI, no handles, runs 22, no log 22, anyps5.log: Transferring control to ELF entry point
GUI, no handles, missing symbol 0xc0000139, output lost 0xc0000139, anyps5.log: FAIL: unresolved ELF import absent from a.prx, Searched libraries: …
GUI, no handles, missing module 0xc0000135, output lost 0xc0000135, anyps5.log: Failed to load module: …\libs\missing.prx
GUI, handles captured output on stderr, no log unchanged: stderr, no log
console, started the same way no log no log

Exit statuses are unchanged in every case; only the output that had nowhere to go now lands in the file.

Full ctest: 814/816. windows_import_modules passes with the branch's new cases. The two failures also fail on main here: pr_overlap_encoding (Python 3.10) and guest_ampr_markers, which fails intermittently on plain main 1c75f4d2 (6 of 10 runs alone, GuestAmpr.cpp:381).

I did not test the system libraries' own output (an uncaught exception or a crash report from a .prx) reaching the file, as that needs a fixture that loads them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107376793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3282#issuecomment-6107376793). Originally posted by [Zurisen](https://github.com/Zurisen) on 2026-10-11T09:00:52Z. --- Native Windows run of @thedrowned925's `fix/3282-windows-logging` (`619a1d46`), merged into current `main` `1c75f4d2` (clean merge): Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, full build with the system libraries. **End to end, the #1127 scenario.** The `test_windows_import_modules.py` executable (exit 22 once its guest entry runs) converted as `--windows-gui` and as console, each started through ShellExecute (`Start-Process`, as Explorer does, so no standard handles), plus the GUI build again with handles captured: | case | `main` | `main` + branch | |---|---|---| | GUI, no handles, runs | 22, no log | 22, `anyps5.log`: `Transferring control to ELF entry point` | | GUI, no handles, missing symbol | `0xc0000139`, output lost | `0xc0000139`, `anyps5.log`: `FAIL: unresolved ELF import absent from a.prx`, `Searched libraries: …` | | GUI, no handles, missing module | `0xc0000135`, output lost | `0xc0000135`, `anyps5.log`: `Failed to load module: …\libs\missing.prx` | | GUI, handles captured | output on stderr, no log | unchanged: stderr, no log | | console, started the same way | no log | no log | Exit statuses are unchanged in every case; only the output that had nowhere to go now lands in the file. **Full ctest:** 814/816. `windows_import_modules` passes with the branch's new cases. The two failures also fail on `main` here: `pr_overlap_encoding` (Python 3.10) and `guest_ampr_markers`, which fails intermittently on plain `main` `1c75f4d2` (6 of 10 runs alone, `GuestAmpr.cpp:381`). I did not test the system libraries' own output (an uncaught exception or a crash report from a `.prx`) reaching the file, as that needs a fixture that loads them.
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#3282
No description provided.