fix(libkernel): return ESPIPE for positioned socket I/O #3151
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3151"
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 MarcZX10 on 2026-10-10T23:22:14Z.
What
Handle positioned I/O on guest socket descriptors before passing them to host file APIs. The POSIX
pread,pwrite,preadvandpwritevexports now return-1witherrno = ESPIPEfor an open guest socket andEBADFfor a closed descriptor. TheirsceKernelforms return the corresponding SCE kernel error values.Regression coverage checks both error forms for scalar and vectored positioned calls.
Tested
Linux, GCC 12.2, Release build:
cmake --build /tmp/AnyPS5-build-socket-positioned --target guest_socket_read_write_tests -j2ctest --test-dir /tmp/AnyPS5-build-socket-positioned -R "^guest_socket_read_write$" --output-on-failure(1/1 passed)python3 tools/check_conventions.py --base upstream/main(passed)Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T23:57:50Z.
Windows check (Windows 11, WinLibs GCC 15.2.0 r7, Release), this head (302eae2b) merged onto
main181420f8:mainwith only the test changes:guest_socket_read_writefails.--repeat until-fail:3).It conflicts with #3150, which touches the same lines, so one of the two will need a rebase after the other merges.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T00:29:32Z.
Review: COMMENTED
Both of these are the same kind of fix — a libkernel socket call that a valid guest argument can drive into undefined or wrong behaviour — and both are settled by the same authority: POSIX behaviour, for
selectin the first case and for positioned I/O on a descriptor that is not seekable in the second.In #3152 the saturation is done the right way round. The check is a division before the multiply (
seconds > remaining / MicrosecondsPerSecond), so the comparison itself cannot overflow, and the second guard subtracts an already-boundedrequestedfromremaining, which is what keeps the residual check safe as well. Saturating attime_point::max()rather than clamping to some large constant is what makes an oversizedtimevalbehave as an effectively infinite wait rather than a long one — and covering normal durations,int64_tmaximum and the clock boundary is the set that would catch a regression in either direction.In #3151 the two error forms are exactly the POSIX ones.
ESPIPEfor an open guest socket andEBADFfor a closed descriptor, with the POSIX exports settingerrnoand returning −1 while thesceKernelforms return the translated kernel error, is the split a caller compiled against either interface expects. Answering from the guest descriptor before the host sees it is the part that matters, and the old behaviour shows why: the host call was made with the guest's own number, which is not a host descriptor at all, so it came backEBADFfrom a table that does not hold that object.ESPIPEfor an open guest socket is the answer the guest is owed, and it can only come from the guest's own descriptor table.The descriptor split is fixed for the process lifetime, which is what makes the guard sound.
GuestSockets::FirstDescriptoris aconstexpr, the table starts its counter at that value and only ever increments, and a host descriptor below the boundary is never entered into it — so a number cannot cross between the ranges, and the number alone decides which table owns the descriptor. That is worth one line in the entry, because otherwise a reader has to reconstruct it from the allocation code.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:25:19Z.
I clarified the descriptor split in
TechnicalDebt.md: guest socket handles start at0x10000000and are allocated upward, which is why the descriptor range selects the guest socket table or host descriptor table. I rebased the PR onto currentmainand reran the Release build plusguest_socket_read_write(1/1 passed); conventions andgit diff --checkpass. The separatepreadv/pwritevbehavior remains scoped in this PR as tested.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:45:08Z.
Thanks for the Windows baseline and current-head results, and for flagging the overlap with #3150. These PRs cover separate socket behaviors but edit adjacent paths in the same file. Neither depends on the other; when one merges, I’ll rebase the remaining PR onto
main, resolve the overlap, and rerun its focused checks.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:40:21Z.
Rebased onto current
main(conflicts with #3150 inGuestSocketReadWrite.cppand theTechnicalDebt.mdread/write line; kept both tests and merged the line with theESPIPE/EBADFwording and the descriptor-range note). Build andguest_socket_read_writepass on the rebased tree; merging.Minor, not blocking: with a negative offset on a socket these return
EINVAL, where FreeBSD checks seekability first and returnsESPIPE.