kernel: do not release a waiter on a zero-count syncOnAddress wake (linux only) #168

Manually merged
github merged 2 commits from gh-pr/168/head into gh-pr/168/base 2026-11-26 09:13:01 +00:00
Owner

@⁠StefanosCosta on GitHub · 2026-08-04 21:02 UTC · original
StefanosCosta:fix/sync-on-address-zero-count-wake → main · +5 −0 · 1 files · 2 commits · merged 2026-08-08 06:17 UTC

Summary

sceKernelSyncOnAddressWake with a count of 0 behaves differently on Linux than on every other
host. WakePortable short-circuits count == 0 and releases nobody; WakeLinux passes the count
straight to FUTEX_WAKE, which does not treat 0 as "wake nobody" — measured directly, FUTEX_WAKE
with val = 0 returns 1 and releases a waiter. Wake admits 0 as valid (it rejects only
count < 0), and SyncOnAddressTests::TestWakeZeroIsNoOp asserts that it releases no waiters, so
the Linux path contradicts both the portable backend and the test — which is red on main on Linux.

What's included

Guest threading

  • Return early from WakeLinux when count == 0 instead of issuing the syscall — without it a
    zero-count wake releases a waiter, which returns from sceKernelSyncOnAddressWait reporting
    success while the watched word is unchanged. Confirmed against the raw syscall: FUTEX_WAKE
    with val = 0 returns 1.

Platform impact

  • Windows — unchanged. The change is confined to WakeLinux, inside
    #if KYTY_PLATFORM == KYTY_PLATFORM_LINUX && !defined(__APPLE__); Windows goes through
    WakePortable, which already had this guard.
  • macOS — unchanged, and for the same reason: Darwin is excluded from the Linux block and
    uses WakePortable.

Testing

Built Release on Linux (Clang, Ninja). SyncOnAddressTests::TestWakeZeroIsNoOp covers exactly
this and fails on current main: 10/10 runs abort on "zero-count wake releases no waiters". With
the fix, ctest -R sync_on_address passes 20/20 consecutive runs (36 checks).

**@⁠StefanosCosta** on GitHub · 2026-08-04 21:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/168) `StefanosCosta:fix/sync-on-address-zero-count-wake` → `main` · +5 −0 · 1 files · 2 commits · merged 2026-08-08 06:17 UTC ## Summary `sceKernelSyncOnAddressWake` with a count of 0 behaves differently on Linux than on every other host. `WakePortable` short-circuits `count == 0` and releases nobody; `WakeLinux` passes the count straight to `FUTEX_WAKE`, which does not treat 0 as "wake nobody" — measured directly, `FUTEX_WAKE` with `val = 0` returns 1 and releases a waiter. `Wake` admits 0 as valid (it rejects only `count < 0`), and `SyncOnAddressTests::TestWakeZeroIsNoOp` asserts that it releases no waiters, so the Linux path contradicts both the portable backend and the test — which is red on `main` on Linux. ## What's included ### Guest threading - Return early from `WakeLinux` when `count == 0` instead of issuing the syscall — without it a zero-count wake releases a waiter, which returns from `sceKernelSyncOnAddressWait` reporting success while the watched word is unchanged. Confirmed against the raw syscall: `FUTEX_WAKE` with `val = 0` returns 1. ## Platform impact - **Windows** — unchanged. The change is confined to `WakeLinux`, inside `#if KYTY_PLATFORM == KYTY_PLATFORM_LINUX && !defined(__APPLE__)`; Windows goes through `WakePortable`, which already had this guard. - **macOS** — unchanged, and for the same reason: Darwin is excluded from the Linux block and uses `WakePortable`. ## Testing Built Release on Linux (Clang, Ninja). `SyncOnAddressTests::TestWakeZeroIsNoOp` covers exactly this and fails on current `main`: 10/10 runs abort on "zero-count wake releases no waiters". With the fix, `ctest -R sync_on_address` passes 20/20 consecutive runs (36 checks).
sceKernelSyncOnAddressWake with a count of 0 must release no waiters. On
Linux it released exactly one.

WakeLinux passes the count straight to FUTEX_WAKE, which does not treat 0
as "wake nobody": the kernel's wake loop tests `if (++ret >= nr_wake) break`
after waking a waiter, so any waiter present is released before the loop can
break. A standalone futex program confirms it -- FUTEX_WAKE with val = 0
returns 1, and the waiter observes its wait return 0 with the word unchanged.

WakePortable already short-circuits count == 0, so the two backends of the
same ABI disagreed, with only the Linux one wrong.

TestWakeZeroIsNoOp in SyncOnAddressTests covers exactly this and fails on
Linux without the fix (15 consecutive failures on the assertion "zero-count
wake releases no waiters"); with the fix the suite passes 15 consecutive runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:00 +00:00
github manually merged commit a6c483ebcc into gh-pr/168/base 2026-11-26 09:13:01 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.