libkernel: writing to a pipe whose reader is closed returns EINVAL on Windows instead of EPIPE; fix branch ready #5246
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-13T15:34:05Z.
On Windows,
write,writev,sceKernelWriteandsceKernelWritevto a pipe whose read end has been closed fail withEINVALinstead ofEPIPE. The host C runtime mapsERROR_NO_DATA(232) toEINVAL, and FreeBSD 11.4pipe_writereturnsEPIPE. A guest that treatsEPIPEas "the reader went away" (the usual way a writer ends cleanly) sees a generic invalid-argument error instead.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libkernel-pipe-write-epipe (one commit on a recent main:
File/src/Open.cppNativeWrite, theTransferIovecserror path inFile/src/Stdio.cpp, and the new testtests/GuestPipeClosedWrite.cpp, registered asguest_pipe_closed_write).ERROR_NO_DATAis now remapped toEPIPEin both places.NativeTransferis left alone because #4885 changes it.Checks:
guest_file_vector,guest_kernel_fcntlandguest_duppass.writevwith 1 to 4 iovecs (including zero-length ones), now giveEPIPE(32) for blocking and nonblocking pipes, andsceKernelWrite/sceKernelWritevreturn 0x80020020. A 1 MiB write blocked on a 4096-byte pipe wakes withEPIPEwhen the reader closes (with two blocked writers main returnedEPIPEfor one andEINVALfor the other; now both getEPIPE), with no hangs. Unchanged against main: a full pipe (EAGAINor blocking), a write to the read end and to a closed or invalid fd (EBADF), and writes to a regular file, a read-only file and a socket. A direct probe through bothucrtbase.dllandmsvcrt.dllshows the sameEINVALwith_doserrno232, which matters because local toolchains and CI use different C runtimes.check_conventions.pyis clean andpr_overlap.pyfinds no overlap; #4885 editsNativeTransfernearby, so a small rebase of theStdio.cpphunk may be needed.Not covered: no
SIGPIPEis raised on Windows (already recorded indocs/dev/debt/libkernel.md); a write that is part done when the reader closes returnsEPIPEinstead of the partial count through the single-buffer path (the iovec path does return the count); the check reads_doserrnowithout clearing it first. A zero-lengthwriteand a zero-lengthwritevon a broken pipe return 0 where FreeBSD returnsEPIPE, and a nonblockingwritevon a full pipe givesENOSPCrather thanEAGAIN; both are the same on main. Only Windows was built and run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T16:00:40Z.
Implemented in #5265. I built
guest_pipe_closed_write_testson Linux and ranguest_pipe_closed_write; the test passed (1/1). The Windows-specific EPIPE mapping was not executable in my Linux environment. The implementation also guards the Windows-only error check so it does not affect Linux compilation.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:25Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. #5265 is closed for the same reason. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.