Skip to content

fix(libkernel): report socket status from fstat on a guest socket - #4903

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
ErenYeager1836:carry/fstat-guest-socket
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
ErenYeager1836:carry/fstat-guest-socket

Conversation

@ErenYeager1836

@ErenYeager1836 ErenYeager1836 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Carries milescoviello:fix/fstat-guest-socket@505bc9b9 unchanged (rebased onto current main and debt conflict resolved). Fixes #4051.

What

fstat on a guest socket descriptor passed the guest number (from 0x10000000 up) to the host, which has no such descriptor, so it threw FillFileStat: fstat failed for fd 268435460; sceKernelFstat returned EBADF for the same descriptor. FreeBSD fills the stat buffer for a socket through soo_stat (sys/kern/sys_socket.c), which reports S_IFSOCK, read/write mode bits from send/recv state, and st_size = sbavail - sb_ctl. fstat/sceKernelFstat now answer that way for guest sockets instead of throwing.

Tested

  • From the original issue & carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags: guest_socket_pair aborts with main's sources (the FillFileStat throw) and passes with the change; all guest_* tests pass (289/289).
  • Windows 11: python tools/check_conventions.py --base upstream/main passes with 0 errors. python tools/check_test_registration.py passes (707 test executables).

Checklist

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test: head 618bcf323 merged onto current main ea2bbefb2 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_socket_pair: guest_socket_pair passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@nicolasfalesy

Copy link
Copy Markdown
Contributor

Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fc together with #4927, #4903, #4877, #4822 and #4823 (no conflicts): guest_socket_pair passes. With this PR's source change reverted (test kept), guest_socket_pair fails on Linux, so the check guards the change on Linux too.

fstat on a guest socket descriptor passed the guest number to the host,
which has no such descriptor, and threw ("FillFileStat: fstat failed for
fd 268435460"); sceKernelFstat returned EBADF. FreeBSD fills the stat
buffer for a socket through soo_stat (sys/kern/sys_socket.c):

	bzero((caddr_t)ub, sizeof (*ub));
	ub->st_mode = S_IFSOCK;
	...
	if ((sb->sb_state & SBS_CANTRCVMORE) == 0 || sbavail(sb))
		ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
	ub->st_size = sbavail(sb) - sb->sb_ctl;
	...
	if ((sb->sb_state & SBS_CANTSENDMORE) == 0)
		ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;

and pru_sense_null (sys/kern/uipc_socket.c) adds
st_blksize = so->so_snd.sb_hiwat.

fstat and sceKernelFstat now answer 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_size from
the bytes queued and st_blksize from the send buffer size, other fields
zero. shutdown records which side it closed. A closed socket descriptor
returns EBADF. The differences from the console (peer shutdown, the
host's FIONREAD and SO_SNDBUF, socketpair identity) are listed in
TechnicalDebt.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ErenYeager1836
ErenYeager1836 force-pushed the carry/fstat-guest-socket branch from 2cbec36 to 472437a Compare October 14, 2026 03:05
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 14, 2026
@oneandonlydean
oneandonlydean merged commit 718ae13 into boykopovar:main Oct 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: fstat on a socket descriptor throws (FillFileStat) and sceKernelFstat returns EBADF; fix branch ready

5 participants