feat(libc): implement Cnd-init, spin-lock, unexpected and std-tag exports #18122

Merged
akkadbakkad89 merged 3 commits from upstream-pr/18122 into main 2026-11-18 05:03:37 +00:00
akkadbakkad89 commented 2026-11-10 14:24:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-11-10T14:24:22Z.


What

Adds real libc.prx exports for five named C++ runtime surfaces that titles import by symbol name:

  • _Lock_shared_ptr_spin_lock / _Unlock_shared_ptr_spin_lock (fRWufXAccuI, 1HYEoANqZ1w) - test-and-set byte with acquire/release ordering, matching the PPSA10665 libc.prx (xchg loop at 0x7cda0, byte-store release at 0x7cdb0 on the module flag at 0x10669c)
  • _Cnd_init_with_name (2B+V3qCqz4s) - delegates to _Cnd_init; the name is dropped like the sibling _Cnd_init_with_default_name_override because named conditions are not modelled
  • __cxa_call_unexpected (usKbuvy2hQg) - aliases __cxa_call_terminate; this library keeps no unexpected-handler state so every call reaches std::terminate, the ABI end state when no handler is installed
  • std:: tag and placeholder data exports (_ZSt10adopt_lock, _ZSt10defer_lock, _ZSt11try_to_lock, _ZSt6ignore, std::placeholders::_1.._20) as single zero bytes whose observable contract is address identity, and _ZSt14_Raise_handler as a null function pointer

All names are exported under the real firmware symbol names with _nid_postfix, so the NID patcher derives the recorded NIDs itself. The earlier forwarding-layer approach was dropped: main already inserts libc.prx into the import search order when libSceLibcInternal.prx is hosted, so these NIDs bind to real implementations without forwarders. fcloseall, the mspace heap-empty queries and the math exports were dropped from this PR's scope in favour of #11831, #10397 and #8417/#6295 respectively.

Tested

Windows 11, MinGW GCC 15.2.0. New focused test guest_libc_named_exports exercises every added export: spin-lock acquire/release roundtrip, _Cnd_init_with_name success + null-handle std::invalid_argument, tag/placeholder address distinctness, _Raise_handler == nullptr, and __cxa_call_unexpected resolving (fork-based SIGABRT death check on non-Windows). Full guest_libc suite 48/48 including all guest_libc_internal_* tests. Export presence verified in the built libc.prx PE export table. Not run on Linux or a console.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5242935929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18122). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-11-10T14:24:22Z. --- ### What Adds real `libc.prx` exports for five named C++ runtime surfaces that titles import by symbol name: - `_Lock_shared_ptr_spin_lock` / `_Unlock_shared_ptr_spin_lock` (`fRWufXAccuI`, `1HYEoANqZ1w`) - test-and-set byte with acquire/release ordering, matching the PPSA10665 `libc.prx` (`xchg` loop at `0x7cda0`, byte-store release at `0x7cdb0` on the module flag at `0x10669c`) - `_Cnd_init_with_name` (`2B+V3qCqz4s`) - delegates to `_Cnd_init`; the name is dropped like the sibling `_Cnd_init_with_default_name_override` because named conditions are not modelled - `__cxa_call_unexpected` (`usKbuvy2hQg`) - aliases `__cxa_call_terminate`; this library keeps no unexpected-handler state so every call reaches `std::terminate`, the ABI end state when no handler is installed - `std::` tag and placeholder data exports (`_ZSt10adopt_lock`, `_ZSt10defer_lock`, `_ZSt11try_to_lock`, `_ZSt6ignore`, `std::placeholders::_1`..`_20`) as single zero bytes whose observable contract is address identity, and `_ZSt14_Raise_handler` as a null function pointer All names are exported under the real firmware symbol names with `_nid_postfix`, so the NID patcher derives the recorded NIDs itself. The earlier forwarding-layer approach was dropped: main already inserts `libc.prx` into the import search order when `libSceLibcInternal.prx` is hosted, so these NIDs bind to real implementations without forwarders. `fcloseall`, the mspace heap-empty queries and the math exports were dropped from this PR's scope in favour of #11831, #10397 and #8417/#6295 respectively. ### 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 11, MinGW GCC 15.2.0. New focused test `guest_libc_named_exports` exercises every added export: spin-lock acquire/release roundtrip, `_Cnd_init_with_name` success + null-handle `std::invalid_argument`, tag/placeholder address distinctness, `_Raise_handler == nullptr`, and `__cxa_call_unexpected` resolving (fork-based SIGABRT death check on non-Windows). Full `guest_libc` suite 48/48 including all `guest_libc_internal_*` tests. Export presence verified in the built `libc.prx` PE export table. Not run on Linux or a console. ### 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
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!18122
No description provided.