Repository navigation
Keep the guest gate in the d3d9 alloc_app and free_app callbacks - #55
Open
kanapitsas wants to merge 2 commits into
Open
kanapitsas wants to merge 2 commits into
kanapitsas wants to merge 2 commits into
Conversation
rt_guest_enter yields the gate once in 1024 calls when a thread waits for it, even when the caller already holds it. mtld3d may call alloc_app or free_app while it holds one of its own locks. During such a yield another guest thread could take the gate, call into d3d9 and wait for that lock, while the first thread waits for the gate: a deadlock. The callbacks now take the gate with rt_guest_enter_no_yield, which never gives it up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rt_guest_entergives the guest gate to a waiting thread once in 1024 calls, even when the caller already holds it. The d3d9alloc_appandfree_appcallbacks take the gate this way. mtld3d can call them while it holds one of its own locks: on a staging miss,alloc_appruns under the page box pool's mutex. During the yield, another guest thread can take the gate, call into d3d9 and wait for that mutex, while the first thread waits for the gate. The game hangs. Nobody has seen it happen, but nothing prevents it.Change
rt_guest_enter_no_yieldinruntime/scheduler.ctakes the gate likert_guest_enter, but never gives it up.host_alloc_appandhost_free_appuse it.Tests
d3d9_alloc_app_keeps_the_guest_gate: a thread waits for the gate while the test, holding it, callsalloc_appandfree_app64 Ki times. The waiting thread must not get in before the test lets go. It fails 5 times out of 5 with the oldrt_guest_enter.make check(217 Python tests, 265 abi-smoke checks) andabi-smoke-ubsanpass.make d3d9metal-checkagainst the real library.Not covered
A separate risk, older than this change: under
D3DCREATE_MULTITHREADED, mtld3d holds itsApiLockthroughPresent, including the unix calls where the gate is released. A second guest thread could take the gate and wait for that lock. Not reproduced.🤖 Generated with Claude Code