Windows: Adding the flag --windows-gui to the relinker causes the relinked application to crash on start #2464

Closed
opened 2026-10-09 22:12:08 +00:00 by FALsGames · 2 comments
FALsGames commented 2026-10-09 22:12:08 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by FALsGames on 2026-10-09T22:12:08Z.


Summary

An executable relinked with --windows --windows-gui terminates immediately when started from Explorer or Console.

Tested Game

Dreaming Sarah

Reproduction

  1. Relink Dreaming Sarah with --windows --windows-gui.
  2. Start the generated executable by double-clicking it in Explorer, or through ShellExecute.
  3. Observe the process exit during startup.

Expected behaviour

The Windows GUI executable starts normally without creating or displaying a console window.

Actual behaviour

The process terminates with 0xC0000409.

Cause

Explorer starts a GUI executable without standard handles. Setting GetStdHandle values after the process has started is insufficient because the UCRT initializes stdin, stdout, and stderr during process startup.

Scope

The fix belongs in the Windows relinker startup stub. It must set the current directory to the executable directory and, only when a standard handle is missing, restart itself once with inheritable NUL handles supplied through STARTF_USESTDHANDLES. It must preserve the Windows GUI subsystem and must not allocate, hide, or briefly display a console window.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5785304479 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2464). Originally posted by [FALsGames](https://github.com/FALsGames) on 2026-10-09T22:12:08Z. --- ## Summary An executable relinked with `--windows --windows-gui` terminates immediately when started from Explorer or Console. ## Tested Game Dreaming Sarah ## Reproduction 1. Relink Dreaming Sarah with `--windows --windows-gui`. 2. Start the generated executable by double-clicking it in Explorer, or through ShellExecute. 3. Observe the process exit during startup. ## Expected behaviour The Windows GUI executable starts normally without creating or displaying a console window. ## Actual behaviour The process terminates with `0xC0000409`. ## Cause Explorer starts a GUI executable without standard handles. Setting `GetStdHandle` values after the process has started is insufficient because the UCRT initializes `stdin`, `stdout`, and `stderr` during process startup. ## Scope The fix belongs in the Windows relinker startup stub. It must set the current directory to the executable directory and, only when a standard handle is missing, restart itself once with inheritable `NUL` handles supplied through `STARTF_USESTDHANDLES`. It must preserve the Windows GUI subsystem and must not allocate, hide, or briefly display a console window.
LeandroLP23 commented 2026-10-09 22:21:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T22:21:37Z.


Data from a title anyone can download: ps5-doom (PPSA99666 v1.1.0, GPL), relinked on main b2714175 (plus the two-line #2462 fix, needed to build on Windows) as --windows --windows-gui and as plain --windows. Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release.

Launch --windows-gui build console build
ShellExecute (PowerShell Start-Process, so no standard handles), working directory = the executable's folder runs (3 of 3, still running after 8 s) runs
same, working directory C:\Windows\System32 or the user folder exits after about 1 s, code 0 exits, code 0
explorer.exe <path> gone after about 0.4 s gone as well

So with this title, missing standard handles alone don't stop a GUI build: it runs from ShellExecute without them. What does stop it is the working directory: started from any other folder, it doesn't find its files and exits, and the console build does the same. The Explorer launch behaves like that too. That supports the first part of the proposed fix (set the current directory to the executable's folder) as a generic problem. I couldn't reproduce the 0xC0000409 with this title (it exits cleanly with 0), so the NUL-handle restart may only matter for titles that write to the standard streams at start-up.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090223266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2464#issuecomment-6090223266). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-09T22:21:37Z. --- Data from a title anyone can download: [ps5-doom](https://github.com/lowbit/ps5-doom) (PPSA99666 v1.1.0, GPL), relinked on `main` b2714175 (plus the two-line #2462 fix, needed to build on Windows) as `--windows --windows-gui` and as plain `--windows`. Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release. | Launch | `--windows-gui` build | console build | |---|---|---| | `ShellExecute` (PowerShell `Start-Process`, so no standard handles), working directory = the executable's folder | runs (3 of 3, still running after 8 s) | runs | | same, working directory `C:\Windows\System32` or the user folder | exits after about 1 s, code 0 | exits, code 0 | | `explorer.exe <path>` | gone after about 0.4 s | gone as well | So with this title, missing standard handles alone don't stop a GUI build: it runs from `ShellExecute` without them. What does stop it is the working directory: started from any other folder, it doesn't find its files and exits, and the console build does the same. The Explorer launch behaves like that too. That supports the first part of the proposed fix (set the current directory to the executable's folder) as a generic problem. I couldn't reproduce the `0xC0000409` with this title (it exits cleanly with 0), so the `NUL`-handle restart may only matter for titles that write to the standard streams at start-up. AI-assisted: yes (Claude Code).
Get-fix commented 2026-10-10 00:58:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-10T00:58:25Z.


Root cause in the code, a test, and a fix verified with ps5-doom.

Cause. The guest filesystem root is taken from the current directory (core/libs/prx/libc/src/General.cpp:111, canonical(current_path())), so /app0/... resolves under the launch directory, and save data goes to the relative _sd (core/libs/prx/libSceSaveData.native/Export.cpp:24). That matches the ps5-doom table above; docs/user/USAGE.md documents the runtime layout as relative to the executable.

Fix. Get-fix/AnyPS5 fix/windows-gui-startup (a2d583f5, on main 0c0dc1e9): the Windows entry stub already finds the executable directory to load libs\; it now passes it to SetCurrentDirectoryA before loading any library (6 lines in WindowsEntryStubBuilder.cpp, one import), with its own failure message. Changing General.cpp and libSceSaveData instead would also change 11 library tests that use the current directory.

Test. windows_working_directory converts a guest whose import spins, starts it from another directory as console and --windows-gui builds, and reads the child's current directory. It fails on main and passes with the change. Relinker-only ctest on a2d583f5: 47 of 47; full Windows ctest before the rebase (64fe7439 plus the #2462 lines): 544 of 544.

ps5-doom (PPSA99666 v1.1.1; eboot.bin and sce_module/libc.prx unwrapped from the fake-signed SELF), --windows --windows-gui, started with Start-Process from another directory and from C:\Windows\System32 (3 runs each) and with explorer.exe <path>: without the change it is gone within 6 s in all 7 starts; with it, it runs in all 7 and the DOOM window renders.

Standard handles. Missing standard handles alone do not stop a title: the entry stub skips its writes when GetStdHandle returns null or invalid, and sceKernelDebugOutText, sceKernelSendNotificationRequest and the libc standard streams return errors instead of throwing. I could not reproduce 0xC0000409. The relaunch in #2466 makes windows_import_modules fail (('missing-symbol-gui', '0x0', '0xc0000139')): the parent exits with 0 without waiting, so the child's status never reaches the caller.

Linux output has the same current-directory root; this change covers Windows only.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091900010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2464#issuecomment-6091900010). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-10T00:58:25Z. --- Root cause in the code, a test, and a fix verified with ps5-doom. **Cause.** The guest filesystem root is taken from the current directory (`core/libs/prx/libc/src/General.cpp:111`, `canonical(current_path())`), so `/app0/...` resolves under the launch directory, and save data goes to the relative `_sd` (`core/libs/prx/libSceSaveData.native/Export.cpp:24`). That matches the ps5-doom table above; `docs/user/USAGE.md` documents the runtime layout as relative to the executable. **Fix.** Get-fix/AnyPS5 [`fix/windows-gui-startup`](https://github.com/Get-fix/AnyPS5/commits/fix/windows-gui-startup) (a2d583f5, on `main` 0c0dc1e9): the Windows entry stub already finds the executable directory to load `libs\`; it now passes it to `SetCurrentDirectoryA` before loading any library (6 lines in `WindowsEntryStubBuilder.cpp`, one import), with its own failure message. Changing `General.cpp` and libSceSaveData instead would also change 11 library tests that use the current directory. **Test.** `windows_working_directory` converts a guest whose import spins, starts it from another directory as console and `--windows-gui` builds, and reads the child's current directory. It fails on `main` and passes with the change. Relinker-only ctest on a2d583f5: 47 of 47; full Windows ctest before the rebase (64fe7439 plus the #2462 lines): 544 of 544. **ps5-doom** (PPSA99666 v1.1.1; `eboot.bin` and `sce_module/libc.prx` unwrapped from the fake-signed SELF), `--windows --windows-gui`, started with `Start-Process` from another directory and from `C:\Windows\System32` (3 runs each) and with `explorer.exe <path>`: without the change it is gone within 6 s in all 7 starts; with it, it runs in all 7 and the DOOM window renders. **Standard handles.** Missing standard handles alone do not stop a title: the entry stub skips its writes when `GetStdHandle` returns null or invalid, and `sceKernelDebugOutText`, `sceKernelSendNotificationRequest` and the libc standard streams return errors instead of throwing. I could not reproduce `0xC0000409`. The relaunch in #2466 makes `windows_import_modules` fail (`('missing-symbol-gui', '0x0', '0xc0000139')`): the parent exits with 0 without waiting, so the child's status never reaches the caller. Linux output has the same current-directory root; this change covers Windows only. AI-assisted: yes (Claude Code).
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#2464
No description provided.