fix(libkernel): let a guest ignore or catch SIGPIPE on Linux #11002

Merged
SandstromPL merged 7 commits from upstream-pr/11002 into main 2026-11-03 16:43:28 +00:00
SandstromPL commented 2026-10-25 13:58:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-25T13:58:54Z.


What

A write to a socket or pipe whose reader is gone fails with EPIPE and raises SIGPIPE: on FreeBSD the socket layer raises it for sockets, as soo_write does, and dofilewrite raises it for other files. A program that does not want a dropped connection to end it ignores SIGPIPE or catches it. Guest signals reach the host only for 2, 4, 6, 8, 11 and 15 (NativeSignal in Signals.cpp), so a guest's signal(SIGPIPE, SIG_IGN) or SIGPIPE handler was recorded but never applied. The host's SIGPIPE kept its default action and ended the process on the first such write. docs/dev/debt/libkernel.md lists this: "the guest cannot ignore it".

One title that does this is the VLC port (PPSA85300), whose web server ignores SIGPIPE for "a phone closing the page mid-answer" and then writes to the client socket.

Outside Windows, guest signal 13 is now the host's SIGPIPE, like the other six:

  • ignoring it makes the write return EPIPE;
  • a handler runs;
  • while 13 is blocked under a handler, it stays pending until unblocked.

As for the other mapped signals, blocking it under the default disposition does not stop the host's default action, which ends the process. The debt entry now says that. The other debt entries that list the mapped signals now include 13: the pending-signal entry, the sigaction entry's list of handlers that run, and the sigtimedwait entry. That entry also says what VLC's drain after a failed write finds.

GuestSignals used 13 as its example of a signal without a host equivalent; it uses 12 now.

The mapping is the smallest change to Signals.cpp, because #9499 reworks Dispatch, Install and pending delivery in the same file. This adds one case and one list entry there.

Tested

Linux (Ubuntu 24.04, GCC 13.3), this branch rebased onto main 636a9c1eec, after #10299:

  • New test guest_broken_pipe, registered outside Windows. A guest-side write to a socketpair whose peer is closed:
    • with 13 ignored, returns EPIPE (32);
    • with a guest handler, the handler runs once;
    • while 13 is blocked, it shows in sigpending and the handler runs when _sigprocmask unblocks it;
    • as in VLC's drain, while 13 is blocked under a handler, sigtimedwait with a zero timeout takes it, and the unblock then runs nothing;
    • with 13 ignored and blocked, nothing is pending: sigtimedwait returns EAGAIN, as FreeBSD 11.4's tdsendsignal discards an ignored signal whatever the mask.
  • On main the test is killed by the host signal (SIGPIPE***Exception). With this PR it passes.
  • guest_signals, guest_sigtimedwait, guest_signal_list, guest_signal_sets, guest_socket_pair and guest_recvmsg_memory pass.
  • All 700 guest_* tests, run before the rebase on main a5a780eaa: 699 pass. guest_usbd didn't run because its library needs the libusb submodule, which isn't checked out here.

Overlap: #11040 adds a pipe entry right after the read, write and vector I/O debt entry this PR updates, so whichever lands second has a small text conflict there. That entry says a Linux guest can't ignore the host SIGPIPE, and its author will update that clause if this PR lands first.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5005390057 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11002). Originally posted by [SandstromPL](https://github.com/SandstromPL) on 2026-10-25T13:58:54Z. --- ### What A write to a socket or pipe whose reader is gone fails with `EPIPE` and raises `SIGPIPE`: on FreeBSD the socket layer raises it for sockets, as [`soo_write`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/sys_socket.c#L147-L151) does, and [`dofilewrite`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_generic.c#L596-L599) raises it for other files. A program that does not want a dropped connection to end it ignores `SIGPIPE` or catches it. Guest signals reach the host only for 2, 4, 6, 8, 11 and 15 (`NativeSignal` in `Signals.cpp`), so a guest's `signal(SIGPIPE, SIG_IGN)` or `SIGPIPE` handler was recorded but never applied. The host's `SIGPIPE` kept its default action and ended the process on the first such write. `docs/dev/debt/libkernel.md` lists this: "the guest cannot ignore it". One title that does this is the VLC port (PPSA85300), whose web server ignores `SIGPIPE` for ["a phone closing the page mid-answer"](https://github.com/ZiZc3/VLC/blob/c1862643f/src/web.cc#L449) and then [`write`s](https://github.com/ZiZc3/VLC/blob/c1862643f/src/web.cc#L110) to the client socket. Outside Windows, guest signal 13 is now the host's `SIGPIPE`, like the other six: - ignoring it makes the write return `EPIPE`; - a handler runs; - while 13 is blocked under a handler, it stays pending until unblocked. As for the other mapped signals, blocking it under the default disposition does not stop the host's default action, which ends the process. The debt entry now says that. The other debt entries that list the mapped signals now include 13: the pending-signal entry, the `sigaction` entry's list of handlers that run, and the `sigtimedwait` entry. That entry also says what VLC's drain after a failed write finds. `GuestSignals` used 13 as its example of a signal without a host equivalent; it uses 12 now. The mapping is the smallest change to `Signals.cpp`, because #9499 reworks `Dispatch`, `Install` and pending delivery in the same file. This adds one `case` and one list entry there. ### Tested Linux (Ubuntu 24.04, GCC 13.3), this branch rebased onto `main` 636a9c1eec, after #10299: - New test `guest_broken_pipe`, registered outside Windows. A guest-side `write` to a socketpair whose peer is closed: - with 13 ignored, returns `EPIPE` (32); - with a guest handler, the handler runs once; - while 13 is blocked, it shows in `sigpending` and the handler runs when `_sigprocmask` unblocks it; - as in VLC's drain, while 13 is blocked under a handler, `sigtimedwait` with a zero timeout takes it, and the unblock then runs nothing; - with 13 ignored and blocked, nothing is pending: `sigtimedwait` returns `EAGAIN`, as FreeBSD 11.4's [`tdsendsignal`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_sig.c#L2174-L2189) discards an ignored signal whatever the mask. - On `main` the test is killed by the host signal (`SIGPIPE***Exception`). With this PR it passes. - `guest_signals`, `guest_sigtimedwait`, `guest_signal_list`, `guest_signal_sets`, `guest_socket_pair` and `guest_recvmsg_memory` pass. - All 700 `guest_*` tests, run before the rebase on `main` a5a780eaa: 699 pass. `guest_usbd` didn't run because its library needs the libusb submodule, which isn't checked out here. Overlap: #11040 adds a pipe entry right after the `read, write and vector I/O` debt entry this PR updates, so whichever lands second has a small text conflict there. That entry says a Linux guest can't ignore the host `SIGPIPE`, and its author will update that clause if this PR lands first. ### 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 (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 14:10:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:10:34Z.

Review: APPROVED


Reviewed the Linux-only SIGPIPE mapping and signal lifecycle. The POSIX branch maps guest signal 13 to host SIGPIPE, includes it in dispatch lookup, and leaves Windows unchanged; the test exercises ignored, caught, and blocked-then-unblocked dispositions against a closed socket peer. I verified conventions/diff cleanliness and both changed C++ files pass local C++20 syntax checks (the Signals.cpp compile emits the pre-existing _sigintr_nid_postfix extern-initializer warning). The reported focused and broad guest tests are strong; hosted product jobs are skipped, and the PR documents the unrun guest_usbd test due to the absent libusb submodule.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643609078 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11002#pullrequestreview-5643609078). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T14:10:34Z. **Review:** APPROVED --- Reviewed the Linux-only SIGPIPE mapping and signal lifecycle. The POSIX branch maps guest signal 13 to host SIGPIPE, includes it in dispatch lookup, and leaves Windows unchanged; the test exercises ignored, caught, and blocked-then-unblocked dispositions against a closed socket peer. I verified conventions/diff cleanliness and both changed C++ files pass local C++20 syntax checks (the Signals.cpp compile emits the pre-existing `_sigintr_nid_postfix` extern-initializer warning). The reported focused and broad guest tests are strong; hosted product jobs are skipped, and the PR documents the unrun `guest_usbd` test due to the absent libusb submodule.
ahmadmuj commented 2026-10-25 14:28:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T14:28:48Z.

Review: COMMENTED


Reviewed head 13b894b8bfe0a0e6c9bd9596f3a3ad07e6d8ef20, merged locally onto current main 3a2c51afd2ee6a824cd3a294912c65e6bbf2b768 (clean). WSL2 Ubuntu 24.04, GCC 13.3, Release, focused targets only.

What I ran:

  • guest_broken_pipe, guest_signals, guest_sigtimedwait, guest_signal_list, guest_signal_sets, guest_socket_pair, guest_socket_stream_options, guest_recvmsg_memory pass. check_conventions.py --base origin/main: 0 errors.
  • Red check: Signals.cpp back to main, your test kept. guest_broken_pipe dies with SIGPIPE***Exception, so the test catches it.
  • guest_socket_options and guest_socket_read_write fail here on both trees with the same message, so that's my WSL loopback, not this PR.
  • A local probe (not for the PR) on the merged tree, all pass: pipe() write with 13 ignored gives EPIPE; with a sigaction handler (flags 0), send(..., 0) and a pipe() write each run it once; MSG_NOSIGNAL and SO_NOSIGPIPE don't; with 13 blocked under a handler, sigtimedwait with a zero timeout takes 13 and the unblock runs nothing; with 13 ignored and blocked nothing is pending (EAGAIN); raise(13) and kill(0, 13) with a handler run it. raise(13) under the default action now ends the process (exit 141), which is FreeBSD's default action for SIGPIPE.
  • Checked soo_write (sys_socket.c L147-149 at 8c639945) and 11.4 dofilewrite (sys_generic.c L596-599). The pipe case matches the second one.

The code looks right to me. Two debt lines on the merged tree still describe the old behaviour:

  1. docs/dev/debt/libkernel.md:251 (sigtimedwait) ends with "SIGPIPE has no host equivalent and is never raised by a host write here (see read, write and vector I/O), so VLC's drain finds nothing". The entry it points to now says the opposite, and the probe above shows the drain finding 13 when a handler is set. Something like: "On Linux guest 13 is the host SIGPIPE: with a handler and 13 blocked, a failed write leaves 13 pending for VLC's drain; ignored, nothing is pending, as FreeBSD discards it. Nothing is raised on Windows, so the drain finds nothing there".
  2. docs/dev/debt/libkernel.md:254 (sigaction) says only handlers on "SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTERM" run. SIGPIPE outside Windows belongs in that list now, same as you did for the pause entry.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643667558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11002#pullrequestreview-5643667558). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T14:28:48Z. **Review:** COMMENTED --- Reviewed head `13b894b8bfe0a0e6c9bd9596f3a3ad07e6d8ef20`, merged locally onto current main `3a2c51afd2ee6a824cd3a294912c65e6bbf2b768` (clean). WSL2 Ubuntu 24.04, GCC 13.3, Release, focused targets only. What I ran: - `guest_broken_pipe`, `guest_signals`, `guest_sigtimedwait`, `guest_signal_list`, `guest_signal_sets`, `guest_socket_pair`, `guest_socket_stream_options`, `guest_recvmsg_memory` pass. `check_conventions.py --base origin/main`: 0 errors. - Red check: `Signals.cpp` back to main, your test kept. `guest_broken_pipe` dies with `SIGPIPE***Exception`, so the test catches it. - `guest_socket_options` and `guest_socket_read_write` fail here on both trees with the same message, so that's my WSL loopback, not this PR. - A local probe (not for the PR) on the merged tree, all pass: `pipe()` write with 13 ignored gives `EPIPE`; with a `sigaction` handler (flags 0), `send(..., 0)` and a `pipe()` write each run it once; `MSG_NOSIGNAL` and `SO_NOSIGPIPE` don't; with 13 blocked under a handler, `sigtimedwait` with a zero timeout takes 13 and the unblock runs nothing; with 13 ignored and blocked nothing is pending (`EAGAIN`); `raise(13)` and `kill(0, 13)` with a handler run it. `raise(13)` under the default action now ends the process (exit 141), which is FreeBSD's default action for SIGPIPE. - Checked `soo_write` (sys_socket.c L147-149 at 8c639945) and 11.4 `dofilewrite` (sys_generic.c L596-599). The pipe case matches the second one. The code looks right to me. Two debt lines on the merged tree still describe the old behaviour: 1. `docs/dev/debt/libkernel.md:251` (sigtimedwait) ends with "`SIGPIPE` has no host equivalent and is never raised by a host write here (see `read, write and vector I/O`), so VLC's drain finds nothing". The entry it points to now says the opposite, and the probe above shows the drain finding 13 when a handler is set. Something like: "On Linux guest 13 is the host `SIGPIPE`: with a handler and 13 blocked, a failed write leaves 13 pending for VLC's drain; ignored, nothing is pending, as FreeBSD discards it. Nothing is raised on Windows, so the drain finds nothing there". 2. `docs/dev/debt/libkernel.md:254` (sigaction) says only handlers on "`SIGINT`, `SIGILL`, `SIGABRT`, `SIGFPE`, `SIGSEGV`, `SIGTERM`" run. `SIGPIPE` outside Windows belongs in that list now, same as you did for the pause entry.
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!11002
No description provided.