feat(libc): forward the std::atomic wait and notify helpers to libkernel #15561

Merged
Danigamer05 merged 2 commits from upstream-pr/15561 into main 2026-11-10 22:53:09 +00:00
Danigamer05 commented 2026-11-03 19:01:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-03T19:01:37Z.


What

Add the four atomic wait and notify helpers that the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6) exports for std::atomic::wait and notify:

Export NID Original RVA
__std_atomic_wait_direct_32 kSLphkBuz6E 0x10EA60
__std_atomic_wait_direct_64 kzfKNNi3eew 0x10EAE0
__std_atomic_notify_one_direct dlNEq6BfzDk 0x10EB60
__std_atomic_notify_all_direct TpT-GpWLpEo 0x10EBA0

In that module they only forward to libkernel:

  • the waits call sceKernelSyncOnAddressWait32/Wait64 with the address, the expected value and the name SceLibcV2AtomicWait. A timeout of 0xffffffff milliseconds passes no timeout. Any other passes milliseconds × 1000 as microseconds, or 0xffffffff when the timeout is 0x418938 milliseconds or more, including values wider than 32 bits. They return 1 whatever libkernel returns;
  • the notifies call sceKernelSyncOnAddressWake with 1 or 0x7fffffff waiters.

libc cannot call libkernel directly, so this follows the FilesystemForwards pattern: AtomicWaitForwards.hpp declares the three calls, libkernel's SyncOnAddress registers them when it loads, and libc's AtomicWait.cpp uses them. A libc waiter and a libkernel waiter therefore share libkernel's wait queue. Without libkernel loaded, the helpers throw.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main 1e658521a0a. Exact tested commit: 8fca613fad7.

  • Built libc, libkernel, their NID-patched production libraries and the related tests. The new guest_std_atomic_wait and guest_std_atomic_wait_kernel pass, along with libkernel's guest_sync_on_address tests, guest_sigvec, guest_sce_v2_filesystem_calls, guest_sce_v2_exceptions, guest_math_exact and public_headers.
  • guest_std_atomic_wait registers recording forwards and checks each argument: the address, the 32- and 64-bit expected values, the absent timeout for 0xffffffff, 0, 5, 0x418937 and 0x418938 milliseconds and a timeout wider than 32 bits, the name, the waiter counts, and that the waits return 1 when libkernel returns an error.
  • guest_std_atomic_wait_kernel links the real libkernel. A different value returns at once, a 20 ms wait times out after at least 15 ms, and a blocked libc waiter is released by libc's notify_all and by libkernel's sceKernelSyncOnAddressWake. A waiter blocked in sceKernelSyncOnAddressWait64 is released by libc's notify_one. It passed three runs in a row.
  • The forwarding, timeout conversion, name and waiter counts were read from the module's code. The helpers were not run side by side with the module: its copies call the same libkernel imports, so a side-by-side run would compare libkernel with itself.
  • Negative control: four lines were altered one at a time: the clamp threshold, an infinite wait passing a timeout, notify_all waking one waiter, and notify_one waking none. guest_std_atomic_wait failed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and both tests passed again.
  • Code conventions and git diff --check pass.
  • tools/pr_overlap.py read 1,772 open PRs and reports no overlap. It keeps exit 2 for 45 branches that already conflict with main. None of them names these helpers. Merging each of the 45 with this branch and with main using git merge-tree gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519 and #15552.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5142915673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15561). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-03T19:01:37Z. --- ### What Add the four atomic wait and notify helpers that the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`) exports for `std::atomic::wait` and `notify`: | Export | NID | Original RVA | | --- | --- | --- | | `__std_atomic_wait_direct_32` | `kSLphkBuz6E` | `0x10EA60` | | `__std_atomic_wait_direct_64` | `kzfKNNi3eew` | `0x10EAE0` | | `__std_atomic_notify_one_direct` | `dlNEq6BfzDk` | `0x10EB60` | | `__std_atomic_notify_all_direct` | `TpT-GpWLpEo` | `0x10EBA0` | In that module they only forward to libkernel: - the waits call `sceKernelSyncOnAddressWait32`/`Wait64` with the address, the expected value and the name `SceLibcV2AtomicWait`. A timeout of 0xffffffff milliseconds passes no timeout. Any other passes milliseconds × 1000 as microseconds, or 0xffffffff when the timeout is 0x418938 milliseconds or more, including values wider than 32 bits. They return 1 whatever libkernel returns; - the notifies call `sceKernelSyncOnAddressWake` with 1 or 0x7fffffff waiters. libc cannot call libkernel directly, so this follows the `FilesystemForwards` pattern: `AtomicWaitForwards.hpp` declares the three calls, libkernel's `SyncOnAddress` registers them when it loads, and libc's `AtomicWait.cpp` uses them. A libc waiter and a libkernel waiter therefore share libkernel's wait queue. Without libkernel loaded, the helpers throw. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows x86-64, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, main `1e658521a0a`. Exact tested commit: `8fca613fad7`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_std_atomic_wait` and `guest_std_atomic_wait_kernel` pass, along with libkernel's `guest_sync_on_address` tests, `guest_sigvec`, `guest_sce_v2_filesystem_calls`, `guest_sce_v2_exceptions`, `guest_math_exact` and `public_headers`. - `guest_std_atomic_wait` registers recording forwards and checks each argument: the address, the 32- and 64-bit expected values, the absent timeout for 0xffffffff, 0, 5, 0x418937 and 0x418938 milliseconds and a timeout wider than 32 bits, the name, the waiter counts, and that the waits return 1 when libkernel returns an error. - `guest_std_atomic_wait_kernel` links the real libkernel. A different value returns at once, a 20 ms wait times out after at least 15 ms, and a blocked libc waiter is released by libc's `notify_all` and by libkernel's `sceKernelSyncOnAddressWake`. A waiter blocked in `sceKernelSyncOnAddressWait64` is released by libc's `notify_one`. It passed three runs in a row. - The forwarding, timeout conversion, name and waiter counts were read from the module's code. The helpers were not run side by side with the module: its copies call the same libkernel imports, so a side-by-side run would compare libkernel with itself. - Negative control: four lines were altered one at a time: the clamp threshold, an infinite wait passing a timeout, `notify_all` waking one waiter, and `notify_one` waking none. `guest_std_atomic_wait` failed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and both tests passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,772 open PRs and reports no overlap. It keeps exit 2 for 45 branches that already conflict with main. None of them names these helpers. Merging each of the 45 with this branch and with main using `git merge-tree` gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519 and #15552. Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15561
No description provided.