feat(libc): implement std::_Atomic_assert #7851

Merged
hypermoist merged 7 commits from upstream-pr/7851 into main 2026-11-08 08:16:14 +00:00
hypermoist commented 2026-10-19 11:01:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-19T11:01:04Z.


What

Implements std::_Atomic_assert(const char* expression, const char* function) (_ZSt14_Atomic_assertPKcS0_, u2tMGOLaqnE), which was a NotImplemented stub in Export.cpp. It now sits next to _Assert in src/StdioExtras.cpp and follows the same pattern: write the message to stderr, then abort.

The message format comes from the retail libc.prx (J03848509), which writes expression, then " in function " and function when function is non-null, then "\n". The console brackets this with sceKernelDebugRaiseExceptionOnReleaseMode(0xa0020007, 0) and sceKernelDebugRaiseException(0xa0020007, 0) followed by ud2. libc can't reach libkernel, so this uses std::abort() like _Assert. A null expression prints nothing for it instead of faulting.

Tested

Linux (CachyOS, GCC Release). The new guest_atomic_assert test forks, calls the export with and without a function name, and checks the exact stderr text and SIGABRT. All 474 guest_* tests pass. The NID drops off the libc todo list in tools/progress.py. tools/check_conventions.py passes. tools/pr_overlap.py --branch reports no line overlap. The only shared hunk is the libc test CMake, which #6044 moves along with every other test.

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:4919887853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-19T11:01:04Z. --- ### What Implements `std::_Atomic_assert(const char* expression, const char* function)` (`_ZSt14_Atomic_assertPKcS0_`, `u2tMGOLaqnE`), which was a `NotImplemented` stub in `Export.cpp`. It now sits next to `_Assert` in `src/StdioExtras.cpp` and follows the same pattern: write the message to stderr, then abort. The message format comes from the retail `libc.prx` (J03848509), which writes `expression`, then `" in function "` and `function` when `function` is non-null, then `"\n"`. The console brackets this with `sceKernelDebugRaiseExceptionOnReleaseMode(0xa0020007, 0)` and `sceKernelDebugRaiseException(0xa0020007, 0)` followed by `ud2`. libc can't reach libkernel, so this uses `std::abort()` like `_Assert`. A null `expression` prints nothing for it instead of faulting. ### Tested Linux (CachyOS, GCC Release). The new `guest_atomic_assert` test forks, calls the export with and without a function name, and checks the exact stderr text and SIGABRT. All 474 `guest_*` tests pass. The NID drops off the libc todo list in `tools/progress.py`. `tools/check_conventions.py` passes. `tools/pr_overlap.py --branch` reports no line overlap. The only shared hunk is the libc test CMake, which #6044 moves along with every other test. ### 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: 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)
fogydes commented 2026-10-19 12:09:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:09:56Z.

Review: APPROVED


Reviewed the diff:

  • Replaces the legacy placeholder stub in core/libs/prx/libc/Export.cpp with a clean Dinkumware implementation in StdioExtras.cpp, writing expression and optional function to stderr before calling std::abort().
  • Removes the non-compliant legacy comment from Export.cpp.
  • GuestAtomicAssert.cpp uses pipe() / fork() / waitpid() to verify child process abort behavior and output formatting, and is correctly gated under if(UNIX) in libc/CMakeLists.txt so Windows builds are unaffected.
  • Zero comments added in code; Conventional Commits title; all checklist items verified.

Ready to merge.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5571319940 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#pullrequestreview-5571319940). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-19T12:09:56Z. **Review:** APPROVED --- Reviewed the diff: - Replaces the legacy placeholder stub in `core/libs/prx/libc/Export.cpp` with a clean Dinkumware implementation in `StdioExtras.cpp`, writing `expression` and optional `function` to stderr before calling `std::abort()`. - Removes the non-compliant legacy comment from `Export.cpp`. - `GuestAtomicAssert.cpp` uses `pipe()` / `fork()` / `waitpid()` to verify child process abort behavior and output formatting, and is correctly gated under `if(UNIX)` in `libc/CMakeLists.txt` so Windows builds are unaffected. - Zero comments added in code; Conventional Commits title; all checklist items verified. Ready to merge. AI-assisted: yes
Athen2045 commented 2026-10-20 05:50:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Athen2045 on 2026-10-20T05:50:25Z.


Windows run of 727c28a96 merged onto main 3611cda29 (Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON):

  • Build: clean, with no warnings in the changed files.
  • guest_atomic_assert is not registered on Windows. It sits in the if(UNIX) block and uses fork, so the export has no automated Windows coverage. I called it from a small harness instead (not committed). The harness loads the patched libc.prx, resolves u2tMGOLaqnE, calls it in a child process and captures stderr and the exit code.
    • ("invalid memory order", "atomic_load"): the first stderr line is exactly invalid memory order in function atomic_load.
    • ("invalid memory order", nullptr): the first line is exactly invalid memory order.
    • In both cases libc's Windows crash report follows (FATAL: abort() (SIGABRT) on thread ... and a backtrace), and the process exits with 0xc0000409. _Assert takes the same std::abort() path, so on Windows the whole of stderr differs from what the Linux test expects, but the message line matches.
  • Negative control: against main the same calls end with [libc] unhandled exception 'St13runtime_error' from the NotImplemented stub.
  • Full suite (select_tests.py ctest ... --timeout 120): 1708 of 1713 pass on the merge. The same 5 tests fail on main on this machine: conventions_env_reference, conventions_blob_reads, windows_import_modules, agc_driver_msaa_dcc_clear_4 and agc_driver_pass_input_hazard.

If Windows coverage is wanted, a variant could spawn itself with CreateProcessW, as GuestFileLock.cpp and GuestHeapRounding.cpp do, and check the first stderr line and the 0xc0000409 exit.

AI-assisted: yes (Claude Code). The results above were run on this machine.

Edit: corrected the base commit from 585075cb7 to 3611cda29, the main these runs were actually built on. The results are unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284376190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#issuecomment-6284376190). Originally posted by [Athen2045](https://github.com/Athen2045) on 2026-10-20T05:50:25Z. --- Windows run of 727c28a96 merged onto `main` 3611cda29 (Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`): - **Build:** clean, with no warnings in the changed files. - **`guest_atomic_assert` is not registered on Windows.** It sits in the `if(UNIX)` block and uses `fork`, so the export has no automated Windows coverage. I called it from a small harness instead (not committed). The harness loads the patched `libc.prx`, resolves `u2tMGOLaqnE`, calls it in a child process and captures stderr and the exit code. - `("invalid memory order", "atomic_load")`: the first stderr line is exactly `invalid memory order in function atomic_load`. - `("invalid memory order", nullptr)`: the first line is exactly `invalid memory order`. - In both cases libc's Windows crash report follows (`FATAL: abort() (SIGABRT) on thread ...` and a backtrace), and the process exits with `0xc0000409`. `_Assert` takes the same `std::abort()` path, so on Windows the whole of stderr differs from what the Linux test expects, but the message line matches. - **Negative control:** against `main` the same calls end with `[libc] unhandled exception 'St13runtime_error'` from the `NotImplemented` stub. - **Full suite** (`select_tests.py ctest ... --timeout 120`): 1708 of 1713 pass on the merge. The same 5 tests fail on `main` on this machine: `conventions_env_reference`, `conventions_blob_reads`, `windows_import_modules`, `agc_driver_msaa_dcc_clear_4` and `agc_driver_pass_input_hazard`. If Windows coverage is wanted, a variant could spawn itself with `CreateProcessW`, as `GuestFileLock.cpp` and `GuestHeapRounding.cpp` do, and check the first stderr line and the `0xc0000409` exit. AI-assisted: yes (Claude Code). The results above were run on this machine. Edit: corrected the base commit from 585075cb7 to 3611cda29, the `main` these runs were actually built on. The results are unchanged.
hypermoist commented 2026-10-21 08:42:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T08:42:27Z.


@Athen2045 thanks for the Windows run and the negative control. Good to have confirmation that the message line matches on Windows, with the 0xc0000409 exit coming from the same std::abort() path _Assert takes. You're right that guest_atomic_assert is Unix-only because of fork. I don't have a Windows toolchain here, so I'd rather not push a CreateProcessW variant I can't build or run. If you'd like to add it along the lines of GuestFileLock.cpp, checking the first stderr line and the 0xc0000409 exit, I'd welcome it here or as a follow-up. Otherwise I'll leave the PR as it is.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311818257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#issuecomment-6311818257). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-21T08:42:27Z. --- @Athen2045 thanks for the Windows run and the negative control. Good to have confirmation that the message line matches on Windows, with the `0xc0000409` exit coming from the same `std::abort()` path `_Assert` takes. You're right that `guest_atomic_assert` is Unix-only because of `fork`. I don't have a Windows toolchain here, so I'd rather not push a `CreateProcessW` variant I can't build or run. If you'd like to add it along the lines of `GuestFileLock.cpp`, checking the first stderr line and the `0xc0000409` exit, I'd welcome it here or as a follow-up. Otherwise I'll leave the PR as it is.
DavidSamir commented 2026-10-22 08:49:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:49:56Z.


Hi @hypermoist, a merge-order note for #9583 (test(libc): run guest_fopen_errors on Windows). It moves guest_fopen_errors out of the if(UNIX) block in core/libs/prx/libc/CMakeLists.txt, right next to where this PR adds guest_atomic_assert, so the two conflict textually in that one hunk and nowhere else. Proposal: neither depends on the other. Whichever merges second keeps guest_atomic_assert inside if(UNIX) and guest_fopen_errors outside it. Does that work for you? I'll record the agreed order in #9583's checklist.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336709333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#issuecomment-6336709333). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T08:49:56Z. --- Hi @hypermoist, a merge-order note for #9583 (`test(libc): run guest_fopen_errors on Windows`). It moves `guest_fopen_errors` out of the `if(UNIX)` block in `core/libs/prx/libc/CMakeLists.txt`, right next to where this PR adds `guest_atomic_assert`, so the two conflict textually in that one hunk and nowhere else. Proposal: neither depends on the other. Whichever merges second keeps `guest_atomic_assert` inside `if(UNIX)` and `guest_fopen_errors` outside it. Does that work for you? I'll record the agreed order in #9583's checklist. AI-assisted: yes
hypermoist commented 2026-10-22 08:52:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T08:52:33Z.


@DavidSamir that works for me. Neither PR depends on the other, and whichever merges second keeps guest_atomic_assert inside if(UNIX) (it uses fork) and guest_fopen_errors outside it. If #9583 lands first, I'll merge main into this branch and resolve it that way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336757012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#issuecomment-6336757012). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-22T08:52:33Z. --- @DavidSamir that works for me. Neither PR depends on the other, and whichever merges second keeps `guest_atomic_assert` inside `if(UNIX)` (it uses `fork`) and `guest_fopen_errors` outside it. If #9583 lands first, I'll merge `main` into this branch and resolve it that way.
MarcZX10 commented 2026-10-27 02:21:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T02:21:23Z.

Review: CHANGES_REQUESTED


I’m updating my earlier approval after checking the SDK 7.00 behavior report in the disassembly comparison against the current stream wrappers.

[P2] Write the diagnostic through the guest stderr stream. The implementation calls host std::fputs(..., stderr), which bypasses the guest _Stderr FileStream. The reported retail routine calls the module’s fputs using _Stderr, so guest freopen/setvbuf state is honored. In this tree __stderrp_nid_postfix points at _Stderr_nid_postfix, and fputs_nid_postfix routes through the guest FileStream; please use that guest stream path (including its status/locking behavior) before aborting. Add a regression that redirects guest stderr and verifies the assertion text reaches the redirected stream; the existing fork test only redirects the host descriptor and therefore cannot detect this mismatch.

Please also resolve the null expression behavior against the same SDK reference: this PR substitutes an empty string, whereas the reported console routine passes the pointer to fputs. Don’t add a made-up success or message for that input; document and test the supported behavior consistent with the project’s conventions and the observed ABI.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661510438 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#pullrequestreview-5661510438). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T02:21:23Z. **Review:** CHANGES_REQUESTED --- I’m updating my earlier approval after checking the SDK 7.00 behavior report in [the disassembly comparison](https://github.com/boykopovar/AnyPS5/pull/7851#issuecomment-6421840856) against the current stream wrappers. **[P2] Write the diagnostic through the guest `stderr` stream.** The implementation calls host `std::fputs(..., stderr)`, which bypasses the guest `_Stderr` `FileStream`. The reported retail routine calls the module’s `fputs` using `_Stderr`, so guest `freopen`/`setvbuf` state is honored. In this tree `__stderrp_nid_postfix` points at `_Stderr_nid_postfix`, and `fputs_nid_postfix` routes through the guest `FileStream`; please use that guest stream path (including its status/locking behavior) before aborting. Add a regression that redirects guest stderr and verifies the assertion text reaches the redirected stream; the existing fork test only redirects the host descriptor and therefore cannot detect this mismatch. Please also resolve the null `expression` behavior against the same SDK reference: this PR substitutes an empty string, whereas the reported console routine passes the pointer to `fputs`. Don’t add a made-up success or message for that input; document and test the supported behavior consistent with the project’s conventions and the observed ABI.
MarcZX10 commented 2026-10-29 12:03:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T12:03:05Z.

Review: APPROVED


Re-checked — new head, looks good

The new head resolves the two earlier findings: the diagnostic uses guest _Stderr, redirected guest stderr is tested, and the null-expression path is no longer replaced with an empty string.

What I ran

Exact head: 5ff0e821f6fea62e78559d73572821bd7e2e844f. Current upstream base: ba5b5330b37724bca4b99f30faab504653635a04. The current-main merge preview completed cleanly (tree 92810a64d035efd27bb35de0da1cedfc204175e3). Environment: Linux x86-64, GCC 12.2.0.

g++ -std=c++20 -I/tmp/AnyPS5-mention-head.ciGWED -Icore/libs -fsyntax-only /tmp/AnyPS5-mention-head.ciGWED/StdioExtras.cpp
g++ -std=c++20 -I/tmp/AnyPS5-mention-head.ciGWED -Icore/libs -fsyntax-only /tmp/AnyPS5-mention-head.ciGWED/GuestAtomicAssert.cpp
git diff --check fe2b52c7e431969782351d7d53fe0f7f9e0f344b..refs/review/mention-7851 -- core/libs/prx/libc/src/StdioExtras.cpp core/libs/tests/GuestAtomicAssert.cpp docs/dev/debt/libc.md

Results

Check Result
GCC syntax-only: StdioExtras.cpp, GuestAtomicAssert.cpp Passed locally
git diff --check Passed locally (exit 0)
Current-main merge preview Clean; tree SHA above
guest_atomic_assert Author reports passing on this exact head in the follow-up
Hosted checks Eligibility, conventions, labels, report, and relinker jobs passed; Linux and Windows product jobs were skipped
Local CTest Not run: the existing build-review configuration is relinker-only and has no guest_atomic_assert_tests target
Raw local check output
StdioExtras.cpp: PASS
GuestAtomicAssert.cpp: PASS
7851 diff-check exit=0
92810a64d035efd27bb35de0da1cedfc204175e3
ninja: error: unknown target 'guest_atomic_assert_tests'
No tests were found!!!

Negative control

Assertion Code mutation Result
Not run No mutation-based negative control was run on this head Not exercised

Findings

Blocking

None found in the reviewed changes.

Non-blocking

The full local target and product build were not available in this relinker-only build configuration. The author reports the focused test on the exact head; hosted product build jobs were skipped.

Sources

Not verified

I did not run the focused test or a full product build locally, and did not verify console behavior beyond the linked SDK 7.00 evidence recorded by the PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697341943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7851#pullrequestreview-5697341943). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T12:03:05Z. **Review:** APPROVED --- # Re-checked — new head, looks good The new head resolves the two earlier findings: the diagnostic uses guest `_Stderr`, redirected guest stderr is tested, and the null-expression path is no longer replaced with an empty string. ### What I ran Exact head: `5ff0e821f6fea62e78559d73572821bd7e2e844f`. Current upstream base: `ba5b5330b37724bca4b99f30faab504653635a04`. The current-main merge preview completed cleanly (tree `92810a64d035efd27bb35de0da1cedfc204175e3`). Environment: Linux x86-64, GCC 12.2.0. ```sh g++ -std=c++20 -I/tmp/AnyPS5-mention-head.ciGWED -Icore/libs -fsyntax-only /tmp/AnyPS5-mention-head.ciGWED/StdioExtras.cpp g++ -std=c++20 -I/tmp/AnyPS5-mention-head.ciGWED -Icore/libs -fsyntax-only /tmp/AnyPS5-mention-head.ciGWED/GuestAtomicAssert.cpp git diff --check fe2b52c7e431969782351d7d53fe0f7f9e0f344b..refs/review/mention-7851 -- core/libs/prx/libc/src/StdioExtras.cpp core/libs/tests/GuestAtomicAssert.cpp docs/dev/debt/libc.md ``` ### Results | Check | Result | |---|---| | GCC syntax-only: `StdioExtras.cpp`, `GuestAtomicAssert.cpp` | Passed locally | | `git diff --check` | Passed locally (exit 0) | | Current-main merge preview | Clean; tree SHA above | | `guest_atomic_assert` | Author reports passing on this exact head in [the follow-up](https://github.com/boykopovar/AnyPS5/pull/7851#issuecomment-6422408142) | | Hosted checks | Eligibility, conventions, labels, report, and relinker jobs passed; Linux and Windows product jobs were skipped | | Local CTest | Not run: the existing `build-review` configuration is relinker-only and has no `guest_atomic_assert_tests` target | <details> <summary>Raw local check output</summary> ```text StdioExtras.cpp: PASS GuestAtomicAssert.cpp: PASS 7851 diff-check exit=0 92810a64d035efd27bb35de0da1cedfc204175e3 ninja: error: unknown target 'guest_atomic_assert_tests' No tests were found!!! ``` </details> ### Negative control | Assertion | Code mutation | Result | |---|---|---| | Not run | No mutation-based negative control was run on this head | Not exercised | ### Findings #### Blocking None found in the reviewed changes. #### Non-blocking The full local target and product build were not available in this relinker-only build configuration. The author reports the focused test on the exact head; hosted product build jobs were skipped. ### Sources - [Guest `_Stderr` implementation at this head](https://github.com/boykopovar/AnyPS5/blob/5ff0e821f6fea62e78559d73572821bd7e2e844f/core/libs/prx/libc/src/StdioExtras.cpp#L84-L95) - [Redirection and null-expression tests at this head](https://github.com/boykopovar/AnyPS5/blob/5ff0e821f6fea62e78559d73572821bd7e2e844f/core/libs/tests/GuestAtomicAssert.cpp#L49-L85) - [Recorded behavior limits at this head](https://github.com/boykopovar/AnyPS5/blob/5ff0e821f6fea62e78559d73572821bd7e2e844f/docs/dev/debt/libc.md#L65) ### Not verified I did not run the focused test or a full product build locally, and did not verify console behavior beyond the linked SDK 7.00 evidence recorded by the PR.
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!7851
No description provided.