fix(libkernel): report a child's stop and kill signals correctly on macOS hosts #11801
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11801"
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 jotitadev on 2026-10-27T08:17:49Z.
What
guest_posix_spawnfails on macOS for two reasons. Each one is a separate commit.1.
waitpidtranslates signals that are already in the FreeBSD numbering (libkernel,Process.cpp).waitpid_nid_postfixmaps the stop and termination signal of a child from the Linux numbering to the FreeBSD one on every non-Windows host. Darwin already uses the BSD numbering, which matches FreeBSD for signals 1 to 31, so on macOS the table moves signals that were already correct:SIGSTOPSIGBUSSIGSYSSIGUSR1NotImplemented("without a guest equivalent")The table now applies only off macOS, so macOS passes the host signal through. Linux is unchanged.
2. The macOS write watch swallows a
SIGBUSorSIGSEGVsent withraiseorkill(libc,GuestWriteWatch.cpp). The write watch installs a process-wide handler for both signals at startup. When a signal is not a write to a watched page and no handler was there before, the handler restores the default action and returns. For a real fault that is enough: the instruction runs again and the process dies. A sent signal does not run again, so the process just keeps going. The spawn test'schild-kill-buschild callsstd::raise(SIGBUS)and, instead of dying, falls through tostd::_Exit(99). WithAPS5_NO_WRITE_WATCH=1the child dies withSIGBUSas expected.The handler now raises the signal again after restoring the default action. The signal stays blocked until the handler returns, so a real fault still ends with the same signal, and a sent one now does too. If
SIG_IGNwas inherited, the behaviour stays as before. Linux has no handler here, since its write watch uses userfaultfd.Tests:
GuestPosixSpawn.cppfinds its own executable with_NSGetExecutablePathon macOS instead of/proc/self/exe, using the same pattern asSpawn.cpp. It also adds a child killed bySIGUSR1, expected as guest 30. That number differs between Linux (10) and FreeBSD (30), and macOS used to reject it.write_watch_raisedis a new mode ofwrite_watch_tests. It forks children thatraise(SIGBUS)andraise(SIGSEGV)and requires that each one is terminated by that signal. The write watch test builds on its own frommainon macOS, so this one runs without the port PRs.Tested
Apple M2 Max, macOS 27.2, Apple clang 21, x86-64 Release under Rosetta 2.
mainalone does not build libkernel's tests on macOS, soguest_posix_spawnran onmain2f0a0071f5plus the open macOS build PRs (#7631, #11249, #11358, #10669, #10552, #7804, #11447, #11437, #11554), with both commits cherry-picked on top.guest_posix_spawnstops atGuestPosixSpawn.cpp:225, the copy of its own executable, because there is no/proc/self/exe.waitpidcommit, it fails at :319 (SIGSTOPreported as 20), 3 out of 3.SIGBUSchild exits with status 99), 3 out of 3.guest_posix_spawnand the 11write_watch_*tests pass 3 runs out of 3. No stopped children are left behind.write_watch_raisedonmainalone (standalonecore/libs/tests/write_watchbuild): it fails witha raised fault signal does not terminate the processwithout theGuestWriteWatch.cppchange, and the 11 tests pass 3 out of 3 with it.guest_posix_spawn. The ones that still fail are known Rosetta FP failures (guest_raise_except*) or tests that do not build there (#4630).guest_posix_spawn(including the newSIGUSR1child, 10 → 30) andguest_waitpidpass 3 out of 3.waitpidchange is in the non-Windows branch, and the spawn test's new child is under#ifndef _WIN32.check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionswaitpidon macOS, andguest_posix_spawnneeds both. I can split them if you prefer.NotImplemented_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)guest_posix_spawnon macOS also needs #11358 (environ) and the open macOS build PRs listed above.🤖 Generated with Claude Code