xgameruntime: release g_error_mutex before invoking XErrorCallback in XErrorReport (OLD-9887) #1135

Closed
ambroseautomation wants to merge 1 commit from upstream-pr/1135 into main
ambroseautomation commented 2026-11-24 19:06:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T19:06:40Z.


Claimed in the coordination issue as: OLD-9887 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141584617)

What and why

Carries forward old-pr/9887 (draft #156, original commit author totonii preserved; indexed in #17), rebased cleanly onto current main (6293c1c4f).

Fixes a re-entrancy deadlock in error_report (XErrorReport) in runtime/shims/xgameruntime.cpp:

  • Copies g_error_callback and g_error_context under g_error_mutex, then releases the lock before invoking the callback so a callback that calls XErrorReport or XErrorSetCallback re-entrantly does not deadlock.
  • Adds a multi-threaded re-entrancy regression test in runtime/test/xgameruntime_test.cpp that invokes both nested XErrorReport and XErrorSetCallback(nullptr, nullptr) from inside the callback with a 2-second deadlock timeout.

Tested

  • Compiled and ran xgameruntime_test.exe natively on Windows 11 with MSVC (/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2): xgameruntime_test: OK (159 checks), including the new re-entrancy test.
  • python -I scripts/check_no_game_data.py runtime/shims/xgameruntime.cpp runtime/test/xgameruntime_test.cpp: exit 0 (no game data).

GPUs tested: n/a (CPU/OS runtime shim; built and tested on Windows 11 Pro 64-bit, MSVC VS 18)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — xgameruntime shim)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5478559466 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1135). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T19:06:40Z. --- Claimed in the coordination issue as: OLD-9887 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141584617) ### What and why Carries forward `old-pr/9887` (draft #156, original commit author `totonii` preserved; indexed in #17), rebased cleanly onto current `main` (`6293c1c4f`). Fixes a re-entrancy deadlock in `error_report` (`XErrorReport`) in `runtime/shims/xgameruntime.cpp`: - Copies `g_error_callback` and `g_error_context` under `g_error_mutex`, then releases the lock before invoking the callback so a callback that calls `XErrorReport` or `XErrorSetCallback` re-entrantly does not deadlock. - Adds a multi-threaded re-entrancy regression test in `runtime/test/xgameruntime_test.cpp` that invokes both nested `XErrorReport` and `XErrorSetCallback(nullptr, nullptr)` from inside the callback with a 2-second deadlock timeout. ### Tested - Compiled and ran `xgameruntime_test.exe` natively on Windows 11 with MSVC (`/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`): `xgameruntime_test: OK (159 checks)`, including the new re-entrancy test. - `python -I scripts/check_no_game_data.py runtime/shims/xgameruntime.cpp runtime/test/xgameruntime_test.cpp`: exit 0 (no game data). GPUs tested: n/a (CPU/OS runtime shim; built and tested on Windows 11 Pro 64-bit, MSVC VS 18) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — `xgameruntime` shim)
abnalstlll-byte commented 2026-11-24 19:14:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T19:14:41Z.

Review: APPROVED


Reviewed and verified. Eliminates re-entrancy deadlock in runtime/shims/xgameruntime.cpp:error_report by snapshotting g_error_callback and context under g_error_mutex and releasing the lock before invoking the user callback. Verified via nested invocation regression tests in runtime/test/xgameruntime_test.cpp (159/159 checks PASS). 100% clean-room.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045717202 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1135#pullrequestreview-6045717202). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T19:14:41Z. **Review:** APPROVED --- Reviewed and verified. Eliminates re-entrancy deadlock in `runtime/shims/xgameruntime.cpp:error_report` by snapshotting `g_error_callback` and context under `g_error_mutex` and releasing the lock before invoking the user callback. Verified via nested invocation regression tests in `runtime/test/xgameruntime_test.cpp` (159/159 checks PASS). 100% clean-room.
madhyn commented 2026-11-24 19:33:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T19:33:00Z.


Tested cab5c1841 on Arch Linux + Wine 11.22 (clang-cl + xwin cross-build):

  • ctest --test-dir runtime/build/win -R "^xgameruntime$" --output-on-failure: Passed (5.44 s)

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142257576 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1135#issuecomment-7142257576). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T19:33:00Z. --- Tested `cab5c1841` on Arch Linux + Wine 11.22 (clang-cl + xwin cross-build): - `ctest --test-dir runtime/build/win -R "^xgameruntime$" --output-on-failure`: **Passed** (5.44 s) AI-assisted: yes
Deedlyy commented 2026-11-24 20:14:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:14:31Z.


Recommendation: [MERGE]

Reasoning: Carries #156: XErrorReport copies the callback and context under g_error_mutex and releases the lock before invoking the callback, fixing a re-entrancy deadlock. Small change with a multi-threaded regression test. Verified on Wine by madhyn. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 4/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143239283 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1135#issuecomment-7143239283). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:14:31Z. --- **Recommendation:** [MERGE] **Reasoning:** Carries #156: `XErrorReport` copies the callback and context under `g_error_mutex` and releases the lock before invoking the callback, fixing a re-entrancy deadlock. Small change with a multi-threaded regression test. Verified on Wine by madhyn. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 4/10

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
ProjectLeonida/mandy!1135
No description provided.