fix(libkernel): initialize close observer registry on first use #13668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13668"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by notHaze on 2026-10-30T22:44:39Z.
What
Fix a DLL initialization failure (
0xC0000142) with MSYS2 UCRT64 GCC 16.2.0.Ksem.cppregisters a descriptor close observer during global initialization, potentially beforeg_closeObserverMutexinEqueue.cpphas been constructed. Locking the uninitialized mutex throwsstd::system_error(EINVAL) duringlibkernel.prxinitialization.Move the mutex and observer list into a function-local static registry, ensuring they are initialized on first use without depending on global constructor order.
Following review, the registry now uses process-lifetime storage to prevent exit callbacks from accessing an already-destroyed mutex or observer list.
Related: #9284 (introduced the global registration).
Tested
Windows, Release,
BUILD_TESTING=ON.Initial fix — full CTest suites on main
9605300f29, with and without the fix:0xC0000142failuresAll 1,739 DLL initialization failures were eliminated. No regressions were observed with WinLibs GCC 15.2.0.
Review follow-up — process-lifetime registry (
a6fd9994f7):Full rebuild and CTest suite on both toolchains.
The six MSYS2 failures also occur on WinLibs. The additional WinLibs failure,
agc_driver, passed when rerun individually, suggesting a possible intermittent or parallel-execution issue.No DLL initialization failures were reported. No regressions attributable to the registry lifetime change were identified.
Conventions checks passed.
PR overlap: The checker could not automatically compare five PRs that already conflict with main. Manual review found that #7509 and #10645 modify unrelated sections of
Equeue.cpp, while #9293, #9297 and #9302 carry the original close-observer code from the already-merged #9284. None implements this initialization fix.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T22:56:31Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The lazy registry fixes initialization order, but its normal static destruction can leave later process-exit callbacks using a destroyed registry.
What I ran
Reviewed head
1caa5a7cab4e1635f0359939512ba66cccded7a4against basebd5d95a5e47fcb0ec442d7d5e504ccfa8b6b258a. Environment: Debian GNU/Linux 12, x86_64, Python 3.11.2; no C++ compiler invocation or build was run.Results
git diff --checkmain9605300f29; not independently reproduced in this review.Unedited output from local checks
Findings
Blocking
GetCloseObserverRegistry()returns a destructible function-local static. If an earlier global initializer registers anatexitcallback that later notifies a descriptor close, and a later initializer first creates this registry, C++ exit ordering can destroy the registry before that callback runs. The subsequent notification locks a destroyed mutex and copies a destroyed vector. A reviewer reports an ASan lifecycle probe reproducing this on the exact head; I did not independently run that probe. Keep the registry alive through process exit (for example, process-lifetime storage) and add a focused regression for notification during exit where the test environment permits.Non-blocking
The description says #10194 reported the failure, but #10194 is an unrelated PR. Please correct or remove that reference.
Sources
Not verified
I did not build or run CTest, reproduce the ASan lifecycle probe, or test Linux, macOS, or console behavior. The full CTest results in the PR description are author-reported; the successful hosted Windows job skipped the full library build and broad CTest steps.
To get this to a good state
Please give the registry process lifetime, add a regression for process-exit notification if feasible, and fix the unrelated #10194 reference. I will rerun the same relevant checks against the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T01:34:11Z.
Review: APPROVED
Re-checked — new head, looks good
The new head keeps the lazily initialized close-observer registry alive through process shutdown, addressing the static-destruction-order blocker from my previous review.
What I ran
Reviewed head
a6fd9994f7a1ea25fb728fecf45937ef38f2dd12against PR basebd5d95a5e47fcb0ec442d7d5e504ccfa8b6b258a; the merge preview against currentmain539c3425f886a9fed61f8e33448e09f21504be91was clean. Environment: Linux 6.1.0-54-amd64 x86_64, Python 3.11.2, GCC 12.2 available; no local build or C++ tests were run.Results
The fix intentionally retains a small registry allocation for process lifetime; the static pointer remains reachable, while the registry object no longer runs a destructor before later exit callbacks.
Findings
Blocking
None found in the updated diff.
Non-blocking
The Windows hosted check was still running when checked, and I did not independently run the author-reported build or CTest suites.
Sources
Not verified
I did not run a local build, C++ tests, Linux runtime, or console behavior.