test(libkernel): throw through the guest runtime on macOS in the host standard error test #9654
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9654"
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 rooklz on 2026-10-22T06:23:43Z.
What
guest_host_standard_errorfails on macOS hosts at the terminate check of its redirected child. On Linux the child'sthrow std::runtime_error("report kept")resolves to libc's__cxa_throwalias (GCC_GLOBAL_ALIASinprx/libc/src/exception/Exports.cpp), so the guest runtime inprx/libc/src/exception/Runtime.cppwrites thewhat(): report keptline the test looks for.GCC_GLOBAL_ALIASexpands to nothing outside Linux, so on macOS the throw goes straight to the host's libc++abi, which prints its own line and the guest runtime never takes part.On macOS the child now throws through the guest runtime itself: it allocates the exception with
__cxa_allocate_exception_nid_postfixand raises it with__cxa_throw_nid_postfix, which is what the Linux alias does for it. The expected text is unchanged on every host, so the test checks AnyPS5's terminate report on macOS too. This is the construction #8658 uses for the same test; @jotitadev pointed it out in review of the first version of this PR, which instead matched libc++abi's own message and so checked the host runtime rather than ours.Tested
ci/macos-series-2at53db0badbwith #7524, the code of #7937 and the libSceSsl change of #7332, plus715fe9ca26,c03168fb47andfb0b5ca919frommaincherry-picked so the file's newer sections compile. The two terminate runs (dup2 and freopen) pass: the host pipe receiveshost, the[libc] unhandled exceptionline,terminate called after throwing an instance of 'std::runtime_error'andwhat(): report kept, and the probe file keeps onlyguest. Without this change those runs fail at thewhat()check. The file's later guest-stdio section (fromc03168fb47) does not complete on that tree, whose base predates it, so I could not run the whole binary to the end there; @jotitadev reports the same construction passing 3 of 3 on #8658 atfbb251c25on an M2 Max.27e968974with other open macOS fixes, toggling only this PR: without itguest_host_standard_erroraborts at thewhat(): report keptcheck (GuestHostStandardError.cpp:104); with it the test passes to the end, the guest-stdio section after the terminate runs included, which my M5 tree could not reach.guest_host_standard_errorpasses on this head in a verify run on my fork. The throw line there is unchanged.check_conventions.pypasses.pr_overlap.pyreports no conflicting lines; #6044 shares the file but conflicts withmain. #8658 edits the same hunk with the same code, so whichever lands first, the other's hunk becomes a no-op.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:13:30Z.
Review: CHANGES_REQUESTED
The macOS-specific expected line matches the libc++abi output documented in the PR, and Linux/Windows retain their existing assertion. Exact-head diff-check and conventions pass. Platform test jobs are skipped here, so the reported three macOS runs are the available runtime evidence; I could not reproduce them locally. I found no issue with the conditional assertion.\n\nTwo process points remain. First, the PR changes
GuestHostStandardError.cpp, which open #8658 also modifies; a merge-tree combines the separate hunks cleanly, but please coordinate the merge order with that author and record that this fix is part of the macOS test support.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T10:57:21Z.
Review: COMMENTED
With this change, the test on macOS no longer checks AnyPS5's terminate report. It checks the host C++ runtime's report. Head
aa9e11f9a.On Linux,
throwin the child resolves to libc's__cxa_throwalias (GCC_GLOBAL_ALIAS(__cxa_throw, __cxa_throw_nid_postfix)inprx/libc/src/exception/Exports.cpp). Thewhat(): report keptline is written by AnyPS5's terminate inprx/libc/src/exception/Runtime.cpp, not by libstdc++.GCC_GLOBAL_ALIASexpands to nothing outside Linux (specifics/gcc/SymbolAlias.hpp). So on macOS the throw goes straight to libc++abi, and the libc++abi line this PR expects is the host runtime's own report. That report goes to host fd 2 whatever the guest did with its descriptor 2, so the check passes without the guest runtime taking part.I checked this on Apple M2 Max, macOS 27.2, Apple clang 21, x86-64 under Rosetta 2, on #8658 @
fbb251c25. I printedterminated.hostin the test:host\nlibc++abi: terminating due to uncaught exception of type std::runtime_error: report kept\n. Passes 3/3.__cxa_allocate_exception_nid_postfix/__cxa_throw_nid_postfixdirectly on macOS and keeps the original assertion:host\n[libc] unhandled exception 'St13runtime_error' thrown from 0x…\nterminate called after throwing an instance of 'std::runtime_error'\n what(): report kept\n. Passes 3/3.Both pass. Only #8658's version checks on macOS the same thing the test checks on Linux. If this PR goes in first, it could throw through
__cxa_throw_nid_postfixon macOS, as #8658 does, rather than change the expected text.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T12:04:16Z.
@jotitadev you're right, that checked libc++abi rather than our runtime. Head
209a55a979now throws through__cxa_allocate_exception_nid_postfixand__cxa_throw_nid_postfixon macOS, the construction from #8658, and the expected text is the same on every host. The description has the details of what I could run: the two terminate runs pass on my tree and capture the guest report ([libc] unhandled exception,terminate called after throwing an instance of 'std::runtime_error',what(): report kept), and without the change they fail at thewhat()check. The file's later guest-stdio section fromc03168fb47doesn't complete on my older tree, so I'm citing your 3 of 3 on #8658 for the whole binary rather than claiming it myself.@MarcZX10 on merge order with #8658: the macOS hunk is now the same code, so whichever lands first the other's hunk is a no-op. On the #5239 direction: this is a test fix for the macOS work on #1, not a title; I'm fine holding it or closing it in favour of #8658 if a maintainer prefers.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:41:56Z.
Review: APPROVED
The current head now routes the macOS test throw through AnyPS5's guest exception runtime, matching the Linux path and preserving the original guest terminate-report assertion. This addresses the prior concern that the test was only checking libc++abi's host message. I fetched exact head
209a55a9;git diff --check upstream/main...HEADandpython3 tools/check_conventions.py --base upstream/main --head HEADboth pass. The author reports focused macOS runs passing, and #8658's author confirmed the same hunk and agreed whichever PR lands first makes the other's hunk a no-op. I did not run the C++ test locally; hosted product test jobs are skipped. I found no remaining code or coordination blocker and approve.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:34:34Z.
Rebased onto current
main(8b3e39832a): headf8ca673040, same diff.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T23:38:20Z.
Review: COMMENTED
Follow-up to my earlier review: with
f8ca673040the macOS path goes through the guest runtime again, so the originalwhat(): report keptassertion is checking AnyPS5's terminate report, not libc++abi's.maindoes not link on macOS, so I ran it on the macOS port branch (#8658 @f48446abb), whoseGuestHostStandardError.cppis identical to this head apart from one comment line. Apple M2 Max, macOS 27.2, x86_64 under Rosetta:ctest -R guest_host_standard_error --repeat until-fail:3passes 3/3.Written with AI assistance (Claude Code). I ran the test above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-26T22:46:29Z.
Review: APPROVED
Approving at
2a7220275c: the macOS throw still goes through the guest runtime, the test passes, andpublic_headerspasses now that the local declarations are gone. The two body fixes below are not blockers.Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
Applied at
2a7220275cto mugurc's macOS series (27e968974) merged withmainat2742004ed2, with other open macOS fixes, then toggled only this PR. Each side ran 3 times, and the "with" side ran another 20 times with--repeat until-fail:20.guest_host_standard_errorpublic_headerswhat(): report keptcheck (GuestHostStandardError.cpp:106at this head). The child's host pipe holdshost\nlibc++abi: terminating due to uncaught exception of type std::runtime_error: report kept\nhost,[libc] unhandled exception 'St13runtime_error' thrown from 0x…,terminate called after throwing an instance of 'std::runtime_error'andwhat(): report keptAt this head the macOS branch compiles against the declarations in
exceptions/Runtime.hpp, which come in throughprx/libc/include/Api.hpp. The new code adds no warnings; the 7 warnings in that compile are the existing C-linkage warnings fromGeneral.hppandApi.hpp. @oneandonlydean'spublic_headersfinding is fixed: the audit reported the two duplicates at0bc464eb0eand passes at2a7220275c.Notes
81b9dba21dfrom 2026-10-22, which is not one of this PR's commits. The build jobs at2a7220275careskipping. The evidence for this head is @rooklz's Docker run in the comment of 2026-10-26, so the bullet should cite that run instead.GuestHostStandardError.cpp. Since the construction comes from #8658, crediting its authoriamthehimanshwould be fair.GuestHostStandardError.cpp:70. The explicit guest throw depends on__APPLE__, while the alias it replaces is missing whenever the host is not__linux__(specifics/gcc/SymbolAlias.hpp). The test is registered for everyUNIXhost.#ifndef __linux__would match the alias condition, if a non-Linux, non-Apple UNIX host is meant to build these tests.throwin host-compiled code linked against libc still goes to libc++abi and skips the guest terminate report, becauseGCC_GLOBAL_ALIASis Linux-only and theasmshims inprx/libc/src/exception/Exports.cppare_WIN32-only. This test now goes around that gap, anddocs/dev/debt/libc.mddoes not mention it. A short debt entry, here or in a follow-up, would keep it visible.GuestHostStandardError.cpp:20.<typeinfo>already comes in throughexceptions/Runtime.hpp. An unconditional#include <new>next to the other standard headers would remove the#elifbranch.AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).