feat(libkernel): implement sceKernelSyncOnAddressWait and sceKernelSyncOnAddressWake #349

Merged
DotDebian merged 1 commit from upstream-pr/349 into main 2026-10-02 19:31:46 +00:00
DotDebian commented 2026-10-02 11:28:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-02T11:28:50Z.


What

Adds sceKernelSyncOnAddressWait (Hc4CaR6JBL0) and sceKernelSyncOnAddressWake (q2y-wDIVWZA) to libkernel, in a new SyncOnAddress/src/SyncOnAddress.cpp.

  • sceKernelSyncOnAddressWait(address, expected, timeout, name) returns 0 at once when the 32-bit word at address differs from expected. Otherwise the thread is parked until a wake releases it (0) or the timeout expires (SCE_KERNEL_ERROR_ETIMEDOUT). A null timeout waits without limit.
  • sceKernelSyncOnAddressWake(address, count) releases up to count threads parked on address, oldest first, and returns 0.
  • A null or misaligned address and a negative count throw.

The libc.prx bundled with Astro Bot (PPSA21564 01.007.000, SDK 9) imports both for its once primitive, so the title stopped at load with unresolved ELF import.

The argument list comes from the two call sites in that libc.prx: Wait(address, 1, null, "SceLibcIV2Once") inside a loop that re-reads a 64-bit state, and Wake(address, 0x7fffffff) after the state is stored. No caller I have passes a timeout: reading it as a pointer to microseconds, and the return values, follow the other kernel waits and KytyPS5. This is recorded in TechnicalDebt.

Not included: sceKernelSyncOnAddressWait32 / sceKernelSyncOnAddressWait64 (no title at hand imports them) and sceKernelMapNamedFlexibleMemoryInternal, the third libkernel import this libc.prx still lacks.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0 (winlibs, ucrt posix seh), Release, -DBUILD_TESTING=ON: full build, ctest 108/108, including the new guest_sync_on_address (also run 40 times in a row).
  • Astro Bot (PPSA21564) on Windows, with this branch plus #296, #289 and a local forwarder for sceKernelMapNamedFlexibleMemoryInternal: every import resolves, the title reaches main() and starts its worker threads, then stops on Non-fixed mapping address hints are not implemented. Without this branch it stops at load.
  • Linux: not tested.

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 in TechnicalDebt
  • 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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4715890540 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/349). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-02T11:28:50Z. --- ### What Adds `sceKernelSyncOnAddressWait` (`Hc4CaR6JBL0`) and `sceKernelSyncOnAddressWake` (`q2y-wDIVWZA`) to libkernel, in a new `SyncOnAddress/src/SyncOnAddress.cpp`. - `sceKernelSyncOnAddressWait(address, expected, timeout, name)` returns 0 at once when the 32-bit word at `address` differs from `expected`. Otherwise the thread is parked until a wake releases it (0) or the timeout expires (`SCE_KERNEL_ERROR_ETIMEDOUT`). A null timeout waits without limit. - `sceKernelSyncOnAddressWake(address, count)` releases up to `count` threads parked on `address`, oldest first, and returns 0. - A null or misaligned address and a negative count throw. The `libc.prx` bundled with Astro Bot (PPSA21564 01.007.000, SDK 9) imports both for its once primitive, so the title stopped at load with `unresolved ELF import`. The argument list comes from the two call sites in that `libc.prx`: `Wait(address, 1, null, "SceLibcIV2Once")` inside a loop that re-reads a 64-bit state, and `Wake(address, 0x7fffffff)` after the state is stored. No caller I have passes a timeout: reading it as a pointer to microseconds, and the return values, follow the other kernel waits and KytyPS5. This is recorded in TechnicalDebt. Not included: `sceKernelSyncOnAddressWait32` / `sceKernelSyncOnAddressWait64` (no title at hand imports them) and `sceKernelMapNamedFlexibleMemoryInternal`, the third libkernel import this `libc.prx` still lacks. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0 (winlibs, ucrt posix seh), Release, `-DBUILD_TESTING=ON`: full build, `ctest` 108/108, including the new `guest_sync_on_address` (also run 40 times in a row). - Astro Bot (PPSA21564) on Windows, with this branch plus #296, #289 and a local forwarder for `sceKernelMapNamedFlexibleMemoryInternal`: every import resolves, the title reaches `main()` and starts its worker threads, then stops on `Non-fixed mapping address hints are not implemented`. Without this branch it stops at load. - Linux: not tested. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-02 13:43:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T13:43:54Z.


Progress report (a4157bb → ba51236)

📈 System libraries: 80.82% (+0.02%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel sceKernelSyncOnAddressWait
libkernel sceKernelSyncOnAddressWake
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5953746198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/349#issuecomment-5953746198). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T13:43:54Z. --- <!-- progress-report --> ### Progress report (a4157bb → ba51236) 📈 **System libraries**: 80.82% (+0.02%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelSyncOnAddressWait` | | libkernel | `sceKernelSyncOnAddressWake` | </details>
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!349
No description provided.