Skip to content

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

Closed
johandavidcm wants to merge 1 commit into
boykopovar:mainfrom
johandavidcm:fix/libkernel-dlopen-unrelinked
Closed

johandavidcm wants to merge 1 commit into
boykopovar:mainfrom
johandavidcm:fix/libkernel-dlopen-unrelinked

Conversation

@johandavidcm

Copy link
Copy Markdown
Contributor

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:

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, on main 751b288.

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. These runs used the change on main b7d1d47; the rebase onto 751b288 touched none of the changed files.

  • With main's libraries, the Bad Image dialog for crm_module_ps5.prx appears 6 s after start.
  • With this change, no dialog appears, stderr has one [module] dlopen: ...crm_module_ps5.prx was not relinked ... line, and the title reaches gameplay.

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 Yakuza 0 Director's Cut (PPSA31327) #6722
  • GPUs tested: n/a
  • AI-assisted: yes

…ws Bad Image dialog

On Windows, dlopen passed a module that was never relinked to LoadLibraryExW, which raised the
modal Bad Image hard-error dialog and blocked the calling thread until someone answered it. The
load now runs with SEM_FAILCRITICALERRORS set for that thread only, so it fails at once with the
same result as before. Every failed load is reported once per file on stderr with a [module]
prefix; a file that exists with no relinked .guest.prx names the relinker's --module-dir option.
@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line open PR limit Closed over the open PR limit: 1 without merged PRs, 20 with at least 1, none from 20 labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown

Thank you for your contribution! Authors with no pull requests merged into main can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

@github-actions github-actions Bot closed this Oct 22, 2026
@johandavidcm johandavidcm changed the title fail dlopen of an unrelinked module without the Windows Bad Image dialog fix(libkernel): fail dlopen of an unrelinked module without the Windows Bad Image dialog Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open PR limit Closed over the open PR limit: 1 without merged PRs, 20 with at least 1, none from 20 unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant