Windows: with --windows-gui, startup errors are not shown and the exit status becomes 0xc0000001 #1127

Closed
opened 2026-10-07 13:16:22 +00:00 by Zurisen · 0 comments
Zurisen commented 2026-10-07 13:16:22 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-07T13:16:22Z.


On main (501f1fe0), an executable relinked with --windows --windows-gui that fails at startup shows nothing and exits with 0xc0000001. The same failure in a console-subsystem executable prints the error and exits with the matching status. Not specific to one title.

Measured

Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release build. The fixtures are the missing-symbol and missing-dependency cases of test_windows_import_modules.py, launched through ShellExecute (Start-Process) as Explorer does, without redirected handles:

Case Subsystem Shown Exit status
missing-symbol console FAIL: unresolved ELF import absent from a.prx ... 0xc0000139
missing-symbol GUI nothing 0xc0000001
missing-dependency console Failed to load module: ...\libs\missing.prx ... 0xc0000135
missing-dependency GUI nothing 0xc0000001

With stderr redirected (subprocess.run(..., capture_output=True)), the GUI executables write the same text as the console ones and exit with 0xc0000139 and 0xc0000135.

Mechanism

  • A GUI-subsystem process started by ShellExecute has no standard handles; GetStdHandle(STD_ERROR_HANDLE) returns NULL.
  • writeString in the entry stub (WindowsEntryStubBuilder.cpp) passes the GetStdHandle result to requireDiagnosticSuccess, which raises 0xc0000001 on NULL. The diagnostic is not written and the status of the original failure is replaced.
  • At run time, Report in CrashReport.cpp writes to the same handle and ignores the result, and an uncaught std::runtime_error is printed by the libstdc++ terminate handler to stderr. In a GUI-subsystem process launched from Explorer both are lost. Read from the code; not reproduced, as it needs a fixture that loads the system libraries.

Reproduce

From the repository root after building with -DBUILD_TESTING=ON:

import subprocess, sys
from pathlib import Path
sys.path.insert(0, "core/relinker/relinker/tests")
from test_windows_import_modules import executable, provider

case = Path("gui-repro")
(case / "prx").mkdir(parents=True, exist_ok=True)
(case / "prx" / "a.prx").write_bytes(provider(11))
(case / "input.elf").write_bytes(executable("a.prx", "absent#A#B"))
subprocess.run([str(Path("build/core/relinker/relinker.exe").resolve()), "--windows", "--windows-gui",
                str(case / "input.elf"), str(case / "gui.exe")], check=True)
$p = Start-Process .\gui-repro\gui.exe -PassThru; $p.WaitForExit(); '{0:x}' -f $p.ExitCode

Prints c0000001; no window or message appears. Double-clicking gui.exe gives the same.

Question

Where should fatal diagnostics go when there is no stderr? Options:

  1. A message box (MessageBoxA, user32) with the diagnostic text, written by the entry stub and by Report/the terminate handler when the standard error handle is NULL.
  2. A log file next to the executable.
  3. Without a handle, skip the write and keep the original exit status, so at least the status is not replaced.

1 and 2 need the text to be collected before the process ends; 3 alone still shows nothing. Which one is wanted? I can implement it with a test that launches the GUI fixture without handles and checks the status (and the file, for 2).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5745618897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1127). Originally posted by [Zurisen](https://github.com/Zurisen) on 2026-10-07T13:16:22Z. --- On main (`501f1fe0`), an executable relinked with `--windows --windows-gui` that fails at startup shows nothing and exits with `0xc0000001`. The same failure in a console-subsystem executable prints the error and exits with the matching status. Not specific to one title. ### Measured Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release build. The fixtures are the `missing-symbol` and `missing-dependency` cases of `test_windows_import_modules.py`, launched through ShellExecute (`Start-Process`) as Explorer does, without redirected handles: | Case | Subsystem | Shown | Exit status | |---|---|---|---| | missing-symbol | console | `FAIL: unresolved ELF import absent from a.prx` ... | `0xc0000139` | | missing-symbol | GUI | nothing | `0xc0000001` | | missing-dependency | console | `Failed to load module: ...\libs\missing.prx` ... | `0xc0000135` | | missing-dependency | GUI | nothing | `0xc0000001` | With stderr redirected (`subprocess.run(..., capture_output=True)`), the GUI executables write the same text as the console ones and exit with `0xc0000139` and `0xc0000135`. ### Mechanism - A GUI-subsystem process started by ShellExecute has no standard handles; `GetStdHandle(STD_ERROR_HANDLE)` returns `NULL`. - `writeString` in the entry stub ([WindowsEntryStubBuilder.cpp](https://github.com/boykopovar/AnyPS5/blob/501f1fe0/core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp#L172-L192)) passes the `GetStdHandle` result to `requireDiagnosticSuccess`, which raises `0xc0000001` on `NULL`. The diagnostic is not written and the status of the original failure is replaced. - At run time, `Report` in [CrashReport.cpp](https://github.com/boykopovar/AnyPS5/blob/501f1fe0/core/libs/prx/libc/src/specifics/windows/CrashReport.cpp#L21-L31) writes to the same handle and ignores the result, and an uncaught `std::runtime_error` is printed by the libstdc++ terminate handler to stderr. In a GUI-subsystem process launched from Explorer both are lost. Read from the code; not reproduced, as it needs a fixture that loads the system libraries. ### Reproduce From the repository root after building with `-DBUILD_TESTING=ON`: ```python import subprocess, sys from pathlib import Path sys.path.insert(0, "core/relinker/relinker/tests") from test_windows_import_modules import executable, provider case = Path("gui-repro") (case / "prx").mkdir(parents=True, exist_ok=True) (case / "prx" / "a.prx").write_bytes(provider(11)) (case / "input.elf").write_bytes(executable("a.prx", "absent#A#B")) subprocess.run([str(Path("build/core/relinker/relinker.exe").resolve()), "--windows", "--windows-gui", str(case / "input.elf"), str(case / "gui.exe")], check=True) ``` ```powershell $p = Start-Process .\gui-repro\gui.exe -PassThru; $p.WaitForExit(); '{0:x}' -f $p.ExitCode ``` Prints `c0000001`; no window or message appears. Double-clicking `gui.exe` gives the same. ### Question Where should fatal diagnostics go when there is no stderr? Options: 1. A message box (`MessageBoxA`, user32) with the diagnostic text, written by the entry stub and by `Report`/the terminate handler when the standard error handle is `NULL`. 2. A log file next to the executable. 3. Without a handle, skip the write and keep the original exit status, so at least the status is not replaced. 1 and 2 need the text to be collected before the process ends; 3 alone still shows nothing. Which one is wanted? I can implement it with a test that launches the GUI fixture without handles and checks the status (and the file, for 2).
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#1127
No description provided.