Skip to content

fix(kernel): retain module registry through process teardown - #5572

Closed
JJenkx wants to merge 5 commits into
boykopovar:mainfrom
JJenkx:fix/module-registry-lifetime
Closed

JJenkx wants to merge 5 commits into
boykopovar:mainfrom
JJenkx:fix/module-registry-lifetime

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

What

The dynamic loader's static module map destroys owned modules with dlclose during process exit. Guest finalizers can reenter module lookup while that map is partly destroyed; the image-ID map has already been destroyed as well. This caused a crash in module lookup during a guest finalizer.

Keep the registry and its mutex alive through process termination. Explicit dlclose still removes a handle and unloads outside the registry lock; remaining native modules are finalized by the host loader. Document the intentional retained allocation and untested Windows teardown ordering.

Add a Unix regression that loads libkernel after registering an exit callback. The callback checks symbol access, callable code, stable loaded-module and image identities, and explicit close after static teardown.

Tested

  • Full Linux and Windows fork CI passes for published head 9265f4e551c5, containing main d1670009fbfd: Linux 1,038 passed / 46 skipped; Windows 714 passed / 389 skipped. Skipped cases remain unvalidated. The regression exercises Unix teardown; Windows teardown ordering remains unverified.
  • The Linux teardown regression segfaults before the production change and passes afterward. It checks callable symbols, stable loaded-module/image identities and explicit close from an exit callback registered before loading libkernel.
  • Earlier combined Linux integration passes related dynamic loader, module information, unwind, AJM teardown, module directory and argument tests. RollerCoaster Tycoon Adventures: Deluxe reached its autosave screen and exited normally on window close in that integration; separate finalizer/startup fixes are also present, so this is not standalone title compatibility evidence.
  • Local conventions and whitespace checks pass. The intentional retained registry allocation and untested platform ordering are documented in library debt.

Checklist

  • Based on current main; no equivalent registry-lifetime fix found
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • No silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none; combined title evidence is qualified above
  • GPUs tested: n/a; module loader change
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5143 docs/dev/debt/libkernel.md L100

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this on current main (checked against PPSA21564's imports and runs). With the queue this high, please hold off on PRs that don't name a title needing the change. Reopen with the title ID and the log line if a title stops on it on current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants