feat(libc): implement std::_Atomic_assert #7851
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7851"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 aNotImplementedstub inExport.cpp. It now sits next to_Assertinsrc/StdioExtras.cppand follows the same pattern: write the message to stderr, then abort.The message format comes from the retail
libc.prx(J03848509), which writesexpression, then" in function "andfunctionwhenfunctionis non-null, then"\n". The console brackets this withsceKernelDebugRaiseExceptionOnReleaseMode(0xa0020007, 0)andsceKernelDebugRaiseException(0xa0020007, 0)followed byud2. libc can't reach libkernel, so this usesstd::abort()like_Assert. A nullexpressionprints nothing for it instead of faulting.Tested
Linux (CachyOS, GCC Release). The new
guest_atomic_asserttest forks, calls the export with and without a function name, and checks the exact stderr text and SIGABRT. All 474guest_*tests pass. The NID drops off the libc todo list intools/progress.py.tools/check_conventions.pypasses.tools/pr_overlap.py --branchreports no line overlap. The only shared hunk is the libc test CMake, which #6044 moves along with every other test.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:09:56Z.
Review: APPROVED
Reviewed the diff:
core/libs/prx/libc/Export.cppwith a clean Dinkumware implementation inStdioExtras.cpp, writingexpressionand optionalfunctionto stderr before callingstd::abort().Export.cpp.GuestAtomicAssert.cppusespipe()/fork()/waitpid()to verify child process abort behavior and output formatting, and is correctly gated underif(UNIX)inlibc/CMakeLists.txtso Windows builds are unaffected.Ready to merge.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Athen2045 on 2026-10-20T05:50:25Z.
Windows run of
727c28a96merged ontomain3611cda29(Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,BUILD_TESTING=ON):guest_atomic_assertis not registered on Windows. It sits in theif(UNIX)block and usesfork, so the export has no automated Windows coverage. I called it from a small harness instead (not committed). The harness loads the patchedlibc.prx, resolvesu2tMGOLaqnE, calls it in a child process and captures stderr and the exit code.("invalid memory order", "atomic_load"): the first stderr line is exactlyinvalid memory order in function atomic_load.("invalid memory order", nullptr): the first line is exactlyinvalid memory order.FATAL: abort() (SIGABRT) on thread ...and a backtrace), and the process exits with0xc0000409._Asserttakes the samestd::abort()path, so on Windows the whole of stderr differs from what the Linux test expects, but the message line matches.mainthe same calls end with[libc] unhandled exception 'St13runtime_error'from theNotImplementedstub.select_tests.py ctest ... --timeout 120): 1708 of 1713 pass on the merge. The same 5 tests fail onmainon this machine:conventions_env_reference,conventions_blob_reads,windows_import_modules,agc_driver_msaa_dcc_clear_4andagc_driver_pass_input_hazard.If Windows coverage is wanted, a variant could spawn itself with
CreateProcessW, asGuestFileLock.cppandGuestHeapRounding.cppdo, and check the first stderr line and the0xc0000409exit.AI-assisted: yes (Claude Code). The results above were run on this machine.
Edit: corrected the base commit from
585075cb7to3611cda29, themainthese runs were actually built on. The results are unchanged.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
0xc0000409exit coming from the samestd::abort()path_Asserttakes. You're right thatguest_atomic_assertis Unix-only because offork. I don't have a Windows toolchain here, so I'd rather not push aCreateProcessWvariant I can't build or run. If you'd like to add it along the lines ofGuestFileLock.cpp, checking the first stderr line and the0xc0000409exit, I'd welcome it here or as a follow-up. Otherwise I'll leave the PR as it is.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 movesguest_fopen_errorsout of theif(UNIX)block incore/libs/prx/libc/CMakeLists.txt, right next to where this PR addsguest_atomic_assert, so the two conflict textually in that one hunk and nowhere else. Proposal: neither depends on the other. Whichever merges second keepsguest_atomic_assertinsideif(UNIX)andguest_fopen_errorsoutside it. Does that work for you? I'll record the agreed order in #9583's checklist.AI-assisted: yes
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_assertinsideif(UNIX)(it usesfork) andguest_fopen_errorsoutside it. If #9583 lands first, I'll mergemaininto this branch and resolve it that way.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
stderrstream. The implementation calls hoststd::fputs(..., stderr), which bypasses the guest_StderrFileStream. The reported retail routine calls the module’sfputsusing_Stderr, so guestfreopen/setvbufstate is honored. In this tree__stderrp_nid_postfixpoints at_Stderr_nid_postfix, andfputs_nid_postfixroutes through the guestFileStream; 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
expressionbehavior against the same SDK reference: this PR substitutes an empty string, whereas the reported console routine passes the pointer tofputs. 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.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 (tree92810a64d035efd27bb35de0da1cedfc204175e3). Environment: Linux x86-64, GCC 12.2.0.Results
StdioExtras.cpp,GuestAtomicAssert.cppgit diff --checkguest_atomic_assertbuild-reviewconfiguration is relinker-only and has noguest_atomic_assert_teststargetRaw local check output
Negative control
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
_Stderrimplementation at this headNot 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.