fix(libkernel): allow repeated thread dtor callback registration #7639
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7639"
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 MarcZX10 on 2026-10-18T18:56:40Z.
What
Make registration of the same thread destructor callback idempotent while preserving the existing error for a different callback. The regression test covers both behaviors through the shared registration helper used by
ThreadLifecycle::SetThreadDtors.Issue #7636 reports a catalog-wide Linux startup abort after #6112 and identifies
ThreadLifecycle::SetThreadDtorsas the throw site. The report suspects duplicate libc startup registration, but does not establish that both calls pass the same callback; this change addresses that case only. It has not been validated against the full title startup/catalog, and Windows behavior is unverified.Tested
thread_dtor_registration_testswith Ninja.thread_dtor_registrationpassed (1/1).python3 tools/check_conventions.py --base upstream/mainpassed locally before opening;git diff --checkpassed.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 repositoryImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:58:10Z.
Source trace after opening: the only in-tree call to
sceKernelSetThreadDtorsisRegisterThreadExitHookinlibSceLibcInternal/Export.cpp, and it always passesRunThreadDestructors_nid_no_patch. Its function-local static should suppress repeat calls within one loaded module. That makes identical callback registration a plausible failure path, but does not establish why the setter is reached a second time (or exclude guest code calling the export with another callback). The production startup repro is still needed to confirm this fixes #7636.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:06:24Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:09:26Z.
I manually reviewed the flagged overlap with #3986. Its
Thread.cppchanges add per-thread signal-mask initialization inThreadArgs,RunThread, andscePthreadCreate; this PR changes onlyThreadLifecycle::SetThreadDtorsand its registration helper. They do not change the same behavior or depend on each other. #3986 is currently conflicting withmain, which is why the overlap bot could not compare those files. The latest conventions run for this PR passes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T19:25:24Z.
Thanks for jumping on this. We traced #7636 to #6112: a recent
libc.prxalready runs its own preinit array fromDT_INIT, and #6112 runs it again first, so libc's whole early start-up runs twice, not only the destructor registration. The revert is up in #7646 and fixes it at the source, so this one shouldn't be needed once that lands.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:29:31Z.
Given the #7636 update that attributes the startup regression to #6112 executing libc preinit twice, this PR's same-callback registration test does not yet establish that the proposed idempotence change fixes the reproduced failure. The focused test covers the helper in isolation, but not the startup path. Could you keep this as a fallback until the #7646 revert is validated against Wind Waker, or add a production-path regression if the call trace shows this change is still needed? Also, this head currently has a conventions failure; its successful convention run is for an earlier run/head according to the status checks.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:48:51Z.
The follow-up trace in #7636 now confirms the title module’s own
DT_INITcalls the startup pointer already invoked through #6112’s module-preinit wrapper. A second repeated registration also reachesSetThreadAtexitCount, so this PR’s destructor-setter idempotence would not fix the full duplicated startup path. I agree this should remain a fallback; #7646 addresses the cause. My issue comment #6254359577 records the trace-to-fix connection. I will wait for #7646 validation before proposing any change here.Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-18T20:01:08Z.
On Windows (MinGW-w64 GCC 15.2, WinLibs),
thread_dtor_registration_testsfails to link:ThreadDtorRegistration.cpp:(.data+0x8): undefined reference to '__gxx_personality_v0'. The library code itself builds and works: with this PR, MGS4 (PPSA18194) gets past the destructor registration and then stops onSetThreadAtexitCount(details in #7636).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:06:42Z.
Review: COMMENTED
The new Windows data point in #7636 reports that
thread_dtor_registration_testsdoes not link under MinGW (undefined reference to __gxx_personality_v0). It also confirms that, after this PR makes the destructor callback registration idempotent, startup proceeds only to the next duplicate registration (SetThreadAtexitCount). That supports keeping this as a fallback rather than treating it as a fix for the reproduced startup regression; #7646 addresses the duplicated preinit execution. I have not changed this PR or altered its status.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T21:45:21Z.
Thanks for the Windows report. I pushed
ed857e237to link the test with the samelibSceLibcInternal/libcruntime setup used by the neighboring guest tests, and added the Windows unwind configuration and runtime PATH entry. The focused test compiles and passes when built directly on Linux. I could not run the full CMake target here because this worktree has uninitialized SDL2 submodule contents; Windows CI will be the confirmation for the reported MinGW link failure.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:44:50Z.
Closing: the root cause of #7636 (libc's preinit array running twice after #6112) was fixed at the source by the revert in #7646, merged 2026-10-18, with Linux and Windows title evidence.
SetThreadAtexitCount), so it does not fix the reproduced path, and the test exercises the helper in isolation, not the startup path.Feel free to reopen with a production-path reproduction if a case still needs it.
Pull request closed