fix(libkernel): fail a write to a pipe with no reader with EPIPE on Windows #5326

Closed
Kikoarl wants to merge 1 commit from upstream-pr/5326 into main
Kikoarl commented 2026-10-13 17:18:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T17:18:04Z.


What

On Windows, the UCRT maps ERROR_NO_DATA (232), which WriteFile reports for a pipe whose read end has been closed, to EINVAL. FreeBSD 11.4 pipe_write returns EPIPE.

Remap ERROR_NO_DATA with EINVAL to EPIPE in NativeWrite (File/src/Open.cpp) and TransferIovecs (File/src/Stdio.cpp), so write, writev, sceKernelWrite and sceKernelWritev return EPIPE (0x80020020) when writing to a broken pipe.

Closes #5246

Tested

  • Linux (x86_64), GCC 16, Release, RAM-disk build (/tmp/anyps5_build).
  • Passes ctest -R guest_pipe_closed_write: verifies broken pipe writes on blocking and non-blocking pipes for scalar and vector writes.
  • Passes ctest -R "guest_file_vector|guest_kernel_fcntl|guest_dup".
  • Passes python3 tools/check_conventions.py.

Checklist

  • Description explains the problem and the change
  • PR follows CONTRIBUTING.md
  • Changes are covered by tests
  • Code passes python3 tools/check_conventions.py
  • Tech debt documented in docs/dev/TechnicalDebt.md (if applicable)
  • AI-assisted: yes
  • Depends on: none
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846867923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5326). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T17:18:04Z. --- ### What On Windows, the UCRT maps `ERROR_NO_DATA` (232), which `WriteFile` reports for a pipe whose read end has been closed, to `EINVAL`. FreeBSD 11.4 `pipe_write` returns `EPIPE`. Remap `ERROR_NO_DATA` with `EINVAL` to `EPIPE` in `NativeWrite` (`File/src/Open.cpp`) and `TransferIovecs` (`File/src/Stdio.cpp`), so `write`, `writev`, `sceKernelWrite` and `sceKernelWritev` return `EPIPE` (`0x80020020`) when writing to a broken pipe. Closes #5246 ### Tested - Linux (x86_64), GCC 16, Release, RAM-disk build (`/tmp/anyps5_build`). - Passes `ctest -R guest_pipe_closed_write`: verifies broken pipe writes on blocking and non-blocking pipes for scalar and vector writes. - Passes `ctest -R "guest_file_vector|guest_kernel_fcntl|guest_dup"`. - Passes `python3 tools/check_conventions.py`. ### Checklist - [x] Description explains the problem and the change - [x] PR follows [CONTRIBUTING.md](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONTRIBUTING.md) - [x] Changes are covered by tests - [x] Code passes `python3 tools/check_conventions.py` - [x] Tech debt documented in `docs/dev/TechnicalDebt.md` (if applicable) - [x] AI-assisted: yes - [x] Depends on: none
github-actions[bot] commented 2026-10-13 17:24:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T17:24:05Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5008 core/libs/prx/libkernel/CMakeLists.txt L1212
#5265 core/libs/prx/libkernel/File/src/Stdio.cpp L1011 core/libs/tests/GuestPipeClosedWrite.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151236821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5326#issuecomment-6151236821). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T17:24:05Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5008 | `core/libs/prx/libkernel/CMakeLists.txt` [L1212](https://github.com/boykopovar/AnyPS5/blob/8cf6a0bc3a17782e8f1063d1127f72419260230b/core/libs/prx/libkernel/CMakeLists.txt#L1212) | | | | #5265 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L1011](https://github.com/boykopovar/AnyPS5/blob/8cf6a0bc3a17782e8f1063d1127f72419260230b/core/libs/prx/libkernel/File/src/Stdio.cpp#L1011) | | `core/libs/tests/GuestPipeClosedWrite.cpp` |
Kikoarl commented 2026-10-13 17:38:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T17:38:36Z.


Closing in favor of earlier carry in #5265.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151494691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5326#issuecomment-6151494691). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T17:38:36Z. --- Closing in favor of earlier carry in #5265.

Pull request closed

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!5326
No description provided.