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

Manually merged
github merged 1 commit from github-bot/gh-556 into main 2026-11-28 04:04:56 +00:00 AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 03:52 UTC · original
Sheffy007:feat/host-posix-wait-on-address → main · +250 −4 · 1 files · 1 commits · merged 2026-11-28 03:59 UTC

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 #559

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-28 03:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/556) `Sheffy007:feat/host-posix-wait-on-address` → `main` · +250 −4 · 1 files · 1 commits · merged 2026-11-28 03:59 UTC ## 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 #559 cc @⁠Olima34
Implement `WaitOnAddress`, `WakeByAddressSingle`, and `WakeByAddressAll` in `host_posix::sync` and register them in `sync::lookup` so `api-ms-win-core-synch-l1-2-0.dll`, `kernelbase.dll`, `kernel32.dll`, and `GetProcAddress` resolve them on macOS.

Uses striped FIFO waiter queues keyed by exact target address on top of `victory_platform::sync::{wait_on_address, wake_one}`, supporting 1-, 2-, 4-, and 8-byte comparisons (aligned `SeqCst` atomic loads and unaligned reads), `ERROR_INVALID_PARAMETER` validation, `ERROR_TIMEOUT` deadlines, and address-isolated single and broadcast wakes.

Closes #555
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 03:53:36 +00:00
github manually merged commit 2f4d81e07f into main 2026-11-28 04:04:56 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 03:59 UTC · original · approved these changes

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) + #543 + 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!

**@⁠Olima34** on GitHub · 2026-11-28 03:59 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/556#pullrequestreview-6095628040) · **approved these changes** 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) + #543 + 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!
This discussion has been locked. Commenting is limited to contributors.
No description provided.