fix(libkernel): follow sceKernelSyncOnAddressWait and Wake as measured on a PS5 #8725

Merged
orezraey merged 7 commits from upstream-pr/8725 into main 2026-10-27 07:03:20 +00:00
orezraey commented 2026-10-20 22:31:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-20T22:31:27Z.


What

sceKernelSyncOnAddressWait, Wait8/16/32/64 and sceKernelSyncOnAddressWake followed assumptions: the debt entries said that the by-value comparand, the return values, the timeout and the alignment were assumed. In a payload process on a PS5 (firmware 13.60) they behave differently, and this PR follows the console:

Call Payload process, firmware 13.60 main before this PR here now
wait, value differs from the comparand 0x80020023 (EAGAIN) at once, timeout left as it was 0 EAGAIN, timeout untouched
wait, value matches, time runs out 0x8002003C (ETIMEDOUT) after the timeout; the timeout is set to 0 ETIMEDOUT, timeout untouched as on the console
wait, woken by Wake 0; the timeout is set to the time left (300000 → 269864 after 30 ms) 0, timeout untouched 0, time left written back
wait with a timeout of 0 ETIMEDOUT at once, even when the value differs and even for a null address ETIMEDOUT if the value matches, 0 if not as on the console
wait on a null address 0x8002000E (EFAULT), timeout untouched throws EFAULT
wait on a misaligned address (Wait32 at +1, +2, Wait16 at +33, Wait64 at +41, +44) compares and waits like an aligned one; a wake at the same address releases it throws as on the console
Wake with a count of 1 or less (1, 0, −1, −2), three waiters wakes one, returns 1 count 0 wakes none, a negative count throws, returns 0 wakes one, returns the number woken
Wake with count 2 or INT_MAX, three waiters wakes 2 or all 3 and returns that number wakes them, returns 0 as on the console
Wake with no waiter, a null address or 0x10 0 0, throws for null 0
a wait at +16 and a wake at +17, or a wait at +20 and a wake at +16 not released (times out) the same the same
the name argument no effect ignored ignored

Wait64 compares all 64 bits, and the timeout is a 32-bit count of microseconds: 2000 timed out after about 2.1 ms and 50000 after 50.1 ms. Both were already the case here. _umtx_op shares the waiter queue and is unchanged.

A misaligned value is read with one x86-64 mov in inline assembly, the same single load the console performs. C++ has no atomic load for a misaligned object, and the assembly keeps the read out of the C++ memory model, so a guest thread storing to the word while a wait compares it is not a data race on the host. Like the console's load, it is not atomic when the word crosses a cache line.

Debt: the two entries in docs/dev/debt/libkernel.md are replaced by one. Its gaps:

  • Only a null address is checked: any other unreadable address faults the host, where the console returned EFAULT for 0x10.
  • The time left is read from the host clock, so it can differ from the console's by the cost of the call.

How the console was measured

  • Setup:
    • The console runs firmware 13.60 and is jailbroken.
    • The probes are ELF payloads built with ps5-payload-dev/sdk v0.44 and clang 18.1.8 and started through elfldr, so they ran in a payload process, not in a title. A title process was not measured.
  • Provenance: the resolve lines show that the six functions were taken from libkernel_sys.sprx by dlsym and called through those pointers.
  • Method:
    • The timeout points to an 8-byte cell whose upper half is 0, so that a 64-bit read would also see a short timeout. The cell is reset before each call and printed after it.
    • Wakes come from a second thread 30 ms after the wait starts.
    • The multi-waiter cases start three threads on one word and call Wake twice with the same count.
    • The first probe (kwait) passed one timeout cell to every call, so after the first timeout it held 0. That is how the write-back was found; kwait2 to kwait4 reset it.
  • Files: the probe sources and the full logs are in this gist, with each probe's main.c renamed <probe>_main.c.
Console output (excerpt, lines copied unchanged)
kwait2: meta fw=0x13600007 pid=114 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 20 2026 18:38:49 log=/data/anyps5-probes/kwait2.log
kwait2: resolve sym=sceKernelSyncOnAddressWait32 module=libkernel_sys.sprx exported=yes

kwait2: case wait32 differs timeout_in=2000 ret=0x80020023 elapsed_us=6 timeout_out=0x00000000000007d0
kwait2: case wait32 equal timeout_in=2000 ret=0x8002003c elapsed_us=2123 timeout_out=0x0000000000000000
kwait2: case wait32 misaligned+1 differs timeout_in=2000 ret=0x80020023 elapsed_us=4 timeout_out=0x00000000000007d0
kwait2: case wait32 null timeout_in=2000 ret=0x8002000e elapsed_us=12 timeout_out=0x00000000000007d0
kwait2: case wait16 +33 equal timeout_in=2000 ret=0x8002003c elapsed_us=2110 timeout_out=0x0000000000000000
kwait2: case wait64 +41 equal timeout_in=2000 ret=0x8002003c elapsed_us=2111 timeout_out=0x0000000000000000
kwait2: case wait32 timeout0 differs timeout_in=0 ret=0x8002003c elapsed_us=4 timeout_out=0x0000000000000000
kwait2: case wait32 timeout50000 equal timeout_in=50000 ret=0x8002003c elapsed_us=50122 timeout_out=0x0000000000000000

kwait3: case woken count=1 wait_ret=0x00000000 elapsed_us=30142 timeout_in=300000 timeout_out=269864 wake_count=1 wake_ret=0x00000001
kwait3: case woken count=-1 wait_ret=0x00000000 elapsed_us=30149 timeout_in=300000 timeout_out=269856 wake_count=-1 wake_ret=0x00000001
kwait3: case misaligned+1 woken same address wait_ret=0x00000000 elapsed_us=30129 timeout_in=300000 timeout_out=269878 wake_count=1 wake_ret=0x00000001
kwait3: case wait+16 wake+17 wait_ret=0x8002003c elapsed_us=300123 timeout_in=300000 timeout_out=0 wake_count=1 wake_ret=0x00000000
kwait3: case wake address=null count=1 ret=0x00000000
kwait3: case wait32 address=0x10 ret=0x8002000e timeout_out=1000

kwait4: case three waiters count=2 created=3 first_wake_ret=2 second_wake_ret=1 returned_ok=3 timed_out=0
kwait4: case three waiters count=0 created=3 first_wake_ret=1 second_wake_ret=1 returned_ok=2 timed_out=1
kwait4: case three waiters count=-2 created=3 first_wake_ret=1 second_wake_ret=1 returned_ok=2 timed_out=1
kwait4: case three waiters count=2147483647 created=3 first_wake_ret=3 second_wake_ret=0 returned_ok=3 timed_out=0
kwait: case wake address=+0 count=-1 waiters=0 ret=0x00000000

The kwaitN: prefix names the probe; the rest of each line is copied unchanged.

Tested

  • Head after merging main (e48379c7af): a09cef91b1. The only conflict was the semaphore debt entry next to this PR's SyncOnAddress entry; both are kept. At this head guest_sync_on_address and guest_raise_exception pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC), guest_umtx_op three runs on Windows, and check_conventions passes.
  • Earlier head after merging main (f26434afa3, with #10706): dcfc5632b0. The test takes its declarations from libkernel/include/Api.hpp and its error codes from KernelErrors.hpp; the header's sceKernelSyncOnAddressWait* take KernelUseconds* (not const), matching this PR's definitions, which write the remaining time back. guest_sync_on_address, guest_raise_exception and guest_umtx_op pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); public_headers audit and check_conventions pass.
    Build: Windows 11 x86-64, WinLibs MinGW-w64 GCC 15.2.0 (posix-seh, ucrt, r7), -DBUILD_TESTING=ON, on main 339217ebc.

Tests:

  • guest_sync_on_address was rewritten for the measured behaviour. It now checks:
    • EAGAIN, ETIMEDOUT and EFAULT;
    • the timeout written back after a timeout and after a wake;
    • wake counts 0, −1 and 1 each releasing one of five waiters, and INT_MAX the rest, with the counts returned;
    • waits and wakes at misaligned addresses, including 2000 waits on a misaligned 64-bit word that another thread keeps changing and waking;
    • null addresses.
  • guest_umtx_op and guest_raise_exception pass. The latter needed Wake's result checked as a count instead of 0.

Old code, new test: with SyncOnAddress.cpp reverted to main, guest_sync_on_address aborts at its first check, where the value differs and main returns 0.

Not run here: macOS.

Console: behaviour measured on a PS5 (firmware 13.60), as described above.

Overlaps:

  • tools/pr_overlap.py lists #8304 (UMTX_OP_SEM_WAIT and UMTX_OP_SEM_WAKE) and #8323 (sharded waiter buckets). Both change lines of SyncOnAddress.cpp next to the ones changed here, and #8304 the same debt lines. Whichever lands second has to reconcile them.
  • #2528 shards the waiters too and already conflicts with main.
  • #6044 moves GuestSyncOnAddress.cpp and GuestRaiseException.cpp.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #10558 (merge order only: its semaphore entry sits on the line above this PR's SyncOnAddress entry in libkernel.md); #10706 removes the test declarations this PR adds to GuestRaiseException.cpp and GuestSyncOnAddress.cpp (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4943398920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-20T22:31:27Z. --- ### What `sceKernelSyncOnAddressWait`, `Wait8/16/32/64` and `sceKernelSyncOnAddressWake` followed assumptions: the debt entries said that the by-value comparand, the return values, the timeout and the alignment were assumed. In a payload process on a PS5 (firmware 13.60) they behave differently, and this PR follows the console: | Call | Payload process, firmware 13.60 | `main` before this PR | here now | |---|---|---|---| | wait, value differs from the comparand | `0x80020023` (`EAGAIN`) at once, timeout left as it was | 0 | `EAGAIN`, timeout untouched | | wait, value matches, time runs out | `0x8002003C` (`ETIMEDOUT`) after the timeout; the timeout is set to 0 | `ETIMEDOUT`, timeout untouched | as on the console | | wait, woken by `Wake` | 0; the timeout is set to the time left (300000 → 269864 after 30 ms) | 0, timeout untouched | 0, time left written back | | wait with a timeout of 0 | `ETIMEDOUT` at once, even when the value differs and even for a null address | `ETIMEDOUT` if the value matches, 0 if not | as on the console | | wait on a null address | `0x8002000E` (`EFAULT`), timeout untouched | throws | `EFAULT` | | wait on a misaligned address (`Wait32` at +1, +2, `Wait16` at +33, `Wait64` at +41, +44) | compares and waits like an aligned one; a wake at the same address releases it | throws | as on the console | | `Wake` with a count of 1 or less (1, 0, −1, −2), three waiters | wakes one, returns 1 | count 0 wakes none, a negative count throws, returns 0 | wakes one, returns the number woken | | `Wake` with count 2 or `INT_MAX`, three waiters | wakes 2 or all 3 and returns that number | wakes them, returns 0 | as on the console | | `Wake` with no waiter, a null address or 0x10 | 0 | 0, throws for null | 0 | | a wait at +16 and a wake at +17, or a wait at +20 and a wake at +16 | not released (times out) | the same | the same | | the name argument | no effect | ignored | ignored | `Wait64` compares all 64 bits, and the timeout is a 32-bit count of microseconds: 2000 timed out after about 2.1 ms and 50000 after 50.1 ms. Both were already the case here. `_umtx_op` shares the waiter queue and is unchanged. A misaligned value is read with one x86-64 `mov` in inline assembly, the same single load the console performs. C++ has no atomic load for a misaligned object, and the assembly keeps the read out of the C++ memory model, so a guest thread storing to the word while a wait compares it is not a data race on the host. Like the console's load, it is not atomic when the word crosses a cache line. **Debt:** the two entries in `docs/dev/debt/libkernel.md` are replaced by one. Its gaps: - Only a null address is checked: any other unreadable address faults the host, where the console returned `EFAULT` for 0x10. - The time left is read from the host clock, so it can differ from the console's by the cost of the call. #### How the console was measured - **Setup:** - The console runs firmware 13.60 and is jailbroken. - The probes are ELF payloads built with [ps5-payload-dev/sdk](https://github.com/ps5-payload-dev/sdk) v0.44 and clang 18.1.8 and started through elfldr, so they ran in a payload process, not in a title. A title process was not measured. - **Provenance:** the `resolve` lines show that the six functions were taken from `libkernel_sys.sprx` by `dlsym` and called through those pointers. - **Method:** - The timeout points to an 8-byte cell whose upper half is 0, so that a 64-bit read would also see a short timeout. The cell is reset before each call and printed after it. - Wakes come from a second thread 30 ms after the wait starts. - The multi-waiter cases start three threads on one word and call `Wake` twice with the same count. - The first probe (kwait) passed one timeout cell to every call, so after the first timeout it held 0. That is how the write-back was found; kwait2 to kwait4 reset it. - **Files:** the probe sources and the full logs are in [this gist](https://gist.github.com/orezraey/f8eb2b390a1c8919a78adf900f2719c4), with each probe's `main.c` renamed `<probe>_main.c`. <details><summary>Console output (excerpt, lines copied unchanged)</summary> ``` kwait2: meta fw=0x13600007 pid=114 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 20 2026 18:38:49 log=/data/anyps5-probes/kwait2.log kwait2: resolve sym=sceKernelSyncOnAddressWait32 module=libkernel_sys.sprx exported=yes kwait2: case wait32 differs timeout_in=2000 ret=0x80020023 elapsed_us=6 timeout_out=0x00000000000007d0 kwait2: case wait32 equal timeout_in=2000 ret=0x8002003c elapsed_us=2123 timeout_out=0x0000000000000000 kwait2: case wait32 misaligned+1 differs timeout_in=2000 ret=0x80020023 elapsed_us=4 timeout_out=0x00000000000007d0 kwait2: case wait32 null timeout_in=2000 ret=0x8002000e elapsed_us=12 timeout_out=0x00000000000007d0 kwait2: case wait16 +33 equal timeout_in=2000 ret=0x8002003c elapsed_us=2110 timeout_out=0x0000000000000000 kwait2: case wait64 +41 equal timeout_in=2000 ret=0x8002003c elapsed_us=2111 timeout_out=0x0000000000000000 kwait2: case wait32 timeout0 differs timeout_in=0 ret=0x8002003c elapsed_us=4 timeout_out=0x0000000000000000 kwait2: case wait32 timeout50000 equal timeout_in=50000 ret=0x8002003c elapsed_us=50122 timeout_out=0x0000000000000000 kwait3: case woken count=1 wait_ret=0x00000000 elapsed_us=30142 timeout_in=300000 timeout_out=269864 wake_count=1 wake_ret=0x00000001 kwait3: case woken count=-1 wait_ret=0x00000000 elapsed_us=30149 timeout_in=300000 timeout_out=269856 wake_count=-1 wake_ret=0x00000001 kwait3: case misaligned+1 woken same address wait_ret=0x00000000 elapsed_us=30129 timeout_in=300000 timeout_out=269878 wake_count=1 wake_ret=0x00000001 kwait3: case wait+16 wake+17 wait_ret=0x8002003c elapsed_us=300123 timeout_in=300000 timeout_out=0 wake_count=1 wake_ret=0x00000000 kwait3: case wake address=null count=1 ret=0x00000000 kwait3: case wait32 address=0x10 ret=0x8002000e timeout_out=1000 kwait4: case three waiters count=2 created=3 first_wake_ret=2 second_wake_ret=1 returned_ok=3 timed_out=0 kwait4: case three waiters count=0 created=3 first_wake_ret=1 second_wake_ret=1 returned_ok=2 timed_out=1 kwait4: case three waiters count=-2 created=3 first_wake_ret=1 second_wake_ret=1 returned_ok=2 timed_out=1 kwait4: case three waiters count=2147483647 created=3 first_wake_ret=3 second_wake_ret=0 returned_ok=3 timed_out=0 kwait: case wake address=+0 count=-1 waiters=0 ret=0x00000000 ``` The `kwaitN:` prefix names the probe; the rest of each line is copied unchanged. </details> ### Tested - Head after merging `main` (`e48379c7af`): `a09cef91b1`. The only conflict was the semaphore debt entry next to this PR's SyncOnAddress entry; both are kept. At this head `guest_sync_on_address` and `guest_raise_exception` pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC), `guest_umtx_op` three runs on Windows, and `check_conventions` passes. - Earlier head after merging `main` (`f26434afa3`, with #10706): `dcfc5632b0`. The test takes its declarations from `libkernel/include/Api.hpp` and its error codes from `KernelErrors.hpp`; the header's `sceKernelSyncOnAddressWait*` take `KernelUseconds*` (not `const`), matching this PR's definitions, which write the remaining time back. `guest_sync_on_address`, `guest_raise_exception` and `guest_umtx_op` pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); `public_headers` audit and `check_conventions` pass. **Build:** Windows 11 x86-64, WinLibs MinGW-w64 GCC 15.2.0 (posix-seh, ucrt, r7), `-DBUILD_TESTING=ON`, on `main` 339217ebc. **Tests:** - `guest_sync_on_address` was rewritten for the measured behaviour. It now checks: - `EAGAIN`, `ETIMEDOUT` and `EFAULT`; - the timeout written back after a timeout and after a wake; - wake counts 0, −1 and 1 each releasing one of five waiters, and `INT_MAX` the rest, with the counts returned; - waits and wakes at misaligned addresses, including 2000 waits on a misaligned 64-bit word that another thread keeps changing and waking; - null addresses. - `guest_umtx_op` and `guest_raise_exception` pass. The latter needed `Wake`'s result checked as a count instead of 0. **Old code, new test:** with `SyncOnAddress.cpp` reverted to `main`, `guest_sync_on_address` aborts at its first check, where the value differs and `main` returns 0. **Not run here:** macOS. **Console:** behaviour measured on a PS5 (firmware 13.60), as described above. **Overlaps:** - `tools/pr_overlap.py` lists #8304 (`UMTX_OP_SEM_WAIT` and `UMTX_OP_SEM_WAKE`) and #8323 (sharded waiter buckets). Both change lines of `SyncOnAddress.cpp` next to the ones changed here, and #8304 the same debt lines. Whichever lands second has to reconcile them. - #2528 shards the waiters too and already conflicts with `main`. - #6044 moves `GuestSyncOnAddress.cpp` and `GuestRaiseException.cpp`. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #10558 (merge order only: its semaphore entry sits on the line above this PR's SyncOnAddress entry in `libkernel.md`); #10706 removes the test declarations this PR adds to `GuestRaiseException.cpp` and `GuestSyncOnAddress.cpp` (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-20 22:32:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:32:05Z.


One concurrency question on LoadAddressValue: the newly supported misaligned path uses memcpy, which is an ordinary non-atomic read. A sync-on-address wait normally races with a guest thread updating that word before calling Wake; g_waitersLock does not synchronize with those guest stores. The aligned path uses atomic_ref, so the misaligned branch appears to introduce a C++ data race/undefined behavior for precisely that usage (even though the console reports that cross-cache-line loads themselves need not be atomic). Could you clarify how concurrent guest stores are represented/synchronized here, or use a host-side access primitive that gives the intended non-atomic hardware semantics without an unsynchronized C++ read? The current misaligned test only wakes without changing the word, so it does not exercise that case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303250627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#issuecomment-6303250627). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T22:32:05Z. --- One concurrency question on `LoadAddressValue`: the newly supported misaligned path uses `memcpy`, which is an ordinary non-atomic read. A sync-on-address wait normally races with a guest thread updating that word before calling `Wake`; `g_waitersLock` does not synchronize with those guest stores. The aligned path uses `atomic_ref`, so the misaligned branch appears to introduce a C++ data race/undefined behavior for precisely that usage (even though the console reports that cross-cache-line loads themselves need not be atomic). Could you clarify how concurrent guest stores are represented/synchronized here, or use a host-side access primitive that gives the intended non-atomic hardware semantics without an unsynchronized C++ read? The current misaligned test only wakes without changing the word, so it does not exercise that case.
orezraey commented 2026-10-20 22:40:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-20T22:40:09Z.


Good point, thanks. f4f9b3c replaces the memcpy with one x86-64 mov in inline assembly (asm volatile with a byte-array memory operand, so no misaligned typed lvalue is formed either). That is the single load the console performs on the word, and as an opaque asm load it is outside the C++ memory model, so a guest store racing the comparison is not UB on the host. It has the hardware semantics you describe: atomic within a cache line, possibly torn across one, like the console's own load. guest_sync_on_address now also runs 2000 waits on a misaligned 64-bit word (offset 3) while another thread keeps storing to it and calling Wake. Each wait returns 0, EAGAIN or ETIMEDOUT, and the loop finishes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303377669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#issuecomment-6303377669). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-20T22:40:09Z. --- Good point, thanks. f4f9b3c replaces the `memcpy` with one x86-64 `mov` in inline assembly (`asm volatile` with a byte-array memory operand, so no misaligned typed lvalue is formed either). That is the single load the console performs on the word, and as an opaque asm load it is outside the C++ memory model, so a guest store racing the comparison is not UB on the host. It has the hardware semantics you describe: atomic within a cache line, possibly torn across one, like the console's own load. `guest_sync_on_address` now also runs 2000 waits on a misaligned 64-bit word (offset 3) while another thread keeps storing to it and calling `Wake`. Each wait returns 0, `EAGAIN` or `ETIMEDOUT`, and the loop finishes.
oneandonlydean commented 2026-10-20 23:34:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:34:04Z.


@orezraey This now conflicts with main in SyncOnAddress.cpp: #8304 (merged earlier today) changed the same code, and it isn't a mechanical resolution, so we'd rather you make the call. Could you merge main into the branch (or rebase) and push? We'll review the new head and run full CI on it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304196026 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#issuecomment-6304196026). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T23:34:04Z. --- @orezraey This now conflicts with `main` in `SyncOnAddress.cpp`: #8304 (merged earlier today) changed the same code, and it isn't a mechanical resolution, so we'd rather you make the call. Could you merge `main` into the branch (or rebase) and push? We'll review the new head and run full CI on it.
MarcZX10 commented 2026-10-20 23:39:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:39:53Z.


Thanks for the follow-up. I checked the updated load and test: the misaligned comparison now uses one opaque x86-64 mov load rather than an ordinary C++ memcpy read, and the regression runs 2,000 waits while another thread updates the misaligned 64-bit word and calls Wake. That resolves the host data-race concern I raised. I see the maintainer’s separate request to merge/rebase current main; I’ll review the updated head after that lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304273805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#issuecomment-6304273805). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T23:39:53Z. --- Thanks for the follow-up. I checked the updated load and test: the misaligned comparison now uses one opaque x86-64 `mov` load rather than an ordinary C++ `memcpy` read, and the regression runs 2,000 waits while another thread updates the misaligned 64-bit word and calls `Wake`. That resolves the host data-race concern I raised. I see the maintainer’s separate request to merge/rebase current `main`; I’ll review the updated head after that lands.
orezraey commented 2026-10-20 23:45:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-20T23:45:48Z.


Thanks @oneandonlydean, merged main in 973234d. I kept #8304's WaitOnKeyLocked/WaitOnKeyUntil unchanged and rebuilt this PR's sceKernelSyncOnAddressWait on them. The ready predicate passed to WaitOnKeyUntil now records whether the value differed, which gives the measured EAGAIN, and reads a misaligned word with the single-load helper. WakeAddress returns the number woken, which sceKernelSyncOnAddressWake reports; the _umtx_op callers, the new SEM_WAIT/SEM_WAKE included, ignore it as before. In libkernel.md I kept #8304's _umtx_op entry and this PR's single sceKernelSyncOnAddressWait entry. guest_sync_on_address, guest_umtx_op and guest_raise_exception pass on Windows (GCC 15.2), and the diff against main touches only this PR's four files.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304352377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#issuecomment-6304352377). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-20T23:45:48Z. --- Thanks @oneandonlydean, merged `main` in 973234d. I kept #8304's `WaitOnKeyLocked`/`WaitOnKeyUntil` unchanged and rebuilt this PR's `sceKernelSyncOnAddressWait` on them. The ready predicate passed to `WaitOnKeyUntil` now records whether the value differed, which gives the measured `EAGAIN`, and reads a misaligned word with the single-load helper. `WakeAddress` returns the number woken, which `sceKernelSyncOnAddressWake` reports; the `_umtx_op` callers, the new `SEM_WAIT`/`SEM_WAKE` included, ignore it as before. In `libkernel.md` I kept #8304's `_umtx_op` entry and this PR's single `sceKernelSyncOnAddressWait` entry. `guest_sync_on_address`, `guest_umtx_op` and `guest_raise_exception` pass on Windows (GCC 15.2), and the diff against `main` touches only this PR's four files.
MarcZX10 commented 2026-10-20 23:48:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:48:08Z.

Review: APPROVED


Reviewed the rebased head 973234db6e. It retains #8304’s waiter-queue implementation and applies the measured wait comparison, timeout writeback, and wake-count behavior on top. Local checks: git diff --check and the conventions checker pass; GCC syntax-checking of the unaligned-load template instantiated for 8/16/32/64-bit types passes. I could not run the full C++ runtime target locally; the author reports the focused Windows suites passing. No blocking issue found in the rebased diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5593217993 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#pullrequestreview-5593217993). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T23:48:08Z. **Review:** APPROVED --- Reviewed the rebased head `973234db6e`. It retains #8304’s waiter-queue implementation and applies the measured wait comparison, timeout writeback, and wake-count behavior on top. Local checks: `git diff --check` and the conventions checker pass; GCC syntax-checking of the unaligned-load template instantiated for 8/16/32/64-bit types passes. I could not run the full C++ runtime target locally; the author reports the focused Windows suites passing. No blocking issue found in the rebased diff.
Filip722 commented 2026-10-21 10:09:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T10:09:30Z.


Additional native Linux runtime validation on exact head 973234db6ebef085936474042cfd3afee32226cc (including the merged waiter-queue changes).

Environment: Debian 13.7 x86-64, kernel 7.2.9-x64v3-xanmod1, Ryzen 5 7640HS, GCC 15.2.0, CMake 3.31.6, Release. Full-project configuration with BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, bundled dependencies and two build jobs; built the actual libkernel and the six relevant test executables.

  • guest_sync_on_address, guest_umtx_op, guest_raise_exception, guest_once, guest_kernel_sync, and guest_pthread_sem each passed three consecutive runs: 18 executions, no failures or skips.
  • The sync test exercises differing-value EAGAIN, zero-timeout precedence, timeout writeback, remaining time after wake, wake counts including zero/negative values, address isolation, every supported width, and misaligned wait/wake including the concurrent 64-bit case. The shared-caller controls include the merged _umtx_op semaphore cases.
  • Negative control: with the same final test executable, replaced only SyncOnAddress.cpp with its merge-base version (5b59fbc5539b6c6db7a26972f6069f1c6cc179ac) and rebuilt libkernel. guest_sync_on_address aborted. Restoring the exact PR source and rebuilding made it pass again.

Commands:

CCACHE_DIR=/tmp/anyps5-ccache cmake --build build --target libkernel guest_sync_on_address_tests guest_umtx_op_tests guest_raise_exception_tests guest_once_tests guest_kernel_sync_tests guest_pthread_sem_tests --parallel 2
ctest --test-dir build --output-on-failure --parallel 2 --repeat until-fail:3 -R '^(guest_sync_on_address|guest_umtx_op|guest_raise_exception|guest_once|guest_kernel_sync|guest_pthread_sem)$'

This adds native Linux execution of the project tests; it does not independently repeat the PS5 payload measurements. Windows-only exception-delivery branches, console execution and games were not tested. The documented unreadable non-null address limitation remains outside this check. AI-assisted testing/reporting: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313422457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8725#issuecomment-6313422457). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-21T10:09:30Z. --- Additional native Linux runtime validation on exact head `973234db6ebef085936474042cfd3afee32226cc` (including the merged waiter-queue changes). Environment: Debian 13.7 x86-64, kernel 7.2.9-x64v3-xanmod1, Ryzen 5 7640HS, GCC 15.2.0, CMake 3.31.6, Release. Full-project configuration with `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, bundled dependencies and two build jobs; built the actual `libkernel` and the six relevant test executables. - `guest_sync_on_address`, `guest_umtx_op`, `guest_raise_exception`, `guest_once`, `guest_kernel_sync`, and `guest_pthread_sem` each passed three consecutive runs: 18 executions, no failures or skips. - The sync test exercises differing-value EAGAIN, zero-timeout precedence, timeout writeback, remaining time after wake, wake counts including zero/negative values, address isolation, every supported width, and misaligned wait/wake including the concurrent 64-bit case. The shared-caller controls include the merged `_umtx_op` semaphore cases. - Negative control: with the same final test executable, replaced only `SyncOnAddress.cpp` with its merge-base version (`5b59fbc5539b6c6db7a26972f6069f1c6cc179ac`) and rebuilt `libkernel`. `guest_sync_on_address` aborted. Restoring the exact PR source and rebuilding made it pass again. Commands: ```sh CCACHE_DIR=/tmp/anyps5-ccache cmake --build build --target libkernel guest_sync_on_address_tests guest_umtx_op_tests guest_raise_exception_tests guest_once_tests guest_kernel_sync_tests guest_pthread_sem_tests --parallel 2 ctest --test-dir build --output-on-failure --parallel 2 --repeat until-fail:3 -R '^(guest_sync_on_address|guest_umtx_op|guest_raise_exception|guest_once|guest_kernel_sync|guest_pthread_sem)$' ``` This adds native Linux execution of the project tests; it does not independently repeat the PS5 payload measurements. Windows-only exception-delivery branches, console execution and games were not tested. The documented unreadable non-null address limitation remains outside this check. AI-assisted testing/reporting: yes.
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
boykopovar/AnyPS5!8725
No description provided.