hle(host_posix): implement WaitOnAddress and WakeByAddress* #556

Merged
Sheffy007 merged 1 commit from upstream-pr/556 into main 2026-11-28 03:59:32 +00:00
Sheffy007 commented 2026-11-28 03:52:40 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-28T03:52:40Z.


Summary

  • Implement WaitOnAddress, WakeByAddressSingle, and WakeByAddressAll in crates/victory-hle/src/host_posix/sync.rs and expose them in sync::lookup.
  • Support 1-, 2-, 4-, and 8-byte comparisons (aligned SeqCst atomic loads or unaligned reads), ERROR_INVALID_PARAMETER on null pointers or invalid sizes, and ERROR_TIMEOUT on zero/expired deadlines.
  • Park waiters on striped FIFO queues keyed by exact target address so wakes cannot be lost between comparison and parking and colliding stripes never steal wakes across distinct addresses.
  • Add unit test wait_on_address_handles_sizes_timeouts_and_isolated_wakes.

Verification

  • cargo xtask policy
  • cargo test --locked --target x86_64-apple-darwin -p victory-hle --lib -- host_posix::sync::tests --test-threads=1 (4 passed)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings

Closes #555

cc @Olima34

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5536407634 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/556). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-28T03:52:40Z. --- ## Summary - Implement `WaitOnAddress`, `WakeByAddressSingle`, and `WakeByAddressAll` in `crates/victory-hle/src/host_posix/sync.rs` and expose them in `sync::lookup`. - Support 1-, 2-, 4-, and 8-byte comparisons (aligned `SeqCst` atomic loads or unaligned reads), `ERROR_INVALID_PARAMETER` on null pointers or invalid sizes, and `ERROR_TIMEOUT` on zero/expired deadlines. - Park waiters on striped FIFO queues keyed by exact target address so wakes cannot be lost between comparison and parking and colliding stripes never steal wakes across distinct addresses. - Add unit test `wait_on_address_handles_sizes_timeouts_and_isolated_wakes`. ## Verification - `cargo xtask policy` - `cargo test --locked --target x86_64-apple-darwin -p victory-hle --lib -- host_posix::sync::tests --test-threads=1` (4 passed) - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings` Closes #555 cc @Olima34
Olima34 commented 2026-11-28 03:59:29 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T03:59:29Z.

Review: APPROVED


Check report (helping the maintainer clear the queue):

  • CI: check and macos-scripts green on 14ec9b75.
  • Read: the whole diff. WaitOnAddress compares under the address's stripe lock and parks on a per-waiter word, and WakeByAddress* removes and flags waiters under the same lock. So a wake between the comparison and the park can't be lost, and waiters on different addresses that share a stripe don't steal each other's wakes. 1/2/4/8-byte compares (atomic when aligned), ERROR_INVALID_PARAMETER for null or bad sizes, and ERROR_TIMEOUT on a zero or expired timeout follow Windows. The exports resolve from api-ms-win-core-synch-l1-2-0, kernelbase and kernel32. The test covers sizes, timeouts and wakes isolated per address.
  • Local check on current main (9c001aa7) + #539 + this PR: victory-hle tests pass on x86_64-apple-darwin (338 + 17), Windows clippy (-D warnings) clean, cargo xtask policy ok.
  • Suggestion, not blocking: a line in docs/native-host.md naming the three functions, and saying the implementation never wakes spuriously (Windows may), would help the next reader.
  • Not checked: no game run.

Thanks @Sheffy007!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6095628040 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/556#pullrequestreview-6095628040). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T03:59:29Z. **Review:** APPROVED --- Check report (helping the maintainer clear the queue): - **CI:** `check` and `macos-scripts` green on 14ec9b75. - **Read:** the whole diff. `WaitOnAddress` compares under the address's stripe lock and parks on a per-waiter word, and `WakeByAddress*` removes and flags waiters under the same lock. So a wake between the comparison and the park can't be lost, and waiters on different addresses that share a stripe don't steal each other's wakes. 1/2/4/8-byte compares (atomic when aligned), `ERROR_INVALID_PARAMETER` for null or bad sizes, and `ERROR_TIMEOUT` on a zero or expired timeout follow Windows. The exports resolve from `api-ms-win-core-synch-l1-2-0`, `kernelbase` and `kernel32`. The test covers sizes, timeouts and wakes isolated per address. - **Local check on current main (9c001aa7) + #539 + this PR:** `victory-hle` tests pass on x86_64-apple-darwin (338 + 17), Windows clippy (`-D warnings`) clean, `cargo xtask policy` ok. - **Suggestion, not blocking:** a line in docs/native-host.md naming the three functions, and saying the implementation never wakes spuriously (Windows may), would help the next reader. - **Not checked:** no game run. Thanks @Sheffy007!
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
LakshanSivakumar/Native-Victory-macOS!556
No description provided.