HLE/gameinput: write callback token before registration and order blocking enumeration #485
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/485"
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 fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T01:23:11Z.
Problem
Two concurrency races in
register_device(crates/victory-hle/src/modules/gameinput.rs):*outreceives the registration token:register_devicepushedregistrationintostate.callbacksand releasedhub.state()before writing*out = registration.token. A concurrentpoll()thread could invoke the callback before*outwas written, racing with the title's token slot.poll():enumeration != 0 && enumeration != ASYNC_ENUMERATION),register_deviceaddedregistrationtostate.callbacks, releasedhub.state(), and then delivered the initialCONNECTEDsnapshot. A concurrentpoll()noticing a disconnect in that window could deliverDISCONNECTEDconcurrently with or ahead of the initialCONNECTEDcallback, inverting the device state seen by the title.Fix
*out = registration.tokenbefore lockinghub.state()and insertingregistrationintostate.callbacks.State::enumeratingand queue any concurrentpoll()events for those tokens intoState::deferred(discarded onforget()).State::deferredfor the token on the registering thread after initial enumeration finishes, clearingenumeratingonly once no deferred events remain (or the callback was unregistered), without ever holdinghub.state()across user callback calls.blocking_enumeration_writes_token_first_and_orders_concurrent_poll.Verification
cargo test -p victory-hle --locked gameinput::tests: 7 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.