fix(relinker): start Windows executables in their own directory #2574

Merged
oneandonlydean merged 1 commit from upstream-pr/2574 into main 2026-10-10 07:07:54 +00:00
oneandonlydean commented 2026-10-10 06:49:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T06:49:12Z.


Carrying @Get-fix's fix for #2464 while PR intake is paused. The change is theirs (from Get-fix/AnyPS5:fix/windows-gui-startup, a2d583f5), cherry-picked unchanged onto current main.

What

The Windows entry stub already finds the executable's directory to load libs\. It now also passes that directory to SetCurrentDirectoryA before loading any library, with its own failure message (6 lines in WindowsEntryStubBuilder.cpp, plus one import). A new relinker test, windows_working_directory, converts a guest whose import spins and starts it from another directory as a console build and as a --windows-gui build. It then reads the child's current directory.

Why

Fixes #2464. The guest filesystem root comes from the current directory (canonical(current_path()) in core/libs/prx/libc/src/General.cpp), and save data goes to the relative _sd. An executable started from Explorer, or from any folder other than its own, doesn't find its title files and exits. In the issue, LeandroLP23 showed with ps5-doom (PPSA99666) that this happens to --windows-gui and console builds alike, and that missing standard handles alone don't stop a title. Fixing it in the stub keeps General.cpp and libSceSaveData unchanged, along with the 11 library tests that use the current directory.

Tested

  • The author's runs: windows_working_directory fails on main and passes with the change. Relinker-only ctest 47/47, and full Windows ctest 544/544 before the rebase. ps5-doom as --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 exits within 6 s in all 7 starts. With it, it runs in all 7 and the window renders.
  • On current main 092e133e: the branch merges cleanly and tools/check_conventions.py passes. CI runs the build and tests.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • 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:4809369114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2574). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T06:49:12Z. --- Carrying @Get-fix's fix for #2464 while PR intake is paused. The change is theirs (from `Get-fix/AnyPS5:fix/windows-gui-startup`, a2d583f5), cherry-picked unchanged onto current `main`. ### What The Windows entry stub already finds the executable's directory to load `libs\`. It now also passes that directory to `SetCurrentDirectoryA` before loading any library, with its own failure message (6 lines in `WindowsEntryStubBuilder.cpp`, plus one import). A new relinker test, `windows_working_directory`, converts a guest whose import spins and starts it from another directory as a console build and as a `--windows-gui` build. It then reads the child's current directory. ### Why Fixes #2464. The guest filesystem root comes from the current directory (`canonical(current_path())` in `core/libs/prx/libc/src/General.cpp`), and save data goes to the relative `_sd`. An executable started from Explorer, or from any folder other than its own, doesn't find its title files and exits. In the issue, LeandroLP23 showed with ps5-doom (PPSA99666) that this happens to `--windows-gui` and console builds alike, and that missing standard handles alone don't stop a title. Fixing it in the stub keeps `General.cpp` and libSceSaveData unchanged, along with the 11 library tests that use the current directory. ### Tested - The author's runs: `windows_working_directory` fails on `main` and passes with the change. Relinker-only ctest 47/47, and full Windows ctest 544/544 before the rebase. ps5-doom as `--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 exits within 6 s in all 7 starts. With it, it runs in all 7 and the window renders. - On current `main` 092e133e: the branch merges cleanly and `tools/check_conventions.py` passes. CI runs the build and tests. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [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
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!2574
No description provided.