fix(libkernel): fail dlopen of an unrelinked module without the Windows Bad Image dialog #9832

Merged
johandavidcm merged 1 commit from upstream-pr/9832 into main 2026-10-23 10:18:01 +00:00
johandavidcm commented 2026-10-22 16:38:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-22T16:38:18Z.


What

On Windows, dlopen passes a module that was never relinked (a PS5 ELF or SELF that a title loads with sceKernelLoadStartModule) to LoadLibraryExW. Windows then raises its modal Bad Image hard-error dialog (0xC000012F), and the calling thread blocks until someone answers it. After that, the load fails with error 193 and sceKernelLoadStartModule returns SCE_KERNEL_ERROR_ENOENT, with nothing in the log.

Yakuza 0 Director's Cut (PPSA31327) hits this whenever these modules are not relinked:

  • at every boot, for /app0/data/crm/ps5/crm_module_ps5.prx (the SEGA account module);
  • in chapter 1, for /app0/data/module/ps5/yakuza_minigame_ps5_retail.prx.

Unattended runs stall on the dialog.

  • No dialog: LoadWithoutErrorDialog sets SEM_FAILCRITICALERRORS on the calling thread for the LoadLibraryExW call only, keeps the loader's error code, and restores the previous thread mode. PatchedLibraries.cpp uses the same flag for its whole process. The module's initialization (InitializeDeferredModule) runs after the mode is restored.
  • Same result: the load fails at once with the same error. The title gets null / ENOENT and continues, as it did after someone answered the dialog.
  • Reporting: every failed load writes the dlerror text and prints it on stderr, once per file, with a [module] prefix. This applies on Windows and on the other hosts.
    • A file that exists but has no relinked <name>.guest.prx gets: dlopen: <path> was not relinked: no <name>.guest.prx was found (Windows loader error 193); relink its directory with the relinker's --module-dir <dir> option.
    • Any other failure gets: dlopen: cannot load <path> (<reason>).
  • Docs: USAGE.md mentions the message beside its existing note on error 193.

Overlaps:

  • #9415 changes the same Windows lines of dlopen (fallback paths). Whichever PR merges second swaps its LoadLibraryExW calls for LoadWithoutErrorDialog and routes its final failure through LoadFailure.
  • The macOS PRs #8658 and #7201 add __APPLE__ blocks between the POSIX lines changed here, and #5021 touches the CMake lines near the new TIMEOUT. These are line-level conflicts only.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, on head dc84bec7b (main a6646f846).

guest_dynamic_loader gains a check. dlopen of an existing 4-byte ELF stub that has no .guest.prx is called twice:

  • with the process error mode reset to the default, because CTest starts tests with critical-error boxes off;
  • with the thread mode set to SEM_NOGPFAULTERRORBOX.

Each call must return null, with a dlerror that names the file and --module-dir, and the thread mode must be unchanged afterwards. The missing-module dlerror must not mention --module-dir.

  • With main's DynamicLoader.cpp, the test shows the Bad Image dialog and fails on the test's new TIMEOUT (30 s, the CI limit).
  • With this change it passes in 0.1 s, prints the was not relinked line once for the two calls, and passes --repeat until-fail:20.

Other tests that pass: guest_dynamic_loader_variant_names, guest_deferred_module_{reload,pinned,parallel,reentrant}, guest_module_info, guest_module_{dir,directories,args,identity,fini} and patched_libraries.

PPSA31327 01.015.000, relinked with only --module-dir data/module/ps5, launched with the default error mode, from boot to gameplay:

  • With libkernel from main 80565c594, the Bad Image dialog for crm_module_ps5.prx appears 6 s after start.
  • With the libraries built from the change on main 0def01bcb (head 4894d1cef, the same diff), no dialog appears, and stderr has one [module] dlopen: ...crm_module_ps5.prx was not relinked ... line. The title reaches gameplay, at about 200,000 draws per 10 s.

Linux: DynamicLoader.cpp and GuestDynamicLoader.cpp compile with GCC 15.2.0 (-Wall -Wextra, no warnings) in WSL Ubuntu. The test was not run there. On Linux and macOS the change is only the reporting: LoadFailure instead of Error(::dlerror()).

Not tested: macOS.

tools/check_conventions.py --base origin/main passes.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: PPSA31327 #6722
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4970828923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9832). Originally posted by [johandavidcm](https://github.com/johandavidcm) on 2026-10-22T16:38:18Z. --- ### What On Windows, `dlopen` passes a module that was never relinked (a PS5 ELF or SELF that a title loads with `sceKernelLoadStartModule`) to `LoadLibraryExW`. Windows then raises its modal Bad Image hard-error dialog (0xC000012F), and the calling thread blocks until someone answers it. After that, the load fails with error 193 and `sceKernelLoadStartModule` returns `SCE_KERNEL_ERROR_ENOENT`, with nothing in the log. Yakuza 0 Director's Cut (PPSA31327) hits this whenever these modules are not relinked: - at every boot, for `/app0/data/crm/ps5/crm_module_ps5.prx` (the SEGA account module); - in chapter 1, for `/app0/data/module/ps5/yakuza_minigame_ps5_retail.prx`. Unattended runs stall on the dialog. - **No dialog:** `LoadWithoutErrorDialog` sets `SEM_FAILCRITICALERRORS` on the calling thread for the `LoadLibraryExW` call only, keeps the loader's error code, and restores the previous thread mode. `PatchedLibraries.cpp` uses the same flag for its whole process. The module's initialization (`InitializeDeferredModule`) runs after the mode is restored. - **Same result:** the load fails at once with the same error. The title gets null / `ENOENT` and continues, as it did after someone answered the dialog. - **Reporting:** every failed load writes the dlerror text and prints it on stderr, once per file, with a `[module]` prefix. This applies on Windows and on the other hosts. - A file that exists but has no relinked `<name>.guest.prx` gets: `dlopen: <path> was not relinked: no <name>.guest.prx was found (Windows loader error 193); relink its directory with the relinker's --module-dir <dir> option`. - Any other failure gets: `dlopen: cannot load <path> (<reason>)`. - **Docs:** `USAGE.md` mentions the message beside its existing note on error 193. **Overlaps:** - #9415 changes the same Windows lines of `dlopen` (fallback paths). Whichever PR merges second swaps its `LoadLibraryExW` calls for `LoadWithoutErrorDialog` and routes its final failure through `LoadFailure`. - The macOS PRs #8658 and #7201 add `__APPLE__` blocks between the POSIX lines changed here, and #5021 touches the CMake lines near the new `TIMEOUT`. These are line-level conflicts only. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, on head dc84bec7b (`main` a6646f846). **`guest_dynamic_loader` gains a check.** dlopen of an existing 4-byte ELF stub that has no `.guest.prx` is called twice: - with the process error mode reset to the default, because CTest starts tests with critical-error boxes off; - with the thread mode set to `SEM_NOGPFAULTERRORBOX`. Each call must return null, with a dlerror that names the file and `--module-dir`, and the thread mode must be unchanged afterwards. The missing-module dlerror must not mention `--module-dir`. - With `main`'s `DynamicLoader.cpp`, the test shows the Bad Image dialog and fails on the test's new `TIMEOUT` (30 s, the CI limit). - With this change it passes in 0.1 s, prints the `was not relinked` line once for the two calls, and passes `--repeat until-fail:20`. **Other tests that pass:** `guest_dynamic_loader_variant_names`, `guest_deferred_module_{reload,pinned,parallel,reentrant}`, `guest_module_info`, `guest_module_{dir,directories,args,identity,fini}` and `patched_libraries`. **PPSA31327 01.015.000**, relinked with only `--module-dir data/module/ps5`, launched with the default error mode, from boot to gameplay: - With `libkernel` from `main` 80565c594, the Bad Image dialog for `crm_module_ps5.prx` appears 6 s after start. - With the libraries built from the change on `main` 0def01bcb (head 4894d1cef, the same diff), no dialog appears, and stderr has one `[module] dlopen: ...crm_module_ps5.prx was not relinked ...` line. The title reaches gameplay, at about 200,000 draws per 10 s. **Linux:** `DynamicLoader.cpp` and `GuestDynamicLoader.cpp` compile with GCC 15.2.0 (`-Wall -Wextra`, no warnings) in WSL Ubuntu. The test was not run there. On Linux and macOS the change is only the reporting: `LoadFailure` instead of `Error(::dlerror())`. **Not tested:** macOS. `tools/check_conventions.py --base origin/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: PPSA31327 #6722 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 16:40:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:40:59Z.

Review: COMMENTED


I reviewed head cc888176de25999eb68d6fc01d0cc641774b58da. python3 tools/check_conventions.py --base upstream/main and git diff --check upstream/main...refs/review/9832 pass. I also ran GCC 12.2 C++20 syntax-only compilation of the changed DynamicLoader.cpp and GuestDynamicLoader.cpp translation units; both compile successfully on Linux.

I did not run the CTest binary or the Windows modal-dialog reproduction here. The PR description reports the focused Windows test, repeated runs, and title reproduction; the PR's hosted Linux/Windows build jobs are skipped. The current main is two commits ahead of this head; a merge-tree check is clean. Please update to current main before merge and ensure the Windows focused test runs on the final head. I found no blocking issue in the reviewed diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5617681701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9832#pullrequestreview-5617681701). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T16:40:59Z. **Review:** COMMENTED --- I reviewed head `cc888176de25999eb68d6fc01d0cc641774b58da`. `python3 tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main...refs/review/9832` pass. I also ran GCC 12.2 C++20 syntax-only compilation of the changed `DynamicLoader.cpp` and `GuestDynamicLoader.cpp` translation units; both compile successfully on Linux. I did not run the CTest binary or the Windows modal-dialog reproduction here. The PR description reports the focused Windows test, repeated runs, and title reproduction; the PR's hosted Linux/Windows build jobs are skipped. The current `main` is two commits ahead of this head; a merge-tree check is clean. Please update to current `main` before merge and ensure the Windows focused test runs on the final head. I found no blocking issue in the reviewed diff.
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!9832
No description provided.