libkernel: fstat on a socket descriptor throws (FillFileStat) and sceKernelFstat returns EBADF; fix branch ready #4051
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 milescoviello on 2026-10-11T22:11:27Z.
fstaton a guest socket descriptor passed the guest number (from0x10000000up) to the host, which has no such descriptor, so it threwFillFileStat: fstat failed for fd 268435460.sceKernelFstatreturnedEBADFfor the same descriptor. FreeBSD fills the stat buffer for a socket throughsoo_stat(sys/kern/sys_socket.c):pru_sense_null(sys/kern/uipc_socket.c) then setsst_blksize = so->so_snd.sb_hiwat.fstatandsceKernelFstatanswer a guest socket from the socket table:S_IFSOCK, the read bits until the receive side is shut down and drained, the write bits until the send side is shut down,st_sizefrom the queued bytes (FIONREAD),st_blksizefromSO_SNDBUF. Every other field is zero, as after FreeBSD'sbzero.shutdownrecords which side it closed.EBADFinstead of the throw.FIONREADper datagram and doublesSO_SNDBUF, andsocketpairends reportst_dev/st_ino0.Fix branch:
milescoviello:fix/fstat-guest-socket, one commit (a84aa9ad) onmainacc5d294.Tested: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags:
guest_socket_pairaborts withmain's sources (theFillFileStatthrow) and passes with the change; allguest_*tests pass (289/289).I'll open the pull request myself as soon as my open one (#3623) is merged, since the open-PR limit allows one until then.
AI-assisted: yes