feat(libkernel): pass descriptors in SCM_RIGHTS messages on Unix sockets #7090

Merged
milescoviello merged 16 commits from upstream-pr/7090 into main 2026-11-01 13:06:02 +00:00
milescoviello commented 2026-10-17 11:01:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T11:01:40Z.


What

sendmsg threw control data is not supported for any control buffer. Wine passes descriptors to and from its wineserver this way, so Forever Launcher's in-process Wine (PPSA99030) stops on it. On a guest Unix-domain socket, SCM_RIGHTS control messages now pass descriptors, as FreeBSD 11's unp_internalize and unp_externalize do.

  • sendmsg: reads FreeBSD's layout: a 12-byte cmsghdr with the descriptors at offset 16, and records CMSG_SPACE bytes apart. It sends the descriptors with the host's SCM_RIGHTS, because a guest descriptor here is a host descriptor (a guest socket's number is a duplicate of its host socket).
    • It returns EBADF for a descriptor that is not open, and EINVAL for a level other than SOL_SOCKET or a record longer than the buffer.
  • recvmsg with a control buffer: receives with the host's SCM_RIGHTS. A received socket is installed as a guest socket (family from getsockname(), type from SO_TYPE); any other descriptor is used as it is.
    • It writes FreeBSD's record, CMSG_LEN in cmsg_len and CMSG_SPACE bytes, when the whole record fits the caller's buffer. Otherwise it copies nothing, sets controlLength 0 and MSG_CTRUNC, and closes the passed descriptors. That is what 11.4's kern_recvit does: it copies only control mbufs that fit whole and disposes the rest with m_dispose_extcontrolm. A fault writing the record, the data or the address also closes them and returns EFAULT, as kern_recvit's out: path disposes of the control descriptors whenever it returns an error.
    • MSG_CMSG_CLOEXEC marks the received descriptors close-on-exec. Where the host has no MSG_CMSG_CLOEXEC (macOS), each received descriptor gets fcntl(F_SETFD, FD_CLOEXEC) before it is installed.
  • Ownership: received descriptors belong to the receive until the whole result, final msghdr write included, is written back. Any earlier return closes each of them exactly once, including a failure part-way through installing them.
  • MSG_PEEK with control space reads only the data, as on main, and leaves any passed descriptors queued.
  • Refused descriptors (b9e987b82e, from XairRrR's review): a guest kqueue returns EOPNOTSUPP, as in FreeBSD's unp_internalize. A random device, a directory or a JIT shared memory descriptor, whose state is libkernel's, throws, as do archived files. So does a zero-byte stream send that carries descriptors, since Linux sends no record without data.
  • Still throws: Windows (its socket pairs are loopback TCP), control messages other than SCM_RIGHTS, and control data on IP sockets. The debt entry says so.

Overlap: #10767 and #11223 (Ragbie) change the same receive condition in recvmsg (#10767 adds the receive-shut check, this PR adds the SCM_RIGHTS setup above it) and add neighbouring entries to docs/dev/debt/libkernel.md. Agreed order: whichever lands second resolves the one-line conflict and keeps both changes.

Tested

  • This head (1e19b327f7, XairRrR's second review): main 52c09d567d merged in, with the kqueue check renamed to IsKqueueDescriptor_nid_no_patch (#11296). A JIT shared memory descriptor (IsJitSharedMemory) now throws too. The 19 tests matching ^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp|^guest_jit pass 3 of 3.

  • This head (b9e987b82e, XairRrR's review): the 18 tests matching ^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp pass 3 of 3. The new kqueue case in guest_socket_rights requires -1/errno 45 and that the next plain send arrives with no control data. With the kqueue check taken out (6966f73e71), the test aborts on it. Windows 11 VM (GT 1030, WinLibs GCC 15.2): of the 31 tests matching the same regex, 28 pass 3 of 3 on the merge base f759e165d9 and on this head. guest_socket_options, guest_socket_options_multicast and guest_socket_stream_options fail the same way on both (0xc0000409).

  • Review rework (1db8d77c9a, main ef90ce0452 merged in), after oneandonlydean's review: ReceivedRights owns the received descriptors until the final header write. The old rollback could close a descriptor twice: after a failed Install the Socket had already closed it, and the loop closed it again. Plain MSG_PEEK works again. The test includes prx/libkernel/include/Api.hpp and prx/libc/include/Api.hpp (the public_headers audit passes) and counts host descriptors with fcntl(F_GETFD) instead of /proc. New cases:

    • a read-only msghdr whose final header write faults after the data and control copies succeeded: EFAULT with the host descriptor count unchanged;
    • a Unix socket and an AF_ROUTE socket passed together in both orders, where installing the route socket fails: the host descriptor count is unchanged;
    • a plain-data MSG_PEEK with control space, which returns the data, and then a read of the same bytes.

    On Linux (Ubuntu 26.04.1, GCC 15.2, Release), guest_socket_rights, guest_socket_pair, guest_recvmsg_memory, guest_udp and guest_tcp pass 3 of 3. With the previous Udp.cpp under the new test, guest_socket_rights aborts. On the Windows 11 VM (WinLibs GCC 15.2, Release), the four of them that build on Windows pass 3 of 3 at this head and at main f759e165d9.

  • Merged main 1e740a23a3 into the branch (04eeeb9d11), then added 484bc8c2c3. main had changed recvmsg in #10308: the host receive runs only for data, a stream socket or a readable one, and msg_flags starts from the call's flags as measured on a PS5. The descriptor-passing receive now sits inside that condition, and the two-socket case of guest_socket_rights now expects MSG_CMSG_CLOEXEC back in msg_flags (it expected 0, and failed 3 of 3 against #10308). On Linux (Ubuntu 26.04.1, GCC 15.2), the 14 guest_socket* tests pass 3 of 3 on 484bc8c2c3, and the 649 tests matching ^guest_|libc passed 3 of 3 on 04eeeb9d11 apart from that case.

  • Title run on 484bc8c2c3 (by @babyhuey, Linux CI image with lavapipe, Ubuntu 24.04, GCC 13, Release): the 14 guest_socket* tests pass, and Forever Launcher (PPSA99030) is still running at the 60 s timeout in 2 of 2 runs, with no sendmsg: control data is not supported, what() or FATAL (main f3456a4152 stops at that sendmsg line).
    Ubuntu 24.04, GCC 13.3, Release. The results below are from main 673f7406c5, except the rebase line.

  • On current main (run by @babyhuey, Linux CI image with lavapipe, Ubuntu 24.04, GCC 13, Release): with the other PRs below merged, main f3456a4152 still stops Forever Launcher with sendmsg: control data is not supported. With this head (1142d3a6bc, clean merge) the 14 guest_socket* tests pass and the launcher runs the full 60 s in 2 of 2 runs, ending on the same first-start Wine prefix result described here.

  • Data and address faults (516263f8f6), also found by @wachi35676: a fault writing the data buffer or the address after the descriptors were installed left them open. They are now closed on those returns too. New guest_socket_rights case: two pipe ends are passed and received into a read-only data buffer, and the receive must return EFAULT with the count in /proc/self/fd unchanged. It aborts with the previous Udp.cpp and passes with the fix, and the 12 guest_socket_* tests pass 3 of 3. The debt entry also says now that several SCM_RIGHTS messages in one sendmsg arrive as one record. @wachi35676 re-checked 516263f8f6 merged onto main a020d0256: the 14 guest_socket_* tests pass 3 of 3, reverting only the Udp.cpp hunks makes the faulted-receive case abort, and their probe now leaves no descriptor open after a fault on the data buffer. The Windows build of Udp.cpp and libkernel succeeds on the same merge.

  • Truncation fixed (223a7c147f), after @wachi35676 found that a short control buffer leaked the passed descriptors. With the old record copy and the new test, guest_socket_rights aborts. With the fix, the 12 guest_socket_* tests pass 3 of 3, and ctest -R '^guest_|libc' passes 475 of 476. guest_module_directories (a relinker test) fails the same way on main in that tree.

  • Rebase onto main bf2c63f853 (5f492d3e94). recvmsg on main now reads the guest's msghdr and iovecs into a copy and writes its results back with ReadGuest/WriteGuest. The control record is written the same way: into the copied control pointer, with controlLength and MSG_CTRUNC in the copied header that is written back. guest_socket_* (12 tests, guest_socket_rights included) pass 3 of 3. ctest -R '^guest_|libc': 474 of 476 pass. guest_bad_optional_access was not built in that tree, and guest_module_directories (a relinker test) fails the same way with main's sources.

  • New guest_socket_rights test (Linux), over a stream socket pair:

    • It passes a pipe's write end, writes through the received descriptor and reads it from the pipe. The received descriptor is not close-on-exec.
    • It passes the ends of a stream and a datagram socket pair in one record with MSG_CMSG_CLOEXEC, and checks that both received sockets are close-on-exec and send and receive.
    • It passes another pipe end with MSG_CMSG_CLOEXEC and checks that the received host descriptor is close-on-exec. A pipe end goes through unchanged, so this reads the host flag, while the sockets' check reads the guest's close-on-exec set.
    • A control buffer of 16 bytes, too small for the 24-byte record, gets controlLength 0 and MSG_CTRUNC. So does a record of two descriptors with room for one (20 bytes), and in both cases the count in /proc/self/fd is unchanged, so no descriptor leaks. A receive without a control buffer gets the data only.
    • A closed descriptor gives EBADF, and another level or an overlong record gives EINVAL.
    • With main's Udp.cpp it aborts on sendmsg: control data is not supported. It passes 3 of 3, with guest_socket_pair too.
  • ctest -R '^guest_|libc': 402 of 402 pass.

  • Forever Launcher (PPSA99030, 01.000.012), in gdb: Wine's first such call is sendmsg on a socket-pair end with MSG_NOSIGNAL | MSG_DONTWAIT, one byte of data and a 24-byte control buffer holding one SOL_SOCKET/SCM_RIGHTS record (cmsg_len 20) that passes the end of another socket pair.

    • On main with the PRs for its earlier stops merged locally (#6915, #6028, #6939, #6787, #7070, #6469), it stops at 0 s on sendmsg: control data is not supported, 2 of 2.
    • With this PR it gets past it 2 of 2: the descriptor reaches the wineserver thread, and the title stops 1 s in at its next unimplemented call, kevent: NOTE_LOWAT (wineserver's kqueue registers EVFILT_READ and EVFILT_WRITE with NOTE_LOWAT 1). That is a separate PR.
    • Since #7092 (NOTE_LOWAT) merged, that next stop is gone. On main 98c251fc62 with #6915, #6939, #6787, #7070, #6469 and this PR (17d9e0a516), Forever Launcher runs the whole 60 s in 2 of 2 runs with no unimplemented call. Its first-start prefix setup then reports title wineboot skipped; prefix must be initialized by payload Wine and failed to open "C:\\windows\\system32\\wineboot.exe", and Wine exits with 0xC0000135, the launcher's "Setting up the Windows files did not finish". I read that as the launcher's own setup, not a missing emulator call, but I haven't looked further.
  • @p3n1cillin checked current main with two catalog titles that run Wine with an in-process wineserver: Forever Launcher (PPSA99030, 01.000.021) and RuneScape Launcher (PPSA99225, 01.000.021). Setup: Ubuntu on WSL2, GCC 15.2.0, Release, llvmpipe on Xvfb, 120 s without input.

    • On main 7fea87746 both abort on sendmsg: control data is not supported.
    • With this PR merged onto main 319621ba2e (4fa9ea8a0f, clean), neither stops there. Both start their wineserver, and Wine runs and shuts down in order.
    • Both then stop on their own first-start prefix setup ("Setting up the Windows files did not finish"), as above.
    • The five scm|rights|unix|sendmsg|recvmsg ctests pass on the merge.
  • Windows build: @wachi35676 found that Udp.cpp did not compile there: GuestControlCloseOnExec was declared inside the non-Windows block. 17d9e0a516 moves the declaration out of it. A MinGW-w64 -fsyntax-only compile of Udp.cpp stops on that line before and passes after, and the 11 socket tests and 411 ^guest_ tests pass again on Linux. @screamm then built head 17d9e0a516 on Windows (Windows 11, WinLibs GCC 15.2.0, full build and libs). Moving the declaration back reproduces the compile error, and the 35 Windows socket, poll, select, rudp, equeue and kqueue tests pass 3 of 3. On Windows, sendmsg with an SCM_RIGHTS buffer still stops with control data is not supported on Windows, as this PR intends. None of their local titles sends or receives such a message.

  • Windows VM (Windows 11, WinLibs GCC 15.2.0, Release), head 1142d3a6bc and its merge base eaff87674c: the 13 guest_socket_* tests that build on Windows (address length, connect to a listener, descriptor flags, descriptors, errors, events, non-socket descriptors, options, pairs, port 0, read/write, stream options, timeouts) pass 3 of 3 on both. SCM_RIGHTS still throws on Windows, as described above, so this checks that the change leaves the rest of the Windows socket layer as it was.

  • macOS: @jotitadev found that SO_DOMAIN and MSG_CMSG_CLOEXEC don't exist in XNU's headers, so Udp.cpp didn't compile on top of #7332. aff8c2af51 takes the received socket's family from getsockname(). Where MSG_CMSG_CLOEXEC doesn't exist, it marks each received descriptor with fcntl(F_SETFD, FD_CLOEXEC) when the guest asked for it. Their local equivalent compiled with -Wall -Wextra on arm64 and x86_64, and guest_socket_rights passed 5 of 5 under Rosetta. They also found that the test didn't check the host flag, so a3b3801aa6 adds the pipe-end case above. On Linux the head passes 3 of 3, and so does a build with the receive flag forced to 0, through the fcntl path. With the flag forced to 0 and the fcntl loop removed, the test fails. ^guest_|libc passed 411 of 411 on aff8c2af51. @jotitadev then checked head a3b3801aa6 on #7332 (57bccfbfc, M2 Max, macOS 27.2, Apple clang 21.0.0): Udp.cpp compiles with -Wall -Wextra on arm64 and x86_64 with no warnings of its own, through the fcntl fallback. Under Rosetta guest_socket_rights passes 5 of 5, and with the fcntl loop removed it fails 3 of 3 on the new pipe check. The 20 socket, UDP, RUDP, poll and select tests pass, except an intermittent ECONNRESET in guest_socket_read_write that also happens on #7332 alone.

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: PPSA99225 #12713 (RuneScape Launcher) past the same sendmsg abort (p3n1cillin's run); PPSA99030 #12712 (Forever Launcher): #6915, #6028, #6939, #6787, #7070 and #6469 have landed, and this is its last stop on main (babyhuey's run)
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4899517628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T11:01:40Z. --- ### What `sendmsg` threw `control data is not supported` for any control buffer. Wine passes descriptors to and from its wineserver this way, so Forever Launcher's in-process Wine (PPSA99030) stops on it. On a guest Unix-domain socket, `SCM_RIGHTS` control messages now pass descriptors, as FreeBSD 11's `unp_internalize` and `unp_externalize` do. - **`sendmsg`:** reads FreeBSD's layout: a 12-byte `cmsghdr` with the descriptors at offset 16, and records `CMSG_SPACE` bytes apart. It sends the descriptors with the host's `SCM_RIGHTS`, because a guest descriptor here is a host descriptor (a guest socket's number is a duplicate of its host socket). - It returns `EBADF` for a descriptor that is not open, and `EINVAL` for a level other than `SOL_SOCKET` or a record longer than the buffer. - **`recvmsg` with a control buffer:** receives with the host's `SCM_RIGHTS`. A received socket is installed as a guest socket (family from `getsockname()`, type from `SO_TYPE`); any other descriptor is used as it is. - It writes FreeBSD's record, `CMSG_LEN` in `cmsg_len` and `CMSG_SPACE` bytes, when the whole record fits the caller's buffer. Otherwise it copies nothing, sets `controlLength` 0 and `MSG_CTRUNC`, and closes the passed descriptors. That is what 11.4's [`kern_recvit`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_syscalls.c#L1143-L1155) does: it copies only control mbufs that fit whole and disposes the rest with `m_dispose_extcontrolm`. A fault writing the record, the data or the address also closes them and returns `EFAULT`, as `kern_recvit`'s `out:` path disposes of the control descriptors whenever it returns an error. - `MSG_CMSG_CLOEXEC` marks the received descriptors close-on-exec. Where the host has no `MSG_CMSG_CLOEXEC` (macOS), each received descriptor gets `fcntl(F_SETFD, FD_CLOEXEC)` before it is installed. - **Ownership:** received descriptors belong to the receive until the whole result, final `msghdr` write included, is written back. Any earlier return closes each of them exactly once, including a failure part-way through installing them. - **`MSG_PEEK` with control space** reads only the data, as on `main`, and leaves any passed descriptors queued. - **Refused descriptors (`b9e987b82e`, from XairRrR's review):** a guest kqueue returns `EOPNOTSUPP`, as in FreeBSD's `unp_internalize`. A random device, a directory or a JIT shared memory descriptor, whose state is libkernel's, throws, as do archived files. So does a zero-byte stream send that carries descriptors, since Linux sends no record without data. - **Still throws:** Windows (its socket pairs are loopback TCP), control messages other than `SCM_RIGHTS`, and control data on IP sockets. The debt entry says so. **Overlap:** #10767 and #11223 (Ragbie) change the same receive condition in `recvmsg` (#10767 adds the receive-shut check, this PR adds the `SCM_RIGHTS` setup above it) and add neighbouring entries to `docs/dev/debt/libkernel.md`. Agreed order: whichever lands second resolves the one-line conflict and keeps both changes. ### Tested - **This head (`1e19b327f7`, XairRrR's second review):** `main` `52c09d567d` merged in, with the kqueue check renamed to `IsKqueueDescriptor_nid_no_patch` (#11296). A JIT shared memory descriptor (`IsJitSharedMemory`) now throws too. The 19 tests matching `^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp|^guest_jit` pass 3 of 3. - **This head (`b9e987b82e`, XairRrR's review):** the 18 tests matching `^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp` pass 3 of 3. The new kqueue case in `guest_socket_rights` requires `-1`/`errno` 45 and that the next plain send arrives with no control data. With the kqueue check taken out (`6966f73e71`), the test aborts on it. Windows 11 VM (GT 1030, WinLibs GCC 15.2): of the 31 tests matching the same regex, 28 pass 3 of 3 on the merge base `f759e165d9` and on this head. `guest_socket_options`, `guest_socket_options_multicast` and `guest_socket_stream_options` fail the same way on both (`0xc0000409`). - **Review rework (`1db8d77c9a`, `main` `ef90ce0452` merged in), after oneandonlydean's review:** `ReceivedRights` owns the received descriptors until the final header write. The old rollback could close a descriptor twice: after a failed `Install` the `Socket` had already closed it, and the loop closed it again. Plain `MSG_PEEK` works again. The test includes `prx/libkernel/include/Api.hpp` and `prx/libc/include/Api.hpp` (the `public_headers` audit passes) and counts host descriptors with `fcntl(F_GETFD)` instead of `/proc`. New cases: - a read-only `msghdr` whose final header write faults after the data and control copies succeeded: `EFAULT` with the host descriptor count unchanged; - a Unix socket and an `AF_ROUTE` socket passed together in both orders, where installing the route socket fails: the host descriptor count is unchanged; - a plain-data `MSG_PEEK` with control space, which returns the data, and then a read of the same bytes. On Linux (Ubuntu 26.04.1, GCC 15.2, Release), `guest_socket_rights`, `guest_socket_pair`, `guest_recvmsg_memory`, `guest_udp` and `guest_tcp` pass 3 of 3. With the previous `Udp.cpp` under the new test, `guest_socket_rights` aborts. On the Windows 11 VM (WinLibs GCC 15.2, Release), the four of them that build on Windows pass 3 of 3 at this head and at `main` `f759e165d9`. - **Merged `main`** 1e740a23a3 into the branch (`04eeeb9d11`), then added `484bc8c2c3`. `main` had changed `recvmsg` in #10308: the host receive runs only for data, a stream socket or a readable one, and `msg_flags` starts from the call's flags as measured on a PS5. The descriptor-passing receive now sits inside that condition, and the two-socket case of `guest_socket_rights` now expects `MSG_CMSG_CLOEXEC` back in `msg_flags` (it expected 0, and failed 3 of 3 against #10308). On Linux (Ubuntu 26.04.1, GCC 15.2), the 14 `guest_socket*` tests pass 3 of 3 on `484bc8c2c3`, and the 649 tests matching `^guest_|libc` passed 3 of 3 on `04eeeb9d11` apart from that case. - **Title run on `484bc8c2c3`** ([by @babyhuey](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6386867670), Linux CI image with lavapipe, Ubuntu 24.04, GCC 13, Release): the 14 `guest_socket*` tests pass, and Forever Launcher (PPSA99030) is still running at the 60 s timeout in 2 of 2 runs, with no `sendmsg: control data is not supported`, `what()` or `FATAL` (`main` f3456a4152 stops at that `sendmsg` line). Ubuntu 24.04, GCC 13.3, Release. The results below are from `main` 673f7406c5, except the rebase line. - **On current `main`** ([run by @babyhuey](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6377455718), Linux CI image with lavapipe, Ubuntu 24.04, GCC 13, Release): with the other PRs below merged, `main` f3456a4152 still stops Forever Launcher with `sendmsg: control data is not supported`. With this head (`1142d3a6bc`, clean merge) the 14 `guest_socket*` tests pass and the launcher runs the full 60 s in 2 of 2 runs, ending on the same first-start Wine prefix result described here. - **Data and address faults (516263f8f6),** also found by @wachi35676: a fault writing the data buffer or the address after the descriptors were installed left them open. They are now closed on those returns too. New `guest_socket_rights` case: two pipe ends are passed and received into a read-only data buffer, and the receive must return `EFAULT` with the count in `/proc/self/fd` unchanged. It aborts with the previous `Udp.cpp` and passes with the fix, and the 12 `guest_socket_*` tests pass 3 of 3. The debt entry also says now that several `SCM_RIGHTS` messages in one `sendmsg` arrive as one record. @wachi35676 [re-checked 516263f8f6](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6282257239) merged onto `main` a020d0256: the 14 `guest_socket_*` tests pass 3 of 3, reverting only the `Udp.cpp` hunks makes the faulted-receive case abort, and their probe now leaves no descriptor open after a fault on the data buffer. The Windows build of `Udp.cpp` and `libkernel` succeeds on the same merge. - **Truncation fixed (223a7c147f), after @wachi35676 [found](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6278795517) that a short control buffer leaked the passed descriptors.** With the old record copy and the new test, `guest_socket_rights` aborts. With the fix, the 12 `guest_socket_*` tests pass 3 of 3, and `ctest -R '^guest_|libc'` passes 475 of 476. `guest_module_directories` (a relinker test) fails the same way on `main` in that tree. - **Rebase onto `main` bf2c63f853 (5f492d3e94).** `recvmsg` on `main` now reads the guest's `msghdr` and iovecs into a copy and writes its results back with `ReadGuest`/`WriteGuest`. The control record is written the same way: into the copied `control` pointer, with `controlLength` and `MSG_CTRUNC` in the copied header that is written back. `guest_socket_*` (12 tests, `guest_socket_rights` included) pass 3 of 3. `ctest -R '^guest_|libc'`: 474 of 476 pass. `guest_bad_optional_access` was not built in that tree, and `guest_module_directories` (a relinker test) fails the same way with `main`'s sources. - **New `guest_socket_rights` test (Linux)**, over a stream socket pair: - It passes a pipe's write end, writes through the received descriptor and reads it from the pipe. The received descriptor is not close-on-exec. - It passes the ends of a stream and a datagram socket pair in one record with `MSG_CMSG_CLOEXEC`, and checks that both received sockets are close-on-exec and send and receive. - It passes another pipe end with `MSG_CMSG_CLOEXEC` and checks that the received host descriptor is close-on-exec. A pipe end goes through unchanged, so this reads the host flag, while the sockets' check reads the guest's close-on-exec set. - A control buffer of 16 bytes, too small for the 24-byte record, gets `controlLength` 0 and `MSG_CTRUNC`. So does a record of two descriptors with room for one (20 bytes), and in both cases the count in `/proc/self/fd` is unchanged, so no descriptor leaks. A receive without a control buffer gets the data only. - A closed descriptor gives `EBADF`, and another level or an overlong record gives `EINVAL`. - With `main`'s `Udp.cpp` it aborts on `sendmsg: control data is not supported`. It passes 3 of 3, with `guest_socket_pair` too. - `ctest -R '^guest_|libc'`: 402 of 402 pass. - Forever Launcher (PPSA99030, 01.000.012), in gdb: Wine's first such call is `sendmsg` on a socket-pair end with `MSG_NOSIGNAL | MSG_DONTWAIT`, one byte of data and a 24-byte control buffer holding one `SOL_SOCKET`/`SCM_RIGHTS` record (`cmsg_len` 20) that passes the end of another socket pair. - On `main` with the PRs for its earlier stops merged locally (#6915, #6028, #6939, #6787, #7070, #6469), it stops at 0 s on `sendmsg: control data is not supported`, 2 of 2. - With this PR it gets past it 2 of 2: the descriptor reaches the wineserver thread, and the title stops 1 s in at its next unimplemented call, `kevent: NOTE_LOWAT` (wineserver's kqueue registers `EVFILT_READ` and `EVFILT_WRITE` with `NOTE_LOWAT` 1). That is a separate PR. - Since #7092 (`NOTE_LOWAT`) merged, that next stop is gone. On `main` 98c251fc62 with #6915, #6939, #6787, #7070, #6469 and this PR (17d9e0a516), Forever Launcher runs the whole 60 s in 2 of 2 runs with no unimplemented call. Its first-start prefix setup then reports `title wineboot skipped; prefix must be initialized by payload Wine` and `failed to open "C:\\windows\\system32\\wineboot.exe"`, and Wine exits with 0xC0000135, the launcher's "Setting up the Windows files did not finish". I read that as the launcher's own setup, not a missing emulator call, but I haven't looked further. - @p3n1cillin [checked current `main`](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6479202038) with two catalog titles that run Wine with an in-process wineserver: Forever Launcher (PPSA99030, 01.000.021) and RuneScape Launcher (PPSA99225, 01.000.021). Setup: Ubuntu on WSL2, GCC 15.2.0, Release, llvmpipe on Xvfb, 120 s without input. - On `main` `7fea87746` both abort on `sendmsg: control data is not supported`. - With this PR merged onto `main` `319621ba2e` (`4fa9ea8a0f`, clean), neither stops there. Both start their wineserver, and Wine runs and shuts down in order. - Both then stop on their own first-start prefix setup ("Setting up the Windows files did not finish"), as above. - The five `scm|rights|unix|sendmsg|recvmsg` ctests pass on the merge. - Windows build: @wachi35676 [found](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6242398103) that `Udp.cpp` did not compile there: `GuestControlCloseOnExec` was declared inside the non-Windows block. 17d9e0a516 moves the declaration out of it. A MinGW-w64 `-fsyntax-only` compile of `Udp.cpp` stops on that line before and passes after, and the 11 socket tests and 411 `^guest_` tests pass again on Linux. @screamm then [built head 17d9e0a516 on Windows](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6250728363) (Windows 11, WinLibs GCC 15.2.0, full build and `libs`). Moving the declaration back reproduces the compile error, and the 35 Windows socket, poll, select, rudp, equeue and kqueue tests pass 3 of 3. On Windows, `sendmsg` with an `SCM_RIGHTS` buffer still stops with `control data is not supported on Windows`, as this PR intends. None of their local titles sends or receives such a message. - Windows VM (Windows 11, WinLibs GCC 15.2.0, Release), head 1142d3a6bc and its merge base eaff87674c: the 13 `guest_socket_*` tests that build on Windows (address length, connect to a listener, descriptor flags, descriptors, errors, events, non-socket descriptors, options, pairs, port 0, read/write, stream options, timeouts) pass 3 of 3 on both. `SCM_RIGHTS` still throws on Windows, as described above, so this checks that the change leaves the rest of the Windows socket layer as it was. - macOS: @jotitadev [found](https://github.com/boykopovar/AnyPS5/pull/7090#pullrequestreview-5564937066) that `SO_DOMAIN` and `MSG_CMSG_CLOEXEC` don't exist in XNU's headers, so `Udp.cpp` didn't compile on top of #7332. aff8c2af51 takes the received socket's family from `getsockname()`. Where `MSG_CMSG_CLOEXEC` doesn't exist, it marks each received descriptor with `fcntl(F_SETFD, FD_CLOEXEC)` when the guest asked for it. Their local equivalent compiled with `-Wall -Wextra` on arm64 and x86_64, and `guest_socket_rights` passed 5 of 5 under Rosetta. They also found that the test didn't check the host flag, so a3b3801aa6 adds the pipe-end case above. On Linux the head passes 3 of 3, and so does a build with the receive flag forced to 0, through the `fcntl` path. With the flag forced to 0 and the `fcntl` loop removed, the test fails. `^guest_|libc` passed 411 of 411 on aff8c2af51. @jotitadev then [checked head a3b3801aa6](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6258231364) on #7332 (57bccfbfc, M2 Max, macOS 27.2, Apple clang 21.0.0): `Udp.cpp` compiles with `-Wall -Wextra` on arm64 and x86_64 with no warnings of its own, through the `fcntl` fallback. Under Rosetta `guest_socket_rights` passes 5 of 5, and with the `fcntl` loop removed it fails 3 of 3 on the new pipe check. The 20 socket, UDP, RUDP, poll and select tests pass, except an intermittent `ECONNRESET` in `guest_socket_read_write` that also happens on #7332 alone. ### 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: PPSA99225 #12713 (RuneScape Launcher) past the same `sendmsg` abort ([p3n1cillin's run](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6479202038)); PPSA99030 #12712 (Forever Launcher): #6915, #6028, #6939, #6787, #7070 and #6469 have landed, and this is its last stop on `main` ([babyhuey's run](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6377455718)) - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wachi35676 commented 2026-10-17 22:36:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-17T22:36:28Z.


This doesn't compile on Windows (head 4cd70d4ae; WinLibs GCC 15.2.0, Ninja, Release), alone or merged onto main 11acfdd84:

core/libs/prx/libkernel/Socket/src/Udp.cpp:1371:51: error: 'GuestControlCloseOnExec' was not declared in this scope

GuestControlCloseOnExec is declared at line 1244, inside the #ifndef _WIN32 block that runs from line 1240 to 1328. The flag check at line 1371 in recvmsg_nid_postfix, (passing ? GuestControlCloseOnExec : 0), is outside any guard. The CI windows job was skipped for this PR, so it didn't show. Declaring the constant above the #ifndef _WIN32 fixes the build here.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6242398103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6242398103). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-17T22:36:28Z. --- This doesn't compile on Windows (head `4cd70d4ae`; WinLibs GCC 15.2.0, Ninja, Release), alone or merged onto `main` `11acfdd84`: ``` core/libs/prx/libkernel/Socket/src/Udp.cpp:1371:51: error: 'GuestControlCloseOnExec' was not declared in this scope ``` `GuestControlCloseOnExec` is declared at line 1244, inside the `#ifndef _WIN32` block that runs from line 1240 to 1328. The flag check at line 1371 in `recvmsg_nid_postfix`, `(passing ? GuestControlCloseOnExec : 0)`, is outside any guard. The CI windows job was skipped for this PR, so it didn't show. Declaring the constant above the `#ifndef _WIN32` fixes the build here. AI-assisted: yes (Claude Code); results above were run on this machine.
milescoviello commented 2026-10-17 23:24:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T23:24:38Z.


Thanks @wachi35676, that's right. 17d9e0a516 declares GuestControlCloseOnExec above the #ifndef _WIN32 block, as you suggested; recvmsg masks the flag on every host.

Checked here with MinGW-w64 (x86_64-w64-mingw32-g++-posix): a -fsyntax-only compile of Udp.cpp stops on exactly your line at 4cd70d4ae, and passes with 17d9e0a516 under -Wall -Wextra with no new warnings. On Linux (GCC 13.3, Release) the 11 socket tests pass 3 of 3, and the 411 ^guest_ tests pass. I haven't run a full Windows build.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243037238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6243037238). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T23:24:38Z. --- Thanks @wachi35676, that's right. 17d9e0a516 declares `GuestControlCloseOnExec` above the `#ifndef _WIN32` block, as you suggested; `recvmsg` masks the flag on every host. Checked here with MinGW-w64 (`x86_64-w64-mingw32-g++-posix`): a `-fsyntax-only` compile of `Udp.cpp` stops on exactly your line at 4cd70d4ae, and passes with 17d9e0a516 under `-Wall -Wextra` with no new warnings. On Linux (GCC 13.3, Release) the 11 socket tests pass 3 of 3, and the 411 `^guest_` tests pass. I haven't run a full Windows build. AI-assisted: yes (Claude Code)
screamm commented 2026-10-18 13:53:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-18T13:53:27Z.


Windows build of head 17d9e0a51, merged onto main 0d078f75d together with #7492 (fd2eb3521) and #7509 (c170bba42); all three merge cleanly.

  • Host: Windows 11 Pro 26220, Ryzen 7 5700X, RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON.
  • A real full build and libs both pass (not a syntax-only compile). Udp.cpp builds with no warning, and g++ -Wall -Wextra -fsyntax-only of it with the project's flags is clean.
  • Control for the fix: moving GuestControlCloseOnExec back inside #ifndef _WIN32 reproduces error: 'GuestControlCloseOnExec' was not declared in this scope at the recvmsg flag check (1391:51 in my copy, the same expression @wachi35676 reported at 1371:51); with the declaration above the block it compiles.
  • guest_socket_rights is registered only if(NOT WIN32), so on Windows it neither runs nor skips; ctest does not list it. The 35 Windows socket, poll, select, rudp, equeue and kqueue tests pass 3x on a quiet host (105/105).
  • Windows behaviour with a scratch probe (not part of the PR): on a socketpair, sendmsg without control and recvmsg with a control buffer behave as before (data, controlLength 0, flags 0), recvmsg with MSG_CMSG_CLOEXEC still fails with 45, and sendmsg with a one-descriptor SCM_RIGHTS buffer ends in terminate with sendmsg: control data is not supported on Windows. With Udp.cpp from main the probe differs only in the message text, so the 32 socket tests cannot tell the two apart on Windows.
  • Non-GPU suite (ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): 936 tests, 929 pass, 2 skipped, 5 load timeouts that pass serially. tools/check_conventions.py --base origin/main and git diff origin/main --check pass.

Titles: PPSA99030 is not available here. recvmsg is imported by 13 and sendmsg by 12 local titles. I ran PPSA74126 (Stremio Plus) and PPSA99082 (OpenNOW) for 45 s each, and PPSA99169 (RetroArch, app.exe only; its picker child's output is not captured), with a local diagnostic libkernel (reverted) that logged every sendmsg and recvmsg call with a control buffer. It logged none, so I have no local title that sends or receives an SCM_RIGHTS message.

Not checked: the descriptor passing itself (Linux only, guest_socket_rights not run), Linux, a console, PPSA99030.

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250728363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6250728363). Originally posted by [screamm](https://github.com/screamm) on 2026-10-18T13:53:27Z. --- Windows build of head `17d9e0a51`, merged onto `main` `0d078f75d` together with #7492 (`fd2eb3521`) and #7509 (`c170bba42`); all three merge cleanly. - Host: Windows 11 Pro 26220, Ryzen 7 5700X, RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`. - A real full build and `libs` both pass (not a syntax-only compile). `Udp.cpp` builds with no warning, and `g++ -Wall -Wextra -fsyntax-only` of it with the project's flags is clean. - Control for the fix: moving `GuestControlCloseOnExec` back inside `#ifndef _WIN32` reproduces `error: 'GuestControlCloseOnExec' was not declared in this scope` at the `recvmsg` flag check (`1391:51` in my copy, the same expression @wachi35676 reported at `1371:51`); with the declaration above the block it compiles. - `guest_socket_rights` is registered only `if(NOT WIN32)`, so on Windows it neither runs nor skips; ctest does not list it. The 35 Windows socket, poll, select, rudp, equeue and kqueue tests pass 3x on a quiet host (105/105). - Windows behaviour with a scratch probe (not part of the PR): on a `socketpair`, `sendmsg` without control and `recvmsg` with a control buffer behave as before (data, `controlLength` 0, flags 0), `recvmsg` with `MSG_CMSG_CLOEXEC` still fails with 45, and `sendmsg` with a one-descriptor `SCM_RIGHTS` buffer ends in `terminate` with `sendmsg: control data is not supported on Windows`. With `Udp.cpp` from `main` the probe differs only in the message text, so the 32 socket tests cannot tell the two apart on Windows. - Non-GPU suite (`ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'`): 936 tests, 929 pass, 2 skipped, 5 load timeouts that pass serially. `tools/check_conventions.py --base origin/main` and `git diff origin/main --check` pass. Titles: PPSA99030 is not available here. `recvmsg` is imported by 13 and `sendmsg` by 12 local titles. I ran PPSA74126 (Stremio Plus) and PPSA99082 (OpenNOW) for 45 s each, and PPSA99169 (RetroArch, `app.exe` only; its picker child's output is not captured), with a local diagnostic `libkernel` (reverted) that logged every `sendmsg` and `recvmsg` call with a control buffer. It logged none, so I have no local title that sends or receives an `SCM_RIGHTS` message. Not checked: the descriptor passing itself (Linux only, `guest_socket_rights` not run), Linux, a console, PPSA99030. Written with Claude Code assistance (validation by a subagent, reviewed in this session).
milescoviello commented 2026-10-18 18:45:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T18:45:40Z.


Thanks @screamm for the full Windows build, the control and the probe. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253709789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6253709789). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T18:45:40Z. --- Thanks @screamm for the full Windows build, the control and the probe. I added it to the description. AI-assisted: yes (Claude Code)
jotitadev commented 2026-10-18 21:04:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T21:04:09Z.

Review: COMMENTED


macOS build note on head 17d9e0a51.

The new code sits under #ifndef _WIN32, so it is also compiled on macOS hosts, but two of its identifiers do not exist in XNU's headers:

  • core/libs/prx/libkernel/Socket/src/Udp.cpp:1315: getsockopt(native, SOL_SOCKET, SO_DOMAIN, ...). macOS has no SO_DOMAIN.
  • core/libs/prx/libkernel/Socket/src/Udp.cpp:1396: MSG_CMSG_CLOEXEC. macOS has no such recv flag.

Repro on an M2 Max (macOS 27.2, Apple clang 21.0.0, arm64): merging this head onto #7332 (b182750ca, the PR that builds libkernel on macOS) is conflict-free. A -fsyntax-only compile of the merged Udp.cpp then fails with exactly these two errors:

Udp.cpp:1421:42: error: use of undeclared identifier 'SO_DOMAIN'
Udp.cpp:1502:122: error: use of undeclared identifier 'MSG_CMSG_CLOEXEC'

The same file from #7332 alone compiles cleanly. The line numbers above are in the merged file; the lines in this PR are 1315 and 1396. guest_socket_rights is registered under if(NOT WIN32), so it would be built on macOS too.

Suggestion that keeps one path for both Unix hosts:

  • Take the family from getsockname() (sockaddr_storage::ss_family) instead of SO_DOMAIN. On macOS this returns AF_UNIX for a socketpair end and AF_INET6 for an unbound IPv6 socket, and SO_TYPE works as it is.
  • Drop MSG_CMSG_CLOEXEC and set FD_CLOEXEC with fcntl on each received descriptor when the guest asked for it, before InstallPassed. Alternatively, guard the flag with #ifdef MSG_CMSG_CLOEXEC and use the fcntl path otherwise.

Not checked: running guest_socket_rights on macOS. The full libs build on macOS needs #7332 and an x86-64 build, which I could not run here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5564937066 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#pullrequestreview-5564937066). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T21:04:09Z. **Review:** COMMENTED --- macOS build note on head `17d9e0a51`. The new code sits under `#ifndef _WIN32`, so it is also compiled on macOS hosts, but two of its identifiers do not exist in XNU's headers: - `core/libs/prx/libkernel/Socket/src/Udp.cpp:1315`: `getsockopt(native, SOL_SOCKET, SO_DOMAIN, ...)`. macOS has no `SO_DOMAIN`. - `core/libs/prx/libkernel/Socket/src/Udp.cpp:1396`: `MSG_CMSG_CLOEXEC`. macOS has no such recv flag. Repro on an M2 Max (macOS 27.2, Apple clang 21.0.0, arm64): merging this head onto #7332 (`b182750ca`, the PR that builds libkernel on macOS) is conflict-free. A `-fsyntax-only` compile of the merged `Udp.cpp` then fails with exactly these two errors: ``` Udp.cpp:1421:42: error: use of undeclared identifier 'SO_DOMAIN' Udp.cpp:1502:122: error: use of undeclared identifier 'MSG_CMSG_CLOEXEC' ``` The same file from #7332 alone compiles cleanly. The line numbers above are in the merged file; the lines in this PR are 1315 and 1396. `guest_socket_rights` is registered under `if(NOT WIN32)`, so it would be built on macOS too. Suggestion that keeps one path for both Unix hosts: - Take the family from `getsockname()` (`sockaddr_storage::ss_family`) instead of `SO_DOMAIN`. On macOS this returns `AF_UNIX` for a `socketpair` end and `AF_INET6` for an unbound IPv6 socket, and `SO_TYPE` works as it is. - Drop `MSG_CMSG_CLOEXEC` and set `FD_CLOEXEC` with `fcntl` on each received descriptor when the guest asked for it, before `InstallPassed`. Alternatively, guard the flag with `#ifdef MSG_CMSG_CLOEXEC` and use the `fcntl` path otherwise. Not checked: running `guest_socket_rights` on macOS. The full libs build on macOS needs #7332 and an x86-64 build, which I could not run here. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-18 21:06:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T21:06:55Z.


@jotitadev thanks, both are right. I took your first suggestion and the #ifdef variant of the second, in aff8c2af51:

  • The received socket's family comes from getsockname() (ss_family) instead of SO_DOMAIN. SO_TYPE is unchanged.
  • Where MSG_CMSG_CLOEXEC exists, recvmsg still sets close-on-exec atomically, so Linux behaves exactly as tested. Elsewhere each received descriptor gets fcntl(F_SETFD, FD_CLOEXEC) right after recvmsg when the guest asked for it, before InstallPassed. I kept the atomic flag where it exists because the fcntl path leaves a window in which another thread's spawn could inherit the descriptor.

I'm running guest_socket_rights on Linux, plus once with the fallback forced so the fcntl path runs too, and the ^guest_|libc set. I'll push when those pass. I can't build for macOS here, so a -fsyntax-only check of the pushed head on top of #7332 would be welcome if you have time.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255151983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6255151983). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T21:06:55Z. --- @jotitadev thanks, both are right. I took your first suggestion and the `#ifdef` variant of the second, in aff8c2af51: - The received socket's family comes from `getsockname()` (`ss_family`) instead of `SO_DOMAIN`. `SO_TYPE` is unchanged. - Where `MSG_CMSG_CLOEXEC` exists, `recvmsg` still sets close-on-exec atomically, so Linux behaves exactly as tested. Elsewhere each received descriptor gets `fcntl(F_SETFD, FD_CLOEXEC)` right after `recvmsg` when the guest asked for it, before `InstallPassed`. I kept the atomic flag where it exists because the `fcntl` path leaves a window in which another thread's spawn could inherit the descriptor. I'm running `guest_socket_rights` on Linux, plus once with the fallback forced so the `fcntl` path runs too, and the `^guest_|libc` set. I'll push when those pass. I can't build for macOS here, so a `-fsyntax-only` check of the pushed head on top of #7332 would be welcome if you have time. AI-assisted: yes (Claude Code)
jotitadev commented 2026-10-19 00:13:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:13:18Z.


@milescoviello thanks. feat/scm-rights is still at 17d9e0a51, and aff8c2af51 isn't on GitHub yet, so I checked the current head plus a local equivalent of what you described. I'll re-run on the pushed head.

M2 Max, macOS 27.2, Apple clang 21.0.0. Base: #7332 at 4a1c11a91 (the PR merges onto it without conflicts).

  • 17d9e0a51 on #7332: Udp.cpp still fails -fsyntax-only for arm64 and x86_64, with the same two errors (SO_DOMAIN, MSG_CMSG_CLOEXEC). #7332 alone compiles.
  • Local equivalent: family from getsockname() ss_family, MSG_CMSG_CLOEXEC under #ifdef, and otherwise fcntl(F_SETFD, FD_CLOEXEC) on each received descriptor before InstallPassed. Udp.cpp compiles with -Wall -Wextra and no warnings on both arches. In a real x86_64 build run under Rosetta, guest_socket_rights passes 5 of 5. The 20 guest_socket_*, guest_udp, guest_rudp_*, guest_poll and guest_select* tests pass. In 3 repeats, guest_socket_read_write failed once and passed on re-run; it is already intermittent on #7332 alone.

One gap in the test: it never checks close-on-exec on the received host descriptor. The only ControlCloseOnExec case receives two sockets. For a guest socket, F_GETFD reads closeOnExecDescriptors, which InstallPassed fills, and not the host fd. So the check passes when nothing sets the host flag:

  • macOS, local equivalent with the fcntl loop removed: guest_socket_rights passes 3 of 3.
  • Linux (Ubuntu 26.04, GCC 15.2, Release), 17d9e0a51 with MSG_CMSG_CLOEXEC removed from the recvmsg call: it also passes 3 of 3.

So your forced-fallback run on Linux will pass whether or not the fcntl path runs. One way to cover both paths is to receive a passed pipe end with ControlCloseOnExec and require fcntl_nid_postfix(writer, GetDescriptorFlags) == 1. A pipe goes through InstallPassed unchanged, so the guest sees the host flag. With that check, both mutations fail (passed pipe without FD_CLOEXEC), and the unmodified code passes on macOS (with the fallback) and on Linux.

Not checked: your actual aff8c2af51, arm64 runtime (the libs build is x86-64 only on macOS).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6256920166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6256920166). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T00:13:18Z. --- @milescoviello thanks. `feat/scm-rights` is still at `17d9e0a51`, and aff8c2af51 isn't on GitHub yet, so I checked the current head plus a local equivalent of what you described. I'll re-run on the pushed head. M2 Max, macOS 27.2, Apple clang 21.0.0. Base: #7332 at `4a1c11a91` (the PR merges onto it without conflicts). - `17d9e0a51` on #7332: `Udp.cpp` still fails `-fsyntax-only` for arm64 and x86_64, with the same two errors (`SO_DOMAIN`, `MSG_CMSG_CLOEXEC`). #7332 alone compiles. - Local equivalent: family from `getsockname()` `ss_family`, `MSG_CMSG_CLOEXEC` under `#ifdef`, and otherwise `fcntl(F_SETFD, FD_CLOEXEC)` on each received descriptor before `InstallPassed`. `Udp.cpp` compiles with `-Wall -Wextra` and no warnings on both arches. In a real x86_64 build run under Rosetta, `guest_socket_rights` passes 5 of 5. The 20 `guest_socket_*`, `guest_udp`, `guest_rudp_*`, `guest_poll` and `guest_select*` tests pass. In 3 repeats, `guest_socket_read_write` failed once and passed on re-run; it is already intermittent on #7332 alone. One gap in the test: it never checks close-on-exec on the received host descriptor. The only `ControlCloseOnExec` case receives two sockets. For a guest socket, `F_GETFD` reads `closeOnExecDescriptors`, which `InstallPassed` fills, and not the host fd. So the check passes when nothing sets the host flag: - macOS, local equivalent with the `fcntl` loop removed: `guest_socket_rights` passes 3 of 3. - Linux (Ubuntu 26.04, GCC 15.2, Release), `17d9e0a51` with `MSG_CMSG_CLOEXEC` removed from the `recvmsg` call: it also passes 3 of 3. So your forced-fallback run on Linux will pass whether or not the `fcntl` path runs. One way to cover both paths is to receive a passed pipe end with `ControlCloseOnExec` and require `fcntl_nid_postfix(writer, GetDescriptorFlags) == 1`. A pipe goes through `InstallPassed` unchanged, so the guest sees the host flag. With that check, both mutations fail (`passed pipe without FD_CLOEXEC`), and the unmodified code passes on macOS (with the fallback) and on Linux. Not checked: your actual aff8c2af51, arm64 runtime (the libs build is x86-64 only on macOS). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
milescoviello commented 2026-10-19 01:04:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T01:04:30Z.


@jotitadev thanks, and sorry the commit wasn't up yet when you looked. Both are pushed now:

  • aff8c2af51 is the fix as described: getsockname() for the family, MSG_CMSG_CLOEXEC where it exists, otherwise fcntl(F_SETFD, FD_CLOEXEC) per received descriptor.
  • a3b3801aa6 is the check you suggested. CheckPassedPipe now also passes a pipe end with ControlCloseOnExec and requires F_GETFD == 1 on it.

You're right that my forced-fallback run proved nothing before that check. With it, on Linux (Ubuntu 24.04, GCC 13.3):

  • The head passes 3 of 3.
  • With the receive flag forced to 0, it passes through the fcntl path.
  • With the flag forced to 0 and the fcntl loop removed, it fails.
  • The ^guest_|libc set passed 411 of 411 on aff8c2af51.

A run of -fsyntax-only on a3b3801aa6 over #7332 would confirm the macOS side whenever you get to it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257457434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6257457434). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T01:04:30Z. --- @jotitadev thanks, and sorry the commit wasn't up yet when you looked. Both are pushed now: - aff8c2af51 is the fix as described: `getsockname()` for the family, `MSG_CMSG_CLOEXEC` where it exists, otherwise `fcntl(F_SETFD, FD_CLOEXEC)` per received descriptor. - a3b3801aa6 is the check you suggested. `CheckPassedPipe` now also passes a pipe end with `ControlCloseOnExec` and requires `F_GETFD == 1` on it. You're right that my forced-fallback run proved nothing before that check. With it, on Linux (Ubuntu 24.04, GCC 13.3): - The head passes 3 of 3. - With the receive flag forced to 0, it passes through the `fcntl` path. - With the flag forced to 0 and the `fcntl` loop removed, it fails. - The `^guest_|libc` set passed 411 of 411 on aff8c2af51. A run of `-fsyntax-only` on a3b3801aa6 over #7332 would confirm the macOS side whenever you get to it. AI-assisted: yes (Claude Code)
jotitadev commented 2026-10-19 02:16:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T02:16:14Z.


@milescoviello re-ran on the pushed head a3b3801aa. The macOS side is fine.

M2 Max, macOS 27.2, Apple clang 21.0.0. Base: #7332 at 57bccfbfc. This PR merges onto it with no conflicts.

  • Udp.cpp -fsyntax-only -Wall -Wextra, arm64 and x86_64: 0 errors, and no warnings in Udp.cpp. The only warnings come from existing headers (-Wreturn-type-c-linkage in Equeue.hpp and General.hpp). On macOS, MSG_CMSG_CLOEXEC is undefined, so the fcntl fallback is the path that gets compiled.
  • Real x86_64 build, run under Rosetta: guest_socket_rights passes 5 of 5.
  • The 20 guest_socket_*, guest_udp, guest_rudp_*, guest_poll and guest_select* tests passed in 2 of 3 runs. In the third, guest_socket_read_write aborted at line 154 with errno 54 (ECONNRESET) and passed on re-run. Run alone, it fails about once in 10 to 30 tries. It was already intermittent on #7332 without this PR in my previous run.
  • Mutation: I removed the fcntl(F_SETFD, FD_CLOEXEC) loop. guest_socket_rights now fails 3 of 3. It aborts on the new pipe check: with a temporary print, F_GETFD on the received pipe end reads 0 with the mutation and 1 without it. So the test now covers the macOS path.

Not checked: arm64 runtime, because the libs build is x86-64 only on macOS.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6258231364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6258231364). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T02:16:14Z. --- @milescoviello re-ran on the pushed head `a3b3801aa`. The macOS side is fine. M2 Max, macOS 27.2, Apple clang 21.0.0. Base: #7332 at `57bccfbfc`. This PR merges onto it with no conflicts. - `Udp.cpp` `-fsyntax-only -Wall -Wextra`, arm64 and x86_64: 0 errors, and no warnings in `Udp.cpp`. The only warnings come from existing headers (`-Wreturn-type-c-linkage` in `Equeue.hpp` and `General.hpp`). On macOS, `MSG_CMSG_CLOEXEC` is undefined, so the `fcntl` fallback is the path that gets compiled. - Real x86_64 build, run under Rosetta: `guest_socket_rights` passes 5 of 5. - The 20 `guest_socket_*`, `guest_udp`, `guest_rudp_*`, `guest_poll` and `guest_select*` tests passed in 2 of 3 runs. In the third, `guest_socket_read_write` aborted at line 154 with errno 54 (`ECONNRESET`) and passed on re-run. Run alone, it fails about once in 10 to 30 tries. It was already intermittent on #7332 without this PR in my previous run. - Mutation: I removed the `fcntl(F_SETFD, FD_CLOEXEC)` loop. `guest_socket_rights` now fails 3 of 3. It aborts on the new pipe check: with a temporary print, `F_GETFD` on the received pipe end reads 0 with the mutation and 1 without it. So the test now covers the macOS path. Not checked: arm64 runtime, because the libs build is x86-64 only on macOS. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
milescoviello commented 2026-10-19 02:18:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T02:18:32Z.


@jotitadev thanks, that settles the macOS side. The mutation result is the useful part: it shows the new pipe check actually exercises the fcntl path. I've added your results to the PR body.

About the guest_socket_read_write abort at line 154: that loop keeps writing to the server end after the client closed. The first write succeeds, the client's stack answers with an RST, and a later write fails. Linux and FreeBSD report a reset that arrives in CLOSE_WAIT as EPIPE, which is what the test expects. I believe XNU reports it as ECONNRESET in that state, and which of the two a write sees depends on whether the RST is processed before or during that write. That would explain 1 failure in 10 to 30 runs and no failures on Linux. If that's right, it belongs with #7332 (accept 54 alongside 32 on Apple at that line), not in this PR. I haven't verified it on a Mac.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6258256845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6258256845). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T02:18:32Z. --- @jotitadev thanks, that settles the macOS side. The mutation result is the useful part: it shows the new pipe check actually exercises the `fcntl` path. I've added your results to the PR body. About the `guest_socket_read_write` abort at line 154: that loop keeps writing to the server end after the client closed. The first write succeeds, the client's stack answers with an RST, and a later write fails. Linux and FreeBSD report a reset that arrives in `CLOSE_WAIT` as `EPIPE`, which is what the test expects. I believe XNU reports it as `ECONNRESET` in that state, and which of the two a write sees depends on whether the RST is processed before or during that write. That would explain 1 failure in 10 to 30 runs and no failures on Linux. If that's right, it belongs with #7332 (accept 54 alongside 32 on Apple at that line), not in this PR. I haven't verified it on a Mac. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-19 21:43:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T21:43:26Z.


Rebased onto main bf2c63f853 (5f492d3e94). recvmsg on main now works on a copy of the guest's msghdr and writes its results back with WriteGuest. The SCM_RIGHTS record now goes through the same path: it is written to the copied control pointer, and controlLength and MSG_CTRUNC go into the header copy that is written back. guest_socket_* pass 3 of 3 (12 tests); details are in the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278054920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6278054920). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T21:43:26Z. --- Rebased onto `main` bf2c63f853 (5f492d3e94). `recvmsg` on `main` now works on a copy of the guest's `msghdr` and writes its results back with `WriteGuest`. The SCM_RIGHTS record now goes through the same path: it is written to the copied `control` pointer, and `controlLength` and `MSG_CTRUNC` go into the header copy that is written back. `guest_socket_*` pass 3 of 3 (12 tests); details are in the description. AI-assisted: yes (Claude Code)
wachi35676 commented 2026-10-19 22:30:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T22:30:19Z.


Re-run of head 5f492d3e9 merged onto current main 0929be5e8 (clean).

Linux: WSL Ubuntu 24.04, GCC 13.3, Release, BUILD_TESTING=ON.

  • guest_socket_* (12 tests, guest_socket_rights included) pass 3/3.
  • Negative control (Udp.cpp from main, tests kept): guest_socket_rights aborts, and the other 11 pass.

Windows: Windows 11 Home 26300, WinLibs GCC 15.2.0, Release.

  • It builds.
  • guest_socket_* (25 tests; guest_socket_rights is not registered on Windows) plus guest_kqueue and guest_select pass 3/3.
  • With Udp.cpp from main the 25 also pass, as expected, since the Windows path only throws.

Truncation. A probe sends one SCM_RIGHTS record with two pipe write ends (record 24 bytes). It receives with different control capacities and counts /proc/self/fd before and after the receive:

2 fds sent (record 24 bytes), control capacity 16: bytes=1 controlLength=16 MSG_CTRUNC=1 cmsg_len=24, process fds after-before=2
2 fds sent (record 24 bytes), control capacity 20: bytes=1 controlLength=20 MSG_CTRUNC=1 cmsg_len=24, process fds after-before=2
2 fds sent (record 24 bytes), control capacity 24: bytes=1 controlLength=24 MSG_CTRUNC=0 cmsg_len=24, process fds after-before=2
2 fds sent (record 24 bytes), control capacity 32: bytes=1 controlLength=24 MSG_CTRUNC=0 cmsg_len=24, process fds after-before=2
  • MSG_CTRUNC is set correctly through the copied header.
  • With a short buffer, both received descriptors stay open, but the guest is told about none of them (capacity 16) or one (capacity 20). Two descriptors leak at capacity 16 and one at capacity 20.
  • FreeBSD 11.4 handles this differently in kern_recvit:
    • it copies only control mbufs that fit whole (len >= m->m_len);
    • it sets MSG_CTRUNC and calls m_dispose_extcontrolm(m) on the rest, which closes the descriptors that didn't fit.
    • So for this record it returns controlLength 0, MSG_CTRUNC, and no new descriptors open. That is not "truncated to the caller's buffer" with the header copied, which is what the description and the 16-byte test case expect.
  • A fix could:
    • close (or not install) the descriptors of a record that doesn't fit whole;
    • copy only whole records;
    • update the 16-byte test case to expect controlLength == 0.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278795517 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6278795517). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-19T22:30:19Z. --- Re-run of head 5f492d3e9 merged onto current `main` 0929be5e8 (clean). **Linux:** WSL Ubuntu 24.04, GCC 13.3, Release, `BUILD_TESTING=ON`. - `guest_socket_*` (12 tests, `guest_socket_rights` included) pass 3/3. - Negative control (`Udp.cpp` from `main`, tests kept): `guest_socket_rights` aborts, and the other 11 pass. **Windows:** Windows 11 Home 26300, WinLibs GCC 15.2.0, Release. - It builds. - `guest_socket_*` (25 tests; `guest_socket_rights` is not registered on Windows) plus `guest_kqueue` and `guest_select` pass 3/3. - With `Udp.cpp` from `main` the 25 also pass, as expected, since the Windows path only throws. **Truncation.** A probe sends one `SCM_RIGHTS` record with two pipe write ends (record 24 bytes). It receives with different control capacities and counts `/proc/self/fd` before and after the receive: ``` 2 fds sent (record 24 bytes), control capacity 16: bytes=1 controlLength=16 MSG_CTRUNC=1 cmsg_len=24, process fds after-before=2 2 fds sent (record 24 bytes), control capacity 20: bytes=1 controlLength=20 MSG_CTRUNC=1 cmsg_len=24, process fds after-before=2 2 fds sent (record 24 bytes), control capacity 24: bytes=1 controlLength=24 MSG_CTRUNC=0 cmsg_len=24, process fds after-before=2 2 fds sent (record 24 bytes), control capacity 32: bytes=1 controlLength=24 MSG_CTRUNC=0 cmsg_len=24, process fds after-before=2 ``` - `MSG_CTRUNC` is set correctly through the copied header. - With a short buffer, both received descriptors stay open, but the guest is told about none of them (capacity 16) or one (capacity 20). Two descriptors leak at capacity 16 and one at capacity 20. - FreeBSD 11.4 handles this differently in [`kern_recvit`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_syscalls.c#L1140-L1155): - it copies only control mbufs that fit whole (`len >= m->m_len`); - it sets `MSG_CTRUNC` and calls `m_dispose_extcontrolm(m)` on the rest, which closes the descriptors that didn't fit. - So for this record it returns `controlLength` 0, `MSG_CTRUNC`, and no new descriptors open. That is not "truncated to the caller's buffer" with the header copied, which is what the description and the 16-byte test case expect. - A fix could: - close (or not install) the descriptors of a record that doesn't fit whole; - copy only whole records; - update the 16-byte test case to expect `controlLength == 0`. AI-assisted: yes (Claude Code); results above were run on this machine.
milescoviello commented 2026-10-19 22:35:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T22:35:38Z.


@wachi35676 thanks, you're right, and the probe that counts /proc/self/fd shows the leak directly. I checked 11.4's kern_recvit (uipc_syscalls.c L1143-L1155). The loop copies only while a whole control mbuf fits (len >= m->m_len), and msg_controllen adds up only what it copied. Whatever is left gets MSG_CTRUNC and m_dispose_extcontrolm, which closes those descriptors. My description and the debt entry claimed the partial copy was what kern_recvit does, and that was wrong.

223a7c147f (not pushed yet) does it FreeBSD's way:

  • A record that doesn't fit is not copied. controlLength is 0, MSG_CTRUNC is set, and the descriptors it carried are closed: sockets through GuestSockets::Close, other descriptors with close.
  • A fault writing the record also closes them and returns EFAULT, as kern_recvit's error path does.
  • guest_socket_rights now expects controlLength 0 for the 16-byte buffer, and adds your case of two descriptors with room for one. Both check that the count in /proc/self/fd is unchanged.
  • The debt entry's sentence about the partial copy is gone.

Red/green runs and the wider ^guest_ set are queued behind the current batch. I'll push and update the description when they're green.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278873236 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6278873236). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T22:35:38Z. --- @wachi35676 thanks, you're right, and the probe that counts `/proc/self/fd` shows the leak directly. I checked 11.4's `kern_recvit` (`uipc_syscalls.c` L1143-L1155). The loop copies only while a whole control mbuf fits (`len >= m->m_len`), and `msg_controllen` adds up only what it copied. Whatever is left gets `MSG_CTRUNC` and `m_dispose_extcontrolm`, which closes those descriptors. My description and the debt entry claimed the partial copy was what `kern_recvit` does, and that was wrong. 223a7c147f (not pushed yet) does it FreeBSD's way: - A record that doesn't fit is not copied. `controlLength` is 0, `MSG_CTRUNC` is set, and the descriptors it carried are closed: sockets through `GuestSockets::Close`, other descriptors with `close`. - A fault writing the record also closes them and returns `EFAULT`, as `kern_recvit`'s error path does. - `guest_socket_rights` now expects `controlLength` 0 for the 16-byte buffer, and adds your case of two descriptors with room for one. Both check that the count in `/proc/self/fd` is unchanged. - The debt entry's sentence about the partial copy is gone. Red/green runs and the wider `^guest_` set are queued behind the current batch. I'll push and update the description when they're green. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-19 23:20:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T23:20:47Z.


@wachi35676 pushed 223a7c147f, and the description now says it the FreeBSD way. A record that doesn't fit whole gets controlLength 0 and MSG_CTRUNC, and its descriptors are closed. guest_socket_rights now covers your two cases (16 bytes, and two descriptors with room for one), and checks that the count in /proc/self/fd is unchanged after each. With the old record copy it aborts. With the fix, the 12 guest_socket_* tests pass 3 of 3 and ^guest_|libc passes 475 of 476 (the one failure, the relinker test guest_module_directories, fails the same way on main here). Your probe on a short buffer should now show process fds after-before=0.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279517051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6279517051). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T23:20:47Z. --- @wachi35676 pushed 223a7c147f, and the description now says it the FreeBSD way. A record that doesn't fit whole gets `controlLength` 0 and `MSG_CTRUNC`, and its descriptors are closed. `guest_socket_rights` now covers your two cases (16 bytes, and two descriptors with room for one), and checks that the count in `/proc/self/fd` is unchanged after each. With the old record copy it aborts. With the fix, the 12 `guest_socket_*` tests pass 3 of 3 and `^guest_|libc` passes 475 of 476 (the one failure, the relinker test `guest_module_directories`, fails the same way on `main` here). Your probe on a short buffer should now show `process fds after-before=0`. AI-assisted: yes (Claude Code)
wachi35676 commented 2026-10-20 00:14:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T00:14:46Z.


Re-run of head 223a7c147 merged onto current main eb7500680 (clean).

Linux: WSL Ubuntu 24.04, GCC 13.3, Release, BUILD_TESTING=ON.

  • guest_socket_* (12 tests) pass 3/3.
  • Negative control: with Udp.cpp from the previous head 5f492d3e9, guest_socket_rights aborts and the other 11 pass. With Udp.cpp from main it aborts too (sendmsg: control data is not supported).

Windows: Windows 11 Home 26300, WinLibs GCC 15.2.0, Release.

  • The full build succeeds.
  • guest_socket_* (25 tests) and guest_kqueue pass 3/3.
  • guest_select aborts (0xc0000409) 3/3 here. It aborts the same way with Udp.cpp from main, so this PR doesn't cause it.

Short control buffer. I ran the same probe as last time. It counts /proc/self/fd around the receive and closes whatever the record reports. "Two records" means one sendmsg with two separate SCM_RIGHTS cmsgs of one descriptor each.

one record, 2 fds (24 bytes), capacity 16: controlLength=0  MSG_CTRUNC=1 reported=0 fds after-before=0
one record, 2 fds (24 bytes), capacity 20: controlLength=0  MSG_CTRUNC=1 reported=0 fds after-before=0
one record, 2 fds (24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2
one record, 2 fds (24 bytes), capacity 32: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2
two records, 1 fd each (2x24 bytes), capacity 16: controlLength=0  MSG_CTRUNC=1 reported=0 fds after-before=0
two records, 1 fd each (2x24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2
two records, 1 fd each (2x24 bytes), capacity 48: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2
read-only control buffer, capacity 32: result=-1 errno=14 fds after-before=0
read-only data buffer, control capacity 32: result=-1 errno=14 fds after-before=2
  • The short-buffer leak is fixed. Capacities 16 and 20 now give controlLength 0, MSG_CTRUNC and no new descriptors. 24 and 32 give the whole 24-byte record. A fault writing the record returns EFAULT and closes both descriptors.
  • Still leaks when the data copy faults. If the guest data buffer can't be written, recvmsg returns EFAULT but leaves both received descriptors open, and the guest never learns their numbers. return Fail(14) after WriteGuest(vector.base, ...) (and the msg_name write after it) runs once passed is installed, but before the new dispose branch. In FreeBSD 11.4 a data-copy error from soreceive reaches kern_recvit's out: label, which calls m_dispose_extcontrolm(control) whenever error != 0 (L1157-L1170). Closing passed on those two early returns as well (the same loop) would match it.
  • Two cmsgs become one record. sendmsg flattens every SCM_RIGHTS cmsg into a single host cmsg, so the receiver sees one 2-descriptor record. Nothing leaks, but the layout differs from FreeBSD: there, unp_internalize keeps one control mbuf per cmsg (uipc_usrreq.c L2096), so the receiver would get two 24-byte records. At capacity 24 or 32 it would get the first record, MSG_CTRUNC, and the second descriptor closed. At capacity 48 it would get both records. So the "only the first record fits" case can't happen here. This could just be a line in the debt entry.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6280231230 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6280231230). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T00:14:46Z. --- Re-run of head 223a7c147 merged onto current `main` eb7500680 (clean). **Linux:** WSL Ubuntu 24.04, GCC 13.3, Release, `BUILD_TESTING=ON`. - `guest_socket_*` (12 tests) pass 3/3. - Negative control: with `Udp.cpp` from the previous head 5f492d3e9, `guest_socket_rights` aborts and the other 11 pass. With `Udp.cpp` from `main` it aborts too (`sendmsg: control data is not supported`). **Windows:** Windows 11 Home 26300, WinLibs GCC 15.2.0, Release. - The full build succeeds. - `guest_socket_*` (25 tests) and `guest_kqueue` pass 3/3. - `guest_select` aborts (0xc0000409) 3/3 here. It aborts the same way with `Udp.cpp` from `main`, so this PR doesn't cause it. **Short control buffer.** I ran the same probe as last time. It counts `/proc/self/fd` around the receive and closes whatever the record reports. "Two records" means one `sendmsg` with two separate `SCM_RIGHTS` cmsgs of one descriptor each. ``` one record, 2 fds (24 bytes), capacity 16: controlLength=0 MSG_CTRUNC=1 reported=0 fds after-before=0 one record, 2 fds (24 bytes), capacity 20: controlLength=0 MSG_CTRUNC=1 reported=0 fds after-before=0 one record, 2 fds (24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2 one record, 2 fds (24 bytes), capacity 32: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2 two records, 1 fd each (2x24 bytes), capacity 16: controlLength=0 MSG_CTRUNC=1 reported=0 fds after-before=0 two records, 1 fd each (2x24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2 two records, 1 fd each (2x24 bytes), capacity 48: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2 read-only control buffer, capacity 32: result=-1 errno=14 fds after-before=0 read-only data buffer, control capacity 32: result=-1 errno=14 fds after-before=2 ``` - The short-buffer leak is fixed. Capacities 16 and 20 now give `controlLength` 0, `MSG_CTRUNC` and no new descriptors. 24 and 32 give the whole 24-byte record. A fault writing the record returns `EFAULT` and closes both descriptors. - **Still leaks when the data copy faults.** If the guest data buffer can't be written, `recvmsg` returns `EFAULT` but leaves both received descriptors open, and the guest never learns their numbers. `return Fail(14)` after `WriteGuest(vector.base, ...)` (and the `msg_name` write after it) runs once `passed` is installed, but before the new dispose branch. In FreeBSD 11.4 a data-copy error from `soreceive` reaches `kern_recvit`'s `out:` label, which calls `m_dispose_extcontrolm(control)` whenever `error != 0` ([L1157-L1170](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_syscalls.c#L1157-L1170)). Closing `passed` on those two early returns as well (the same loop) would match it. - **Two cmsgs become one record.** `sendmsg` flattens every `SCM_RIGHTS` cmsg into a single host cmsg, so the receiver sees one 2-descriptor record. Nothing leaks, but the layout differs from FreeBSD: there, `unp_internalize` keeps one control mbuf per cmsg ([uipc_usrreq.c L2096](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_usrreq.c#L2096)), so the receiver would get two 24-byte records. At capacity 24 or 32 it would get the first record, `MSG_CTRUNC`, and the second descriptor closed. At capacity 48 it would get both records. So the "only the first record fits" case can't happen here. This could just be a line in the debt entry. AI-assisted: yes (Claude Code); results above were run on this machine.
milescoviello commented 2026-10-20 02:47:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T02:47:42Z.


@wachi35676 thanks again, both points were right. 516263f8f6 (pushed) closes the passed descriptors on the data and address EFAULT returns as well, through the same helper as the short-buffer path, which matches kern_recvit's out: disposal on any error. A new guest_socket_rights case passes two pipe ends and receives into a read-only data buffer. It requires EFAULT and an unchanged /proc/self/fd count, aborts with the previous Udp.cpp, and passes with the fix; the 12 guest_socket_* tests pass 3 of 3.

On the two cmsgs: Linux merges them into one SCM_RIGHTS record on the receiving side, so keeping FreeBSD's one record per message would need bookkeeping of our own. As you suggested, the debt entry now records it: several SCM_RIGHTS messages in one sendmsg arrive as one record, so a buffer with room for only the first record can't receive it alone.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6282157245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6282157245). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-20T02:47:42Z. --- @wachi35676 thanks again, both points were right. 516263f8f6 (pushed) closes the passed descriptors on the data and address `EFAULT` returns as well, through the same helper as the short-buffer path, which matches `kern_recvit`'s `out:` disposal on any error. A new `guest_socket_rights` case passes two pipe ends and receives into a read-only data buffer. It requires `EFAULT` and an unchanged `/proc/self/fd` count, aborts with the previous `Udp.cpp`, and passes with the fix; the 12 `guest_socket_*` tests pass 3 of 3. On the two cmsgs: Linux merges them into one `SCM_RIGHTS` record on the receiving side, so keeping FreeBSD's one record per message would need bookkeeping of our own. As you suggested, the debt entry now records it: several `SCM_RIGHTS` messages in one `sendmsg` arrive as one record, so a buffer with room for only the first record can't receive it alone. AI-assisted: yes (Claude Code)
wachi35676 commented 2026-10-20 02:55:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T02:55:55Z.


Re-checked head 516263f8f merged onto current main a020d0256 (clean merge).

Linux (WSL Ubuntu 24.04, GCC 13.3, Release, BUILD_TESTING=ON):

  • guest_socket_* (14 tests) pass 3/3.
  • Negative control: with only the Udp.cpp hunks of 516263f8f reverted, guest_socket_rights aborts (the new faulted-receive case) and the other 13 pass. Restored, 14/14 pass.

Probe (same as last time; it counts /proc/self/fd around the receive):

one record, 2 fds (24 bytes), capacity 16: controlLength=0  MSG_CTRUNC=1 reported=0 fds after-before=0
one record, 2 fds (24 bytes), capacity 20: controlLength=0  MSG_CTRUNC=1 reported=0 fds after-before=0
one record, 2 fds (24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2
one record, 2 fds (24 bytes), capacity 32: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2
two records, 1 fd each (2x24 bytes), capacity 16: controlLength=0  MSG_CTRUNC=1 reported=0 fds after-before=0
two records, 1 fd each (2x24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2
two records, 1 fd each (2x24 bytes), capacity 48: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2
read-only control buffer, capacity 32: result=-1 errno=14 fds after-before=0
read-only data buffer, control capacity 32: result=-1 errno=14 fds after-before=0
  • The data-copy fault no longer leaks. A read-only data buffer still returns EFAULT, and no descriptors are left open (it was +2 on 223a7c147). The short-buffer and read-only-control rows are the same as before.
  • The debt entry now says that several SCM_RIGHTS messages arrive as one record, so a buffer with room for only the first record can't receive it alone. That matches what the probe measures.
  • check_conventions.py --base origin/main passes.

Windows (WinLibs GCC 15.2.0, Release): Udp.cpp and libkernel build on the same merge. guest_socket_rights is Linux only, so it doesn't run here.

Nothing further from me on this PR.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6282257239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6282257239). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T02:55:55Z. --- Re-checked head 516263f8f merged onto current `main` a020d0256 (clean merge). **Linux** (WSL Ubuntu 24.04, GCC 13.3, Release, `BUILD_TESTING=ON`): - `guest_socket_*` (14 tests) pass 3/3. - Negative control: with only the `Udp.cpp` hunks of 516263f8f reverted, `guest_socket_rights` aborts (the new faulted-receive case) and the other 13 pass. Restored, 14/14 pass. **Probe** (same as last time; it counts `/proc/self/fd` around the receive): ``` one record, 2 fds (24 bytes), capacity 16: controlLength=0 MSG_CTRUNC=1 reported=0 fds after-before=0 one record, 2 fds (24 bytes), capacity 20: controlLength=0 MSG_CTRUNC=1 reported=0 fds after-before=0 one record, 2 fds (24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2 one record, 2 fds (24 bytes), capacity 32: controlLength=24 MSG_CTRUNC=0 reported=2 fds after-before=2 two records, 1 fd each (2x24 bytes), capacity 16: controlLength=0 MSG_CTRUNC=1 reported=0 fds after-before=0 two records, 1 fd each (2x24 bytes), capacity 24: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2 two records, 1 fd each (2x24 bytes), capacity 48: controlLength=24 MSG_CTRUNC=0 record{cmsg_len=24 fds=2} fds after-before=2 read-only control buffer, capacity 32: result=-1 errno=14 fds after-before=0 read-only data buffer, control capacity 32: result=-1 errno=14 fds after-before=0 ``` - The data-copy fault no longer leaks. A read-only data buffer still returns `EFAULT`, and no descriptors are left open (it was +2 on 223a7c147). The short-buffer and read-only-control rows are the same as before. - The debt entry now says that several `SCM_RIGHTS` messages arrive as one record, so a buffer with room for only the first record can't receive it alone. That matches what the probe measures. - `check_conventions.py --base origin/main` passes. **Windows** (WinLibs GCC 15.2.0, Release): `Udp.cpp` and `libkernel` build on the same merge. `guest_socket_rights` is Linux only, so it doesn't run here. Nothing further from me on this PR. AI-assisted: yes (Claude Code); results above were run on this machine.
milescoviello commented 2026-10-20 03:01:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T03:01:47Z.


@wachi35676 thanks for the re-check and for the probe across all the buffer cases. I added your run to Tested.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6282326480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6282326480). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-20T03:01:47Z. --- @wachi35676 thanks for the re-check and for the probe across all the buffer cases. I added your run to Tested. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-20 03:56:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T03:56:59Z.


Rebased onto main 525e299fc0 (now 766b697384). The only conflict was in docs/dev/debt/libkernel.md, next to main's new MSG_DONTWAIT entry, which on Windows now polls with WSAPoll first. I kept that text as main has it, and the SCM_RIGHTS entry is unchanged. Udp.cpp merged on its own with main's changes. The 14 guest_socket_* tests pass 3 of 3, and ctest -R '^guest_|libc' passes 482 of 483. The one failure, guest_module_directories (a relinker test), fails the same way on main here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6283017900 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6283017900). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-20T03:56:59Z. --- Rebased onto `main` 525e299fc0 (now 766b697384). The only conflict was in `docs/dev/debt/libkernel.md`, next to `main`'s new `MSG_DONTWAIT` entry, which on Windows now polls with `WSAPoll` first. I kept that text as `main` has it, and the `SCM_RIGHTS` entry is unchanged. `Udp.cpp` merged on its own with `main`'s changes. The 14 `guest_socket_*` tests pass 3 of 3, and `ctest -R '^guest_|libc'` passes 482 of 483. The one failure, `guest_module_directories` (a relinker test), fails the same way on `main` here. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-21 18:04:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T18:04:47Z.


Rebased onto main 606297f34f (now 3e9a4ad967). #8474 had changed NativeReceiveFlags to take the socket type for MSG_WAITALL, and added a debt entry next to this PR's. Both recvmsg paths here now pass socket->type, and both debt entries are kept. On that base the 26 guest_socket_*, net_* and guest_sce_net* tests pass 3 of 3, except the three net_dontwait_blocking_* tests, which fail on main on this host as well (#8917, #8918).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323008195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6323008195). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T18:04:47Z. --- Rebased onto `main` 606297f34f (now `3e9a4ad967`). #8474 had changed `NativeReceiveFlags` to take the socket type for `MSG_WAITALL`, and added a debt entry next to this PR's. Both `recvmsg` paths here now pass `socket->type`, and both debt entries are kept. On that base the 26 `guest_socket_*`, `net_*` and `guest_sce_net*` tests pass 3 of 3, except the three `net_dontwait_blocking_*` tests, which fail on `main` on this host as well (#8917, #8918). AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-21 18:45:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T18:45:54Z.


Rebased again onto main eaff87674c (now 1142d3a6bc), past #8492 and #8663. Only the debt file conflicted: #8492 added its zero-length receive entry next to this one, and both are kept. The 26 socket and net tests give the same result as before, 3 of 3: all pass except the three net_dontwait_blocking_* (#8917, #8918). This time the tree was built with GCC 15.2.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323822279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6323822279). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-21T18:45:54Z. --- Rebased again onto `main` eaff87674c (now `1142d3a6bc`), past #8492 and #8663. Only the debt file conflicted: #8492 added its zero-length receive entry next to this one, and both are kept. The 26 socket and net tests give the same result as before, 3 of 3: all pass except the three `net_dontwait_blocking_*` (#8917, #8918). This time the tree was built with GCC 15.2. AI-assisted: yes (Claude Code)
XairRrR commented 2026-10-29 04:12:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T04:12:04Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The SCM_RIGHTS transport, the receive-side ownership and the truncation and fault paths work in my runs, but sendmsg reports success for two inputs whose descriptors do not arrive intact: libkernel's emulated descriptors (kqueue, /dev/urandom) and a zero-byte send on a stream socket.

What I ran

  • PR head: 1db8d77c9afda0f719e2b4467cdc131843c95edd
  • main: b433c40f2f46aa2e59e19806010a839ac8572d64
  • Merged with git merge --no-ff in a clean worktree (no conflicts). Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF.
git diff --check origin/main...refs/review/7090
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs guest_socket_rights_tests guest_socket_pair_tests guest_udp_tests guest_tcp_tests \
    guest_socket_read_write_tests guest_socket_descriptors_tests guest_socket_on_non_socket_tests guest_socket_descriptor_flags_tests
ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \
    -R '^(guest_socket_rights|guest_socket_pair|guest_recvmsg_memory|guest_udp|guest_tcp|guest_socket_read_write|guest_socket_descriptors|guest_socket_on_non_socket|guest_socket_descriptor_flags)$'
# negative control
git checkout origin/main -- core/libs/prx/libkernel/Socket/src/Udp.cpp
cmake --build build -j10 --target guest_socket_rights_tests
ctest --test-dir build --output-on-failure -R '^guest_socket_rights$'
# probe: a temporary main() in GuestSocketRights.cpp (reverted afterwards), see Findings

Results

Check Result
Merge onto main clean
git diff --check clean
check_conventions.py All conventions checks passed.
Build (libs and the 8 socket test targets) passes
9 socket tests, 3 repeats 9 of 9 pass each time; guest_socket_rights takes 0.01 s
Negative control guest_socket_rights aborts
Probe: emulated descriptors and a zero-byte stream send the 3 cases below go wrong
Probe output on the merged tree
PROBE urandom: fd=9 direct read=8 sent=3 received=3 fd=10 read=0
PROBE kqueue: fd=11 kevent=0 sent=2 errno=0 received=2 controlLength=24 fd=12 kevent=-1 errno=9
PROBE zero-byte stream: sent=0 plain=1 received=1 controlLength=0 flags=0x0

Negative control

I restored only core/libs/prx/libkernel/Socket/src/Udp.cpp from main and kept the new test. guest_socket_rights aborts with terminate called after throwing an instance of 'std::runtime_error' / what(): sendmsg: control data is not supported. With the PR's Udp.cpp back, it passes.

Findings

Line numbers in Udp.cpp are at the PR head. The other libkernel files are linked at main.

Blocking

  1. sendmsg passes libkernel's placeholder descriptors as if they were the real ones. The description says "a guest descriptor here is a host descriptor", but that doesn't hold for every descriptor. A guest kqueue is a /dev/null placeholder plus an entry in g_kqueues (Kqueue.cpp L86-L92, L561-L572). A guest /dev/urandom is a /dev/null placeholder that libkernel fills on read (RandomDevice.cpp L28-L38). PassedDescriptors checks only that the host descriptor is open and that it isn't an archived file, so the placeholder is sent. The probe shows the result:

    • kqueue: sendmsg returns 2. The received descriptor fails kevent with EBADF, though the original returns 0. FreeBSD 11.4 refuses the send instead: unp_internalize returns EOPNOTSUPP for a file without DFLAG_PASSABLE (uipc_usrreq.c L2004-L2011), and kqueueops sets no fo_flags (kern_event.c L122-L135).
    • /dev/urandom (opened with sceKernelOpen): reading the original gives 8 bytes, but reading the received descriptor gives 0, an end of file.

    Both calls succeed and hand the receiver something else. CONTRIBUTING.md asks that "every function either does exactly what it is supposed to or throws". Suggested fix: in PassedDescriptors, return 45 (EOPNOTSUPP) for a kqueue descriptor, as FreeBSD does. Every other descriptor whose behaviour lives in a libkernel table (random device, and any other placeholder) should throw through NotImplemented_nid_no_patch, as RefuseArchivedFile already does for archived files. Name them in the debt entry, and add a guest_socket_rights case for the kqueue EOPNOTSUPP.

  2. A zero-byte sendmsg with SCM_RIGHTS on a stream socket returns 0 and drops the descriptors. SendPassing hands an empty iovec to the host sendmsg. Linux doesn't carry ancillary data on a SOCK_STREAM Unix socket without at least one data byte. In the probe the call returns 0, and the receive after a later one-byte plain send gets controlLength 0 and no MSG_CTRUNC, so the descriptor is gone and neither side is told. FreeBSD 11.4 delivers control-only sends: sosend_generic builds "a single empty mbuf" when "resid is 0, which can happen only if we have control to send" and calls pru_send with it (uipc_socket.c L1325-L1331). Suggested fix: when the socket is a stream, descriptors is not empty and data is empty, throw through NotImplemented_nid_no_patch and add the case to the debt entry, until there is a way to carry the record. Datagram and seqpacket sockets aren't affected.

Non-blocking

  1. @lgqdaxia reported that guest getpeername returns ENOTCONN on a received connected Unix socket. The debt entry at docs/dev/debt/libkernel.md:239 (PR head) mentions only default emulated socket options. I did not reproduce this. If it holds, one more sentence in that entry would cover it.

Not verified

  • macOS and Windows builds; I relied on the earlier reports in this thread for those.
  • The full test suite, and the other ^guest_|libc tests outside the 9 listed.
  • Any title: no game or homebrew was launched.
  • Whether RefuseArchivedFile also catches the /dev/null placeholder that DirectoryDescriptor.cpp opens for an archived directory.

To get this to a good state

  • Refuse emulated descriptors in PassedDescriptors: EOPNOTSUPP for kqueue, NotImplemented_nid_no_patch for the others. Add a test and a debt line.
  • Throw on a zero-byte stream sendmsg that carries descriptors, and list it in the debt entry.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692766296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#pullrequestreview-5692766296). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T04:12:04Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The `SCM_RIGHTS` transport, the receive-side ownership and the truncation and fault paths work in my runs, but `sendmsg` reports success for two inputs whose descriptors do not arrive intact: libkernel's emulated descriptors (kqueue, `/dev/urandom`) and a zero-byte send on a stream socket. ## What I ran - PR head: `1db8d77c9afda0f719e2b4467cdc131843c95edd` - `main`: `b433c40f2f46aa2e59e19806010a839ac8572d64` - Merged with `git merge --no-ff` in a clean worktree (no conflicts). Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF. ``` git diff --check origin/main...refs/review/7090 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs guest_socket_rights_tests guest_socket_pair_tests guest_udp_tests guest_tcp_tests \ guest_socket_read_write_tests guest_socket_descriptors_tests guest_socket_on_non_socket_tests guest_socket_descriptor_flags_tests ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \ -R '^(guest_socket_rights|guest_socket_pair|guest_recvmsg_memory|guest_udp|guest_tcp|guest_socket_read_write|guest_socket_descriptors|guest_socket_on_non_socket|guest_socket_descriptor_flags)$' # negative control git checkout origin/main -- core/libs/prx/libkernel/Socket/src/Udp.cpp cmake --build build -j10 --target guest_socket_rights_tests ctest --test-dir build --output-on-failure -R '^guest_socket_rights$' # probe: a temporary main() in GuestSocketRights.cpp (reverted afterwards), see Findings ``` ## Results | Check | Result | |---|---| | Merge onto `main` | clean | | `git diff --check` | clean | | `check_conventions.py` | `All conventions checks passed.` | | Build (`libs` and the 8 socket test targets) | passes | | 9 socket tests, 3 repeats | 9 of 9 pass each time; `guest_socket_rights` takes 0.01 s | | Negative control | `guest_socket_rights` aborts | | Probe: emulated descriptors and a zero-byte stream send | the 3 cases below go wrong | <details><summary>Probe output on the merged tree</summary> ``` PROBE urandom: fd=9 direct read=8 sent=3 received=3 fd=10 read=0 PROBE kqueue: fd=11 kevent=0 sent=2 errno=0 received=2 controlLength=24 fd=12 kevent=-1 errno=9 PROBE zero-byte stream: sent=0 plain=1 received=1 controlLength=0 flags=0x0 ``` </details> ## Negative control I restored only `core/libs/prx/libkernel/Socket/src/Udp.cpp` from `main` and kept the new test. `guest_socket_rights` aborts with `terminate called after throwing an instance of 'std::runtime_error'` / `what(): sendmsg: control data is not supported`. With the PR's `Udp.cpp` back, it passes. ## Findings Line numbers in `Udp.cpp` are at the PR head. The other libkernel files are linked at `main`. ### Blocking 1. **`sendmsg` passes libkernel's placeholder descriptors as if they were the real ones.** The description says "a guest descriptor here is a host descriptor", but that doesn't hold for every descriptor. A guest kqueue is a `/dev/null` placeholder plus an entry in `g_kqueues` ([`Kqueue.cpp` L86-L92](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L86-L92), [L561-L572](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L561-L572)). A guest `/dev/urandom` is a `/dev/null` placeholder that libkernel fills on read ([`RandomDevice.cpp` L28-L38](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/core/libs/prx/libkernel/File/src/RandomDevice.cpp#L28-L38)). [`PassedDescriptors`](https://github.com/boykopovar/AnyPS5/blob/1db8d77c9afda0f719e2b4467cdc131843c95edd/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1612-L1613) checks only that the host descriptor is open and that it isn't an archived file, so the placeholder is sent. The probe shows the result: - **kqueue:** `sendmsg` returns 2. The received descriptor fails `kevent` with `EBADF`, though the original returns 0. FreeBSD 11.4 refuses the send instead: `unp_internalize` returns `EOPNOTSUPP` for a file without `DFLAG_PASSABLE` ([`uipc_usrreq.c` L2004-L2011](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_usrreq.c#L2004-L2011)), and `kqueueops` sets no `fo_flags` ([`kern_event.c` L122-L135](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_event.c#L122-L135)). - **`/dev/urandom` (opened with `sceKernelOpen`):** reading the original gives 8 bytes, but reading the received descriptor gives 0, an end of file. Both calls succeed and hand the receiver something else. CONTRIBUTING.md asks that "every function either does exactly what it is supposed to or throws". Suggested fix: in `PassedDescriptors`, return 45 (`EOPNOTSUPP`) for a kqueue descriptor, as FreeBSD does. Every other descriptor whose behaviour lives in a libkernel table (random device, and any other placeholder) should throw through `NotImplemented_nid_no_patch`, as `RefuseArchivedFile` already does for archived files. Name them in the debt entry, and add a `guest_socket_rights` case for the kqueue `EOPNOTSUPP`. 2. **A zero-byte `sendmsg` with `SCM_RIGHTS` on a stream socket returns 0 and drops the descriptors.** [`SendPassing`](https://github.com/boykopovar/AnyPS5/blob/1db8d77c9afda0f719e2b4467cdc131843c95edd/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1623-L1644) hands an empty iovec to the host `sendmsg`. Linux doesn't carry ancillary data on a `SOCK_STREAM` Unix socket without at least one data byte. In the probe the call returns 0, and the receive after a later one-byte plain send gets `controlLength` 0 and no `MSG_CTRUNC`, so the descriptor is gone and neither side is told. FreeBSD 11.4 delivers control-only sends: `sosend_generic` builds "a single empty mbuf" when "resid is 0, which can happen only if we have control to send" and calls `pru_send` with it ([`uipc_socket.c` L1325-L1331](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c#L1325-L1331)). Suggested fix: when the socket is a stream, `descriptors` is not empty and `data` is empty, throw through `NotImplemented_nid_no_patch` and add the case to the debt entry, until there is a way to carry the record. Datagram and seqpacket sockets aren't affected. ### Non-blocking 1. @lgqdaxia [reported](https://github.com/boykopovar/AnyPS5/pull/7090#issuecomment-6403976075) that guest `getpeername` returns `ENOTCONN` on a received connected Unix socket. The debt entry at `docs/dev/debt/libkernel.md:239` (PR head) mentions only default emulated socket options. I did not reproduce this. If it holds, one more sentence in that entry would cover it. ## Not verified - macOS and Windows builds; I relied on the earlier reports in this thread for those. - The full test suite, and the other `^guest_|libc` tests outside the 9 listed. - Any title: no game or homebrew was launched. - Whether `RefuseArchivedFile` also catches the `/dev/null` placeholder that `DirectoryDescriptor.cpp` opens for an archived directory. ## To get this to a good state - Refuse emulated descriptors in `PassedDescriptors`: `EOPNOTSUPP` for kqueue, `NotImplemented_nid_no_patch` for the others. Add a test and a debt line. - Throw on a zero-byte stream `sendmsg` that carries descriptors, and list it in the debt entry.
XairRrR commented 2026-10-29 05:23:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T05:23:45Z.

Review: CHANGES_REQUESTED


Re-checked — changes still requested

b9e987b82e fixes both earlier blockers: a kqueue now gets EOPNOTSUPP, and a random device, a directory or a zero-byte stream send now throws. But the head no longer compiles on current main, and a JIT shared-memory descriptor is still passed as if it were complete.

What changed since my last review

  • One commit, b9e987b82e. It adds the kqueue, random-device and directory checks to PassedDescriptors and the zero-byte stream check to SendPassing, adds a CheckRefusedKqueue case to guest_socket_rights, and rewrites the debt entry.
  • The author replied in the thread, and the description now has a "Refused descriptors" item and a new top Tested line.
  • The progress bot now counts sendmsg_nid_postfix as a stub. That is how tools/progress.py works: sendmsg reaches a helper that calls NotImplemented_nid_no_patch, so it counts. It is expected and not a problem.

What I ran

  • PR head: b9e987b82e177fbd8d4da475806e0a0d56199f2c
  • main: 52c09d567d2fa453494dd720fcf53a98149468e4
  • I merged with git merge --no-ff in a clean worktree. Git reported no textual conflict. Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF.
git diff --check origin/main...refs/review/7090
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs guest_socket_rights_tests guest_socket_pair_tests guest_udp_tests guest_tcp_tests \
    guest_socket_read_write_tests guest_socket_descriptors_tests guest_socket_on_non_socket_tests guest_socket_descriptor_flags_tests
# fails; then, locally only, renamed the call at Udp.cpp:1627 (merged tree) to IsKqueueDescriptor_nid_no_patch and rebuilt
ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \
    -R '^(guest_socket_rights|guest_socket_pair|guest_recvmsg_memory|guest_udp|guest_tcp|guest_socket_read_write|guest_socket_descriptors|guest_socket_on_non_socket|guest_socket_descriptor_flags)$'
# negative control: deleted only the `IsKqueueDescriptor_nid_no_patch(passed)) return 45;` line
cmake --build build -j10 --target guest_socket_rights_tests
ctest --test-dir build --output-on-failure -R '^guest_socket_rights$'
# probe: a temporary main() in GuestSocketRights.cpp (reverted afterwards)
Check Result
Textual merge onto main clean
git diff --check clean
check_conventions.py All conventions checks passed.
Build of the merged tree fails: Udp.cpp:1627: error: 'IsKqueueDescriptor' was not declared in this scope (GCC's message, translated from the host locale)
9 socket tests, 3 repeats (with the local rename) 9 of 9 pass each time
Negative control (kqueue check removed) guest_socket_rights aborts (Subprocess aborted)
Probe see below
Probe output on the merged tree (with the local rename)
PROBE jit: create=0 fd=10 map(original)=0 sent=1 received=1 controlLength=24 fd=11 map(received)=0x80020009
PROBE urandom: threw: sendmsg: passing a random device descriptor, whose state is libkernel's, fd=12 not implemented
PROBE zero-byte stream: threw: sendmsg: SCM_RIGHTS without data on a stream socket not implemented
PROBE zero-byte datagram: sent=0 received=0 controlLength=24

Previous findings

  1. Blocking 1 (placeholder descriptors): resolved for the descriptors it named. The new test and my negative control cover the kqueue EOPNOTSUPP. In the probe, /dev/urandom opened with sceKernelOpen now throws. The archived-directory /dev/null placeholder is in g_directories (OpenDirectoryDescriptor registers the descriptor that OpenPlaceholder returns), so IsDirectoryDescriptor covers it too. That closes the item I listed under "Not verified" last time. The JIT table is the same kind of problem, under New findings.
  2. Blocking 2 (zero-byte stream send): resolved. In the probe it throws. A zero-byte datagram send still delivers its 24-byte record.
  3. Non-blocking (getpeername on a received socket): still open, unverified. Neither of us reproduced it, so leaving the entry as it is seems fine.

New findings

Blocking

  1. The head does not compile on current main. #11296, merged on 2026-10-28, renamed IsKqueueDescriptor to IsKqueueDescriptor_nid_no_patch (commit f87b6289ac). The new check at Udp.cpp L1614 still uses the old name. Git merges the files without a textual conflict, but libkernel then fails to build. The branch's merge base f759e165d9 is older than the rename, which is why it built for the author. Fix: merge or rebase onto current main and call IsKqueueDescriptor_nid_no_patch(passed). With that one-line rename, everything above passes.

  2. A JIT shared-memory descriptor is still sent as if it were complete. sceKernelJitCreateSharedMemory returns a real host memfd, but its size object and maximum protection live in libkernel's g_jitDescriptors. sceKernelJitMapSharedMemory returns EBADF for any descriptor that is not in that table. dup copies the entry (Stdio.cpp L862), but the receive side of SCM_RIGHTS does not. In the probe, sendmsg returns 1 and the record arrives. Mapping the original descriptor returns 0, but mapping the received one returns 0x80020009 (SCE_KERNEL_ERROR_EBADF). Handing JIT memory to another party is the main reason to send this descriptor over a socket, and the call succeeds while giving the receiver a descriptor it cannot map. Under CONTRIBUTING.md's "does exactly what it is supposed to or throws", that should throw. Suggested fix: export a predicate from Jit.cpp (as IsRandomDevice is exported), throw for it in PassedDescriptors next to the random-device and directory check, and add "JIT shared memory" to the debt entry at docs/dev/debt/libkernel.md:239. The alternative is to register the received descriptor under the sender's entry.

Non-blocking

None.

Not verified

  • macOS and Windows builds of this head.
  • Tests outside the 9 socket tests listed. I ran no title.
  • Whether other libkernel-only state is lost on a received descriptor (for example, emulated-only status flags in DescriptorControl.cpp). I found nothing else in a table that sendmsg hands over on Linux. The SharedMemory.cpp access table is Windows-only, and SCM_RIGHTS throws on Windows.

To get this to a good state

  • Bring the branch up to current main and rename the call to IsKqueueDescriptor_nid_no_patch.
  • Refuse JIT shared-memory descriptors in PassedDescriptors, or register them on receive, and list the case in the debt entry.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693232139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#pullrequestreview-5693232139). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T05:23:45Z. **Review:** CHANGES_REQUESTED --- # Re-checked — changes still requested `b9e987b82e` fixes both earlier blockers: a kqueue now gets `EOPNOTSUPP`, and a random device, a directory or a zero-byte stream send now throws. But the head no longer compiles on current `main`, and a JIT shared-memory descriptor is still passed as if it were complete. ## What changed since my last review - One commit, `b9e987b82e`. It adds the kqueue, random-device and directory checks to `PassedDescriptors` and the zero-byte stream check to `SendPassing`, adds a `CheckRefusedKqueue` case to `guest_socket_rights`, and rewrites the debt entry. - The author replied in the thread, and the description now has a "Refused descriptors" item and a new top `Tested` line. - The progress bot now counts `sendmsg_nid_postfix` as a stub. That is how `tools/progress.py` works: `sendmsg` reaches a helper that calls `NotImplemented_nid_no_patch`, so it counts. It is expected and not a problem. ## What I ran - PR head: `b9e987b82e177fbd8d4da475806e0a0d56199f2c` - `main`: `52c09d567d2fa453494dd720fcf53a98149468e4` - I merged with `git merge --no-ff` in a clean worktree. Git reported no textual conflict. Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF. ``` git diff --check origin/main...refs/review/7090 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs guest_socket_rights_tests guest_socket_pair_tests guest_udp_tests guest_tcp_tests \ guest_socket_read_write_tests guest_socket_descriptors_tests guest_socket_on_non_socket_tests guest_socket_descriptor_flags_tests # fails; then, locally only, renamed the call at Udp.cpp:1627 (merged tree) to IsKqueueDescriptor_nid_no_patch and rebuilt ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \ -R '^(guest_socket_rights|guest_socket_pair|guest_recvmsg_memory|guest_udp|guest_tcp|guest_socket_read_write|guest_socket_descriptors|guest_socket_on_non_socket|guest_socket_descriptor_flags)$' # negative control: deleted only the `IsKqueueDescriptor_nid_no_patch(passed)) return 45;` line cmake --build build -j10 --target guest_socket_rights_tests ctest --test-dir build --output-on-failure -R '^guest_socket_rights$' # probe: a temporary main() in GuestSocketRights.cpp (reverted afterwards) ``` | Check | Result | |---|---| | Textual merge onto `main` | clean | | `git diff --check` | clean | | `check_conventions.py` | `All conventions checks passed.` | | Build of the merged tree | **fails**: `Udp.cpp:1627: error: 'IsKqueueDescriptor' was not declared in this scope` (GCC's message, translated from the host locale) | | 9 socket tests, 3 repeats (with the local rename) | 9 of 9 pass each time | | Negative control (kqueue check removed) | `guest_socket_rights` aborts (`Subprocess aborted`) | | Probe | see below | <details><summary>Probe output on the merged tree (with the local rename)</summary> ``` PROBE jit: create=0 fd=10 map(original)=0 sent=1 received=1 controlLength=24 fd=11 map(received)=0x80020009 PROBE urandom: threw: sendmsg: passing a random device descriptor, whose state is libkernel's, fd=12 not implemented PROBE zero-byte stream: threw: sendmsg: SCM_RIGHTS without data on a stream socket not implemented PROBE zero-byte datagram: sent=0 received=0 controlLength=24 ``` </details> ## Previous findings 1. **Blocking 1 (placeholder descriptors): resolved** for the descriptors it named. The new test and my negative control cover the kqueue `EOPNOTSUPP`. In the probe, `/dev/urandom` opened with `sceKernelOpen` now throws. The archived-directory `/dev/null` placeholder is in `g_directories` (`OpenDirectoryDescriptor` registers the descriptor that `OpenPlaceholder` returns), so `IsDirectoryDescriptor` covers it too. That closes the item I listed under "Not verified" last time. The JIT table is the same kind of problem, under New findings. 2. **Blocking 2 (zero-byte stream send): resolved.** In the probe it throws. A zero-byte datagram send still delivers its 24-byte record. 3. **Non-blocking (`getpeername` on a received socket): still open, unverified.** Neither of us reproduced it, so leaving the entry as it is seems fine. ## New findings ### Blocking 1. **The head does not compile on current `main`.** #11296, merged on 2026-10-28, renamed `IsKqueueDescriptor` to [`IsKqueueDescriptor_nid_no_patch`](https://github.com/boykopovar/AnyPS5/blob/52c09d567d2fa453494dd720fcf53a98149468e4/core/libs/prx/libkernel/Equeue/Equeue.hpp#L134-L134) (commit `f87b6289ac`). The new check at [`Udp.cpp` L1614](https://github.com/boykopovar/AnyPS5/blob/b9e987b82e177fbd8d4da475806e0a0d56199f2c/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1614-L1614) still uses the old name. Git merges the files without a textual conflict, but `libkernel` then fails to build. The branch's merge base `f759e165d9` is older than the rename, which is why it built for the author. Fix: merge or rebase onto current `main` and call `IsKqueueDescriptor_nid_no_patch(passed)`. With that one-line rename, everything above passes. 2. **A JIT shared-memory descriptor is still sent as if it were complete.** `sceKernelJitCreateSharedMemory` returns a real host memfd, but its size object and maximum protection live in libkernel's [`g_jitDescriptors`](https://github.com/boykopovar/AnyPS5/blob/52c09d567d2fa453494dd720fcf53a98149468e4/core/libs/prx/libkernel/DirectMemory/Jit.cpp#L97-L103). [`sceKernelJitMapSharedMemory`](https://github.com/boykopovar/AnyPS5/blob/52c09d567d2fa453494dd720fcf53a98149468e4/core/libs/prx/libkernel/DirectMemory/Jit.cpp#L217-L221) returns `EBADF` for any descriptor that is not in that table. `dup` copies the entry ([`Stdio.cpp` L862](https://github.com/boykopovar/AnyPS5/blob/52c09d567d2fa453494dd720fcf53a98149468e4/core/libs/prx/libkernel/File/src/Stdio.cpp#L862-L862)), but the receive side of `SCM_RIGHTS` does not. In the probe, `sendmsg` returns 1 and the record arrives. Mapping the original descriptor returns 0, but mapping the received one returns `0x80020009` (`SCE_KERNEL_ERROR_EBADF`). Handing JIT memory to another party is the main reason to send this descriptor over a socket, and the call succeeds while giving the receiver a descriptor it cannot map. Under CONTRIBUTING.md's "does exactly what it is supposed to or throws", that should throw. Suggested fix: export a predicate from `Jit.cpp` (as `IsRandomDevice` is exported), throw for it in `PassedDescriptors` next to the random-device and directory check, and add "JIT shared memory" to the debt entry at `docs/dev/debt/libkernel.md:239`. The alternative is to register the received descriptor under the sender's entry. ### Non-blocking None. ## Not verified - macOS and Windows builds of this head. - Tests outside the 9 socket tests listed. I ran no title. - Whether other libkernel-only state is lost on a received descriptor (for example, emulated-only status flags in `DescriptorControl.cpp`). I found nothing else in a table that `sendmsg` hands over on Linux. The `SharedMemory.cpp` access table is Windows-only, and `SCM_RIGHTS` throws on Windows. ## To get this to a good state - Bring the branch up to current `main` and rename the call to `IsKqueueDescriptor_nid_no_patch`. - Refuse JIT shared-memory descriptors in `PassedDescriptors`, or register them on receive, and list the case in the debt entry.
XairRrR commented 2026-10-29 06:12:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T06:12:28Z.

Review: APPROVED


Re-checked — approved

1e19b327f7 merges current main, renames the kqueue call to IsKqueueDescriptor_nid_no_patch, and refuses JIT shared-memory descriptors in sendmsg. Both of my earlier blockers are fixed, and the merged tree builds and passes the socket and JIT tests.

What changed since my last review

  • 9409deaa87: merge of main 52c09d567d into the branch. Git reported no conflicts, and it brings in #11296's rename.
  • 1e19b327f7: adds IsJitSharedMemory (a lookup in g_jitDescriptors under g_jitLock), throws for it in PassedDescriptors next to the random-device and directory cases, calls IsKqueueDescriptor_nid_no_patch, and adds JIT shared memory to the debt entry at docs/dev/debt/libkernel.md:242.
  • The author replied in the thread, and the description has a new top Tested line.

What I ran

  • PR head: 1e19b327f7f0262d5e3c4df150ec3f04b9adad2d
  • main: 2960e9a6e7e1fc99c4ed180c71495b5eb83464c7
  • I merged with git merge --no-ff in a clean worktree. Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF.
git diff --check origin/main...refs/review/7090
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs <the 17 test executables behind the 19 tests below>
ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \
    -R '^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp|^guest_jit'
# probe: a temporary main() in GuestSocketRights.cpp (reverted afterwards)
# guest_socket_options_multicast on origin/main, same worktree
cmake --build build -j10 --target guest_socket_options_tests
ctest --test-dir build --output-on-failure -R '^guest_socket_options_multicast$'
Check Result
Merge onto main clean
git diff --check clean
check_conventions.py All conventions checks passed.
Build of libs and the tests succeeds
19 tests, ^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp|^guest_jit 18 pass; guest_socket_options_multicast aborts (joining 224.0.0.251 through INADDR_ANY failed (errno 5)) and fails the same way on main. My test environment has no network, so this is not caused by the PR
Probe see below
Probe output on the merged tree
PROBE jit: threw: sendmsg: passing a JIT shared memory descriptor, whose state is libkernel's, fd=9 not implemented
PROBE jit: next received=4 controlLength=0
PROBE alias: threw: sendmsg: passing a JIT shared memory descriptor, whose state is libkernel's, fd=10 not implemented
PROBE alias: next received=4 controlLength=0
PROBE dup: threw: sendmsg: passing a JIT shared memory descriptor, whose state is libkernel's, fd=11 not implemented
PROBE dup: next received=4 controlLength=0
PROBE pipe-after-jit-closed: sent=1
PROBE pipe-after-jit-closed: received=1 controlLength=24
PROBE pipe-after-jit-closed: next received=4 controlLength=0

jit comes from sceKernelJitCreateSharedMemory, alias from sceKernelJitCreateAliasOfSharedMemory and dup from dup. After each refusal, nothing is queued on the pair: the next plain send arrives without control data. A pipe end sent after the JIT descriptor is closed still goes through.

Negative control

None. This push adds no test and changes none. The probe above covers the new refusal instead.

Previous findings

  1. Blocking 1 (does not compile on current main): resolved. The head calls IsKqueueDescriptor_nid_no_patch (Udp.cpp L1628). On main 2960e9a6e7, the merged tree builds libs and the tests without my local rename.
  2. Blocking 2 (JIT shared-memory descriptor passed as complete): resolved. The probe shows that a created, aliased or duplicated JIT descriptor now throws before anything is sent. Aliases and dup copies have their own entries in g_jitDescriptors, so the lookup covers them. Closing the descriptor removes its entry (ForgetJitSharedMemory in Stdio.cpp and Open.cpp), so a later descriptor that reuses the number is not refused by mistake. The debt entry lists the case.
  3. Non-blocking (getpeername on a received socket): no change. Neither of us reproduced it, and the author left the entry as it is. That is fine.

New findings

Blocking

None.

Non-blocking

  1. The JIT refusal has no regression test. NotImplemented_nid_no_patch throws an exception that a test can catch. My probe shows this, and the random-device and directory refusals have no test either. A CheckRefusedJit case in guest_socket_rights would keep the check from disappearing quietly. It could catch the exception for a sceKernelJitCreateSharedMemory descriptor, then confirm that the next plain send arrives without control data. This is optional.
  2. A stray line in the description's Tested section. "Ubuntu 24.04, GCC 13.3, Release. The results below are from main 673f7406c5, except the rebase line." sits in the middle of the list, after the title-run item. It looks like a leftover from an earlier version of the description and no longer fits the items around it. Consider removing it.

Not verified

  • macOS and Windows builds of this head. IsJitSharedMemory is defined outside the platform blocks in Jit.cpp, so it should build everywhere, but I did not compile it there.
  • Tests outside the 19 listed. I ran no title.
  • guest_socket_options_multicast with a network. Its failure here matches main.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693588265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7090#pullrequestreview-5693588265). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T06:12:28Z. **Review:** APPROVED --- # Re-checked — approved `1e19b327f7` merges current `main`, renames the kqueue call to `IsKqueueDescriptor_nid_no_patch`, and refuses JIT shared-memory descriptors in `sendmsg`. Both of my earlier blockers are fixed, and the merged tree builds and passes the socket and JIT tests. ## What changed since my last review - `9409deaa87`: merge of `main` `52c09d567d` into the branch. Git reported no conflicts, and it brings in #11296's rename. - `1e19b327f7`: adds [`IsJitSharedMemory`](https://github.com/boykopovar/AnyPS5/blob/1e19b327f7f0262d5e3c4df150ec3f04b9adad2d/core/libs/prx/libkernel/DirectMemory/Jit.cpp#L183-L186) (a lookup in `g_jitDescriptors` under `g_jitLock`), throws for it in [`PassedDescriptors`](https://github.com/boykopovar/AnyPS5/blob/1e19b327f7f0262d5e3c4df150ec3f04b9adad2d/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1628-L1631) next to the random-device and directory cases, calls `IsKqueueDescriptor_nid_no_patch`, and adds JIT shared memory to the debt entry at `docs/dev/debt/libkernel.md:242`. - The author replied in the thread, and the description has a new top `Tested` line. ## What I ran - PR head: `1e19b327f7f0262d5e3c4df150ec3f04b9adad2d` - `main`: `2960e9a6e7e1fc99c4ed180c71495b5eb83464c7` - I merged with `git merge --no-ff` in a clean worktree. Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF. ``` git diff --check origin/main...refs/review/7090 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs <the 17 test executables behind the 19 tests below> ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \ -R '^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp|^guest_jit' # probe: a temporary main() in GuestSocketRights.cpp (reverted afterwards) # guest_socket_options_multicast on origin/main, same worktree cmake --build build -j10 --target guest_socket_options_tests ctest --test-dir build --output-on-failure -R '^guest_socket_options_multicast$' ``` | Check | Result | |---|---| | Merge onto `main` | clean | | `git diff --check` | clean | | `check_conventions.py` | `All conventions checks passed.` | | Build of `libs` and the tests | succeeds | | 19 tests, `^guest_socket\|^guest_recvmsg\|^guest_udp\|^guest_tcp\|^guest_jit` | 18 pass; `guest_socket_options_multicast` aborts (`joining 224.0.0.251 through INADDR_ANY failed (errno 5)`) and fails the same way on `main`. My test environment has no network, so this is not caused by the PR | | Probe | see below | <details><summary>Probe output on the merged tree</summary> ``` PROBE jit: threw: sendmsg: passing a JIT shared memory descriptor, whose state is libkernel's, fd=9 not implemented PROBE jit: next received=4 controlLength=0 PROBE alias: threw: sendmsg: passing a JIT shared memory descriptor, whose state is libkernel's, fd=10 not implemented PROBE alias: next received=4 controlLength=0 PROBE dup: threw: sendmsg: passing a JIT shared memory descriptor, whose state is libkernel's, fd=11 not implemented PROBE dup: next received=4 controlLength=0 PROBE pipe-after-jit-closed: sent=1 PROBE pipe-after-jit-closed: received=1 controlLength=24 PROBE pipe-after-jit-closed: next received=4 controlLength=0 ``` `jit` comes from `sceKernelJitCreateSharedMemory`, `alias` from `sceKernelJitCreateAliasOfSharedMemory` and `dup` from `dup`. After each refusal, nothing is queued on the pair: the next plain send arrives without control data. A pipe end sent after the JIT descriptor is closed still goes through. </details> ## Negative control None. This push adds no test and changes none. The probe above covers the new refusal instead. ## Previous findings 1. **Blocking 1 (does not compile on current `main`): resolved.** The head calls `IsKqueueDescriptor_nid_no_patch` ([`Udp.cpp` L1628](https://github.com/boykopovar/AnyPS5/blob/1e19b327f7f0262d5e3c4df150ec3f04b9adad2d/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1628-L1628)). On `main` `2960e9a6e7`, the merged tree builds `libs` and the tests without my local rename. 2. **Blocking 2 (JIT shared-memory descriptor passed as complete): resolved.** The probe shows that a created, aliased or duplicated JIT descriptor now throws before anything is sent. Aliases and `dup` copies have their own entries in `g_jitDescriptors`, so the lookup covers them. Closing the descriptor removes its entry (`ForgetJitSharedMemory` in `Stdio.cpp` and `Open.cpp`), so a later descriptor that reuses the number is not refused by mistake. The debt entry lists the case. 3. **Non-blocking (`getpeername` on a received socket): no change.** Neither of us reproduced it, and the author left the entry as it is. That is fine. ## New findings ### Blocking None. ### Non-blocking 1. **The JIT refusal has no regression test.** `NotImplemented_nid_no_patch` throws an exception that a test can catch. My probe shows this, and the random-device and directory refusals have no test either. A `CheckRefusedJit` case in `guest_socket_rights` would keep the check from disappearing quietly. It could catch the exception for a `sceKernelJitCreateSharedMemory` descriptor, then confirm that the next plain send arrives without control data. This is optional. 2. **A stray line in the description's `Tested` section.** "Ubuntu 24.04, GCC 13.3, Release. The results below are from `main` 673f7406c5, except the rebase line." sits in the middle of the list, after the title-run item. It looks like a leftover from an earlier version of the description and no longer fits the items around it. Consider removing it. ## Not verified - macOS and Windows builds of this head. `IsJitSharedMemory` is defined outside the platform blocks in `Jit.cpp`, so it should build everywhere, but I did not compile it there. - Tests outside the 19 listed. I ran no title. - `guest_socket_options_multicast` with a network. Its failure here matches `main`.
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!7090
No description provided.