hle(host_posix): implement WaitOnAddress, WakeByAddressSingle, and WakeByAddressAll #559

Closed
opened 2026-11-28 03:53:25 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 03:48 UTC · original

Problem

docs/native-host.md lists WaitOnAddress and WakeByAddress* (api-ms-win-core-synch-l1-2-0.dll, kernelbase.dll, kernel32.dll) among the core Win32 synchronisation primitives for title and C++ runtime code, and victory_platform::sync already provides wait_on_address / wake_one / wake_all for internal locks.

However, crates/victory-hle/src/host_posix/sync.rs does not implement or export WaitOnAddress, WakeByAddressSingle, or WakeByAddressAll in sync::lookup. On macOS:

  • GetProcAddress for WaitOnAddress / WakeByAddressSingle / WakeByAddressAll fails with ERROR_PROC_NOT_FOUND.
  • Direct PE imports under --unimplemented zero return 0 immediately without waiting and without setting ERROR_TIMEOUT, causing any caller synchronizing via WaitOnAddress to either proceed prematurely or busy-spin.

Note that Win32 WaitOnAddress supports AddressSize values of 1, 2, 4, and 8 bytes (aligned or unaligned) while WakeByAddressSingle / WakeByAddressAll take only the target Address without a size argument (whereas Darwin's os_sync_wake_by_address_* requires size in {4, 8} matching the wait call and aligned to size).

Proposed Fix

  • Implement WaitOnAddress, WakeByAddressSingle, and WakeByAddressAll in crates/victory-hle/src/host_posix/sync.rs using striped wait queues keyed by exact Address on top of victory_platform::sync::{wait_on_address, wake_one}:
    • Support AddressSize in {1, 2, 4, 8} (using SeqCst atomic loads when naturally aligned and unaligned reads otherwise); reject null pointers or invalid AddressSize with ERROR_INVALID_PARAMETER.
    • Compare and enqueue atomically under the address stripe lock so wakes cannot be lost between comparison and parking, and never steal wakes across distinct addresses sharing a stripe.
    • Honor ms == 0, finite millisecond timeouts (ERROR_TIMEOUT), and INFINITE.
  • Register WaitOnAddress, WakeByAddressSingle, and WakeByAddressAll in sync::lookup.
  • Add unit tests covering 1/2/4/8-byte waits, immediate mismatch return, WakeByAddressSingle vs WakeByAddressAll isolation, timeouts, and invalid arguments.
**@⁠Sheffy007** on GitHub · 2026-11-28 03:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/555) ## Problem `docs/native-host.md` lists `WaitOnAddress` and `WakeByAddress*` (`api-ms-win-core-synch-l1-2-0.dll`, `kernelbase.dll`, `kernel32.dll`) among the core Win32 synchronisation primitives for title and C++ runtime code, and `victory_platform::sync` already provides `wait_on_address` / `wake_one` / `wake_all` for internal locks. However, `crates/victory-hle/src/host_posix/sync.rs` does not implement or export `WaitOnAddress`, `WakeByAddressSingle`, or `WakeByAddressAll` in `sync::lookup`. On macOS: - `GetProcAddress` for `WaitOnAddress` / `WakeByAddressSingle` / `WakeByAddressAll` fails with `ERROR_PROC_NOT_FOUND`. - Direct PE imports under `--unimplemented zero` return `0` immediately without waiting and without setting `ERROR_TIMEOUT`, causing any caller synchronizing via `WaitOnAddress` to either proceed prematurely or busy-spin. Note that Win32 `WaitOnAddress` supports `AddressSize` values of `1`, `2`, `4`, and `8` bytes (aligned or unaligned) while `WakeByAddressSingle` / `WakeByAddressAll` take only the target `Address` without a size argument (whereas Darwin's `os_sync_wake_by_address_*` requires `size` in `{4, 8}` matching the wait call and aligned to `size`). ## Proposed Fix - Implement `WaitOnAddress`, `WakeByAddressSingle`, and `WakeByAddressAll` in `crates/victory-hle/src/host_posix/sync.rs` using striped wait queues keyed by exact `Address` on top of `victory_platform::sync::{wait_on_address, wake_one}`: - Support `AddressSize` in `{1, 2, 4, 8}` (using `SeqCst` atomic loads when naturally aligned and unaligned reads otherwise); reject null pointers or invalid `AddressSize` with `ERROR_INVALID_PARAMETER`. - Compare and enqueue atomically under the address stripe lock so wakes cannot be lost between comparison and parking, and never steal wakes across distinct addresses sharing a stripe. - Honor `ms == 0`, finite millisecond timeouts (`ERROR_TIMEOUT`), and `INFINITE`. - Register `WaitOnAddress`, `WakeByAddressSingle`, and `WakeByAddressAll` in `sync::lookup`. - Add unit tests covering 1/2/4/8-byte waits, immediate mismatch return, `WakeByAddressSingle` vs `WakeByAddressAll` isolation, timeouts, and invalid arguments.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 03:53:34 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 03:48 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-28 03:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/555#issuecomment-7233404627) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 03:48 UTC · original

Claimed by @⁠Sheffy007. Open a draft pull request with Refs #555 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 03:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/555#issuecomment-7233407752) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #555` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.