fix(libc): accept guest thread atexit dso on Windows #5155

Closed
kallmek3nny wants to merge 1 commit from upstream-pr/5155 into main
kallmek3nny commented 2026-10-13 13:04:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kallmek3nny on 2026-10-13T13:04:02Z.


What

Normalize the DSO argument passed through __cxa_thread_atexit_impl_nid_postfix to nullptr on Windows before calling MinGW's host __cxa_thread_atexit implementation.

Guest modules pass guest-side DSO handles. MinGW's TLS atexit runtime only accepts its host DSO handle (or null), so forwarding a guest DSO can assert in tls_atexit.c. Linux behavior is unchanged and still forwards the real DSO.

The existing callback regression previously forced directDso = nullptr on Windows, which hid this mismatch. The test now passes a real non-null module handle on every platform so the Windows path exercises guest/foreign DSO normalization.

This is distinct from open #5065 / #5090: those add the missing BKSCW2bCACA / __cxa_thread_atexit export. This PR fixes the existing callback bridge's Windows DSO behavior and can be merged independently; the export PR benefits from it once landed.

Related: #5055.

Tested

  • Diff inspected after squashing: only CxxAbiSupport.cpp and GuestThreadCallbackAbi.cpp change, 3 additions / 3 deletions.
  • No local build result is claimed. The upstream build workflow is PR-gated, so this draft is being opened to obtain repository CI results before marking it ready.

Checklist

  • Based on current main; fresh duplicate search covered #5055, __cxa_thread_atexit_impl_nid_postfix, BKSCW2bCACA, libc, both affected files, and Windows/DSO title keywords. #5065/#5090 export the symbol but do not implement this behavior.
  • 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
  • No new third-party code
  • Generic behavior, not title-specific
  • Depends on: none
  • Unblocks: Windows callers of the guest thread-local destructor bridge that pass guest DSO handles; observed in #5055
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4843657929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5155). Originally posted by [kallmek3nny](https://github.com/kallmek3nny) on 2026-10-13T13:04:02Z. --- ### What Normalize the DSO argument passed through `__cxa_thread_atexit_impl_nid_postfix` to `nullptr` on Windows before calling MinGW's host `__cxa_thread_atexit` implementation. Guest modules pass guest-side DSO handles. MinGW's TLS atexit runtime only accepts its host DSO handle (or null), so forwarding a guest DSO can assert in `tls_atexit.c`. Linux behavior is unchanged and still forwards the real DSO. The existing callback regression previously forced `directDso = nullptr` on Windows, which hid this mismatch. The test now passes a real non-null module handle on every platform so the Windows path exercises guest/foreign DSO normalization. This is distinct from open #5065 / #5090: those add the missing `BKSCW2bCACA` / `__cxa_thread_atexit` export. This PR fixes the existing callback bridge's Windows DSO behavior and can be merged independently; the export PR benefits from it once landed. Related: #5055. ### Tested - Diff inspected after squashing: only `CxxAbiSupport.cpp` and `GuestThreadCallbackAbi.cpp` change, 3 additions / 3 deletions. - No local build result is claimed. The upstream build workflow is PR-gated, so this draft is being opened to obtain repository CI results before marking it ready. ### Checklist - [x] Based on current `main`; fresh duplicate search covered #5055, `__cxa_thread_atexit_impl_nid_postfix`, `BKSCW2bCACA`, `libc`, both affected files, and Windows/DSO title keywords. #5065/#5090 export the symbol but do not implement this behavior. - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] No silent stubs added - [x] No notes, investigation files or images added - [x] No new third-party code - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] Unblocks: Windows callers of the guest thread-local destructor bridge that pass guest DSO handles; observed in #5055 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 13:14:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T13:14:42Z.


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
#4627 core/libs/prx/libc/src/CxxAbiSupport.cpp L74-83
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146386454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5155#issuecomment-6146386454). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T13:14:42Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #4627 | `core/libs/prx/libc/src/CxxAbiSupport.cpp` [L74-83](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/core/libs/prx/libc/src/CxxAbiSupport.cpp#L74-L83) | | |
simonbronk commented 2026-10-13 21:08:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T21:08:35Z.


Checked on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build (AI-assisted: Claude Code).

This looks superseded by #5065 (merged as 9c383e329, "ignore the guest DSO of thread atexit on Windows in the shared bridge"). Current main already sets dso = nullptr under _WIN32 at the top of __cxa_thread_atexit_impl_nid_postfix, and GuestThreadCallbackAbi.cpp already passes directDso = module on every platform.

  • main (0aa4cb1c2) without this PR: guest_thread_callback_abi passes with the non-null DSO.
  • This PR (923fcab8c) merged onto main merges cleanly but adds a second identical #ifdef _WIN32 dso = nullptr; #endif block after the context allocation. guest_thread_callback_abi passes 20/20, with no change in behaviour.

Unless something else is still missing here, this one can probably be closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155233956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5155#issuecomment-6155233956). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-13T21:08:35Z. --- Checked on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build (AI-assisted: Claude Code). This looks superseded by #5065 (merged as `9c383e329`, "ignore the guest DSO of thread atexit on Windows in the shared bridge"). Current `main` already sets `dso = nullptr` under `_WIN32` at the top of `__cxa_thread_atexit_impl_nid_postfix`, and `GuestThreadCallbackAbi.cpp` already passes `directDso = module` on every platform. - `main` (`0aa4cb1c2`) without this PR: `guest_thread_callback_abi` passes with the non-null DSO. - This PR (`923fcab8c`) merged onto `main` merges cleanly but adds a second identical `#ifdef _WIN32 dso = nullptr; #endif` block after the context allocation. `guest_thread_callback_abi` passes 20/20, with no change in behaviour. Unless something else is still missing here, this one can probably be closed.
oneandonlydean commented 2026-10-14 02:33:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:15Z.


Closing: the Windows guest DSO handling and the test change are on main since #5065.
Reopen if something here is still missing on current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159591239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5155#issuecomment-6159591239). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:15Z. --- Closing: the Windows guest DSO handling and the test change are on main since #5065. Reopen if something here is still missing on current main.

Pull request closed

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!5155
No description provided.