fix(libkernel): report NODEV and a per-socket inode from fstat on a socketpair end #10621

Merged
Retr0G28 merged 4 commits from upstream-pr/10621 into main 2026-10-26 21:30:32 +00:00
Retr0G28 commented 2026-10-24 13:19:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-24T13:19:27Z.


What

fstat on a socketpair end reported st_dev and st_ino 0, which the debt entry recorded. FreeBSD 11's uipc_sense, the pru_sense of a local socket, sets st_dev to NODEV and st_ino to the socket's unp_ino. A socket gets its unp_ino from one global counter the first time it is sensed, skipping 0, and keeps it. dev_t and ino_t are 32-bit in FreeBSD 11, as in FileStat, so NODEV is 0xFFFFFFFF. Inet sockets use pru_sense_null, which leaves both 0.

GuestSockets::Stat now does the same for a socket of family AF_UNIX, which only socketpair creates. The socket gets a number from a counter under socketsMutex the first time it is stat'ed, and the number is kept in Socket. A dup shares the Socket, so it reports the same number, as it shares the struct socket on FreeBSD. The other fields are unchanged.

main added a sentence to the fstat on a guest socket debt entry saying a socketpair end reports st_dev and st_ino 0. It now names only what still differs: the number comes from a counter this process starts at 1, where FreeBSD's unp_ino is one counter for every local socket on the system, so the numbers differ from the console's. st_dev now matches.

Test: guest_socket_pair checks that both ends of a stream pair report st_dev 0xFFFFFFFF and a nonzero st_ino. The two ends must differ, a second fstat or sceKernelFstat must give the same number, and a dup of an end must report that end's number. An AF_INET socket still reports st_dev and st_ino 0.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, -DBUILD_TESTING=ON, rebased on main 6cd36e6517.

  • Before the rebase, on main a23f8fc9fb: with main's Udp.cpp, guest_socket_pair fails (exit 0xc0000409 from the failed Require). With this PR it passes, and ctest -R "socket|sendfile|kqueue|poll" passes 39 of 39.
  • After the rebase: ctest -R "socket|recvmsg|sendfile|kqueue|^guest_poll$" passes 32 of 32 when run serially.
  • After merging main afc780e681 (head ada29c700c): the same pattern passes 42 of 42 when run serially.
  • python tools/check_conventions.py --base origin/main reports no errors.
  • Not run on Linux or macOS, where the pair is a host AF_UNIX pair and the same code path runs. No title or homebrew run.

Overlap (tools/pr_overlap.py):

  • #8344 (mine) added the peer member next to the new inode member (Udp.cpp L124). It merged first; this branch keeps both members.
  • #8605 changes the same fstat on a guest socket debt entry, for the read bits after the peer closes, and code near GuestSockets::Stat. The two touch different sentences and fields, so the second needs only a rebase of that entry.
  • #7605 and #9365 change the debt lines next to it, the poll entry and stale socket statements. Neither changes the st_dev or st_ino sentence.
  • None of the PRs it could not compare changes GuestSockets::Stat or the socketpair fstat checks.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995730670 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10621). Originally posted by [Retr0G28](https://github.com/Retr0G28) on 2026-10-24T13:19:27Z. --- ### What `fstat` on a socketpair end reported `st_dev` and `st_ino` 0, which the debt entry recorded. FreeBSD 11's [`uipc_sense`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/uipc_usrreq.c#L1099-L1115), the `pru_sense` of a local socket, sets `st_dev` to `NODEV` and `st_ino` to the socket's `unp_ino`. A socket gets its `unp_ino` from one global counter the first time it is sensed, skipping 0, and keeps it. `dev_t` and `ino_t` are 32-bit in FreeBSD 11, as in `FileStat`, so `NODEV` is 0xFFFFFFFF. Inet sockets use `pru_sense_null`, which leaves both 0. `GuestSockets::Stat` now does the same for a socket of family `AF_UNIX`, which only `socketpair` creates. The socket gets a number from a counter under `socketsMutex` the first time it is stat'ed, and the number is kept in `Socket`. A `dup` shares the `Socket`, so it reports the same number, as it shares the `struct socket` on FreeBSD. The other fields are unchanged. `main` added a sentence to the `fstat on a guest socket` debt entry saying a socketpair end reports `st_dev` and `st_ino` 0. It now names only what still differs: the number comes from a counter this process starts at 1, where FreeBSD's `unp_ino` is one counter for every local socket on the system, so the numbers differ from the console's. `st_dev` now matches. Test: `guest_socket_pair` checks that both ends of a stream pair report `st_dev` 0xFFFFFFFF and a nonzero `st_ino`. The two ends must differ, a second `fstat` or `sceKernelFstat` must give the same number, and a `dup` of an end must report that end's number. An `AF_INET` socket still reports `st_dev` and `st_ino` 0. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, `-DBUILD_TESTING=ON`, rebased on `main` 6cd36e6517. - Before the rebase, on `main` a23f8fc9fb: with `main`'s `Udp.cpp`, `guest_socket_pair` fails (exit 0xc0000409 from the failed `Require`). With this PR it passes, and `ctest -R "socket|sendfile|kqueue|poll"` passes 39 of 39. - After the rebase: `ctest -R "socket|recvmsg|sendfile|kqueue|^guest_poll$"` passes 32 of 32 when run serially. - After merging `main` afc780e681 (head ada29c700c): the same pattern passes 42 of 42 when run serially. - `python tools/check_conventions.py --base origin/main` reports no errors. - Not run on Linux or macOS, where the pair is a host `AF_UNIX` pair and the same code path runs. No title or homebrew run. Overlap (`tools/pr_overlap.py`): - #8344 (mine) added the `peer` member next to the new `inode` member (Udp.cpp L124). It merged first; this branch keeps both members. - #8605 changes the same `fstat on a guest socket` debt entry, for the read bits after the peer closes, and code near `GuestSockets::Stat`. The two touch different sentences and fields, so the second needs only a rebase of that entry. - #7605 and #9365 change the debt lines next to it, the `poll` entry and stale socket statements. Neither changes the `st_dev` or `st_ino` sentence. - None of the PRs it could not compare changes `GuestSockets::Stat` or the socketpair `fstat` checks. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 13:20:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:20:54Z.

Review: COMMENTED


The GuestSockets::Stat change and tests look consistent with the described AF_UNIX behavior: inode assignment occurs under socketsMutex, the Socket owns the value so dup shares it, and the AF_INET control preserves zeros. One coordination item remains in the PR body: it says #8344 adds a Socket member adjacent to this new inode field and whichever merges second needs a rebase, but the checklist says Depends on: none. CONTRIBUTING.md asks overlapping PRs to agree on order and declare that dependency. Please record the agreed order (or state that #8344 is the prerequisite) so reviewers and automation can track the shared insertion hunk. I have not independently run the Windows socket tests; hosted product build legs were skipped by eligibility.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638393906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10621#pullrequestreview-5638393906). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:20:54Z. **Review:** COMMENTED --- The `GuestSockets::Stat` change and tests look consistent with the described AF_UNIX behavior: inode assignment occurs under `socketsMutex`, the `Socket` owns the value so `dup` shares it, and the AF_INET control preserves zeros. One coordination item remains in the PR body: it says #8344 adds a `Socket` member adjacent to this new `inode` field and whichever merges second needs a rebase, but the checklist says `Depends on: none`. CONTRIBUTING.md asks overlapping PRs to agree on order and declare that dependency. Please record the agreed order (or state that #8344 is the prerequisite) so reviewers and automation can track the shared insertion hunk. I have not independently run the Windows socket tests; hosted product build legs were skipped by eligibility.
MarcZX10 commented 2026-10-24 13:41:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:41:43Z.

Review: APPROVED


The author has resolved the coordination item: #8344 is explicitly first, and this PR now declares Depends on: #8344 and says it will rebase and rerun guest_socket_pair after #8344 merges. I approve the reviewed implementation and tests at head c27cdcaf4cc1218a0679720ad6f3200645599255. The previously reviewed behavior remains consistent: inode assignment is protected by socketsMutex, lifetime is owned by the shared Socket (so dup retains identity), and AF_INET stats remain zero. Hosted eligibility/conventions/intake/labels pass; product checks were skipped. Windows socket test results are author-reported, not independently reproduced. The PR remains dependent on #8344 and should be revalidated after that rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638448511 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10621#pullrequestreview-5638448511). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:41:43Z. **Review:** APPROVED --- The author has resolved the coordination item: #8344 is explicitly first, and this PR now declares `Depends on: #8344` and says it will rebase and rerun `guest_socket_pair` after #8344 merges. I approve the reviewed implementation and tests at head `c27cdcaf4cc1218a0679720ad6f3200645599255`. The previously reviewed behavior remains consistent: inode assignment is protected by `socketsMutex`, lifetime is owned by the shared `Socket` (so dup retains identity), and AF_INET stats remain zero. Hosted eligibility/conventions/intake/labels pass; product checks were skipped. Windows socket test results are author-reported, not independently reproduced. The PR remains dependent on #8344 and should be revalidated after that rebase.
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!10621
No description provided.