Repository navigation
feat(libkernel): pass descriptors in SCM_RIGHTS messages on Unix sockets - #7090
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
b89d198 to
4cd70d4
Compare
|
This doesn't compile on Windows (head
AI-assisted: yes (Claude Code); results above were run on this machine. |
|
Thanks @wachi35676, that's right. 17d9e0a declares Checked here with MinGW-w64 ( AI-assisted: yes (Claude Code) |
|
Windows build of head
Titles: PPSA99030 is not available here. Not checked: the descriptor passing itself (Linux only, Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
|
Thanks @screamm for the full Windows build, the control and the probe. I added it to the description. AI-assisted: yes (Claude Code) |
jotitadev
left a comment
There was a problem hiding this comment.
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 noSO_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 ofSO_DOMAIN. On macOS this returnsAF_UNIXfor asocketpairend andAF_INET6for an unbound IPv6 socket, andSO_TYPEworks as it is. - Drop
MSG_CMSG_CLOEXECand setFD_CLOEXECwithfcntlon each received descriptor when the guest asked for it, beforeInstallPassed. Alternatively, guard the flag with#ifdef MSG_CMSG_CLOEXECand use thefcntlpath 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)
|
@jotitadev thanks, both are right. I took your first suggestion and the
I'm running AI-assisted: yes (Claude Code) |
|
@milescoviello thanks. M2 Max, macOS 27.2, Apple clang 21.0.0. Base: #7332 at
One gap in the test: it never checks close-on-exec on the received host descriptor. The only
So your forced-fallback run on Linux will pass whether or not the Not checked: your actual aff8c2a, 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. |
|
@jotitadev thanks, and sorry the commit wasn't up yet when you looked. Both are pushed now:
You're right that my forced-fallback run proved nothing before that check. With it, on Linux (Ubuntu 24.04, GCC 13.3):
A run of AI-assisted: yes (Claude Code) |
|
@milescoviello re-ran on the pushed head M2 Max, macOS 27.2, Apple clang 21.0.0. Base: #7332 at
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. |
|
@jotitadev thanks, that settles the macOS side. The mutation result is the useful part: it shows the new pipe check actually exercises the About the AI-assisted: yes (Claude Code) |
a3b3801 to
5f492d3
Compare
|
Rebased onto AI-assisted: yes (Claude Code) |
|
Re-run of head 5f492d3 merged onto current Linux: WSL Ubuntu 24.04, GCC 13.3, Release,
Windows: Windows 11 Home 26300, WinLibs GCC 15.2.0, Release.
Truncation. A probe sends one
AI-assisted: yes (Claude Code); results above were run on this machine. |
|
@wachi35676 thanks, you're right, and the probe that counts 223a7c1 (not pushed yet) does it FreeBSD's way:
Red/green runs and the wider AI-assisted: yes (Claude Code) |
# Conflicts: # core/libs/prx/libkernel/Socket/src/Udp.cpp # docs/dev/debt/libkernel.md
|
Merged
The 15 AI-assisted: yes (Claude Code) |
|
@milescoviello I am coordinating #11872 (POSIX read/receive cancellation, head bcf5df1) with this PR under CONTRIBUTING.md. Proposed order: #11872 first, then #7090. Your recvmsg control-data branch and #11872 modify the same native receive. With #11872 first, the later SCM_RIGHTS integration should retain the POSIX Io/descriptor admission boundary, route the blocking recvmsg through the native interruption machinery, and keep ownership of received descriptors through failure/cancellation and guest-output copy. Combined checks should cover blocked cancellation and close/reuse as well as rights truncation/copy failure; I have not run the combined branch. Would you agree to that order and record #11872 in your Depends on line for the ordering? If your PR needs to go first, please say so; I can handle the later conflict resolution on #11872 instead. This is a proposal awaiting your confirmation, not an existing agreement. AI-assisted coordination. |
|
@Felipebmaitan thanks for checking first. I'd like #7090 to go first, and I'll take your offer to handle the later conflict on #11872. My reasons:
So I'll leave When you rebase #11872 onto it, the code to keep is in
So a cancellation while blocked has nothing to release. Your interruption path can wrap the native call without touching the rights handling after it. If it helps, I can run the combined branch with AI-assisted: yes (Claude Code) |
|
@milescoviello thanks for this, the SCM_RIGHTS passing itself reads right. A few things before it can go in:
Please keep the existing truncation/data/address cases and the explicit unsupported behaviour and debt as they are, without tests that pin unsupported forms to throw. Connected-socket state and composition with #11872 can stay as follow-ups. |
|
@oneandonlydean thanks for the careful read. I'll work through all four:
The truncation, data and address cases and the unsupported behaviour and debt stay as they are. Connected-socket state and #11872 stay as follow-ups. AI-assisted: yes (Claude Code) |
…s whole result A fault on the final message header write, or an installation that fails part-way, now closes every received descriptor exactly once. A plain-data MSG_PEEK with control space on a Unix socket reads the data again, as on main, and the test includes the public headers and counts host descriptors portably. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@oneandonlydean all four are in
Tested on Linux (Ubuntu 26.04.1, GCC 15.2, Release, The truncation, data and address cases and the unsupported behaviour are as they were. Connected-socket state and #11872 stay follow-ups. AI-assisted: yes (Claude Code) |
|
Two homebrew catalog titles that need this on Linux: bizkut's Wine-based Forever Launcher (PPSA99030, 01.000.021) and RuneScape Launcher (PPSA99225, 01.000.021). Both run Wine with an in-process wineserver, which passes descriptors to its clients with Setup:
With this PR (merge
Not tested: Windows (the titles can't start there), and a console. AI-assisted: yes (Claude Code). |
|
@p3n1cillin thanks for running both launchers on current AI-assisted: yes (Claude Code) |
XairRrR
left a comment
There was a problem hiding this comment.
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-ffin 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
-
sendmsgpasses 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/nullplaceholder plus an entry ing_kqueues(Kqueue.cppL86-L92, L561-L572). A guest/dev/urandomis a/dev/nullplaceholder that libkernel fills on read (RandomDevice.cppL28-L38).PassedDescriptorschecks 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:
sendmsgreturns 2. The received descriptor failskeventwithEBADF, though the original returns 0. FreeBSD 11.4 refuses the send instead:unp_internalizereturnsEOPNOTSUPPfor a file withoutDFLAG_PASSABLE(uipc_usrreq.cL2004-L2011), andkqueueopssets nofo_flags(kern_event.cL122-L135). /dev/urandom(opened withsceKernelOpen): 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 throughNotImplemented_nid_no_patch, asRefuseArchivedFilealready does for archived files. Name them in the debt entry, and add aguest_socket_rightscase for the kqueueEOPNOTSUPP. - kqueue:
-
A zero-byte
sendmsgwithSCM_RIGHTSon a stream socket returns 0 and drops the descriptors.SendPassinghands an empty iovec to the hostsendmsg. Linux doesn't carry ancillary data on aSOCK_STREAMUnix socket without at least one data byte. In the probe the call returns 0, and the receive after a later one-byte plain send getscontrolLength0 and noMSG_CTRUNC, so the descriptor is gone and neither side is told. FreeBSD 11.4 delivers control-only sends:sosend_genericbuilds "a single empty mbuf" when "resid is 0, which can happen only if we have control to send" and callspru_sendwith it (uipc_socket.cL1325-L1331). Suggested fix: when the socket is a stream,descriptorsis not empty anddatais empty, throw throughNotImplemented_nid_no_patchand 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
- @lgqdaxia reported that guest
getpeernamereturnsENOTCONNon a received connected Unix socket. The debt entry atdocs/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_|libctests outside the 9 listed. - Any title: no game or homebrew was launched.
- Whether
RefuseArchivedFilealso catches the/dev/nullplaceholder thatDirectoryDescriptor.cppopens for an archived directory.
To get this to a good state
- Refuse emulated descriptors in
PassedDescriptors:EOPNOTSUPPfor kqueue,NotImplemented_nid_no_patchfor the others. Add a test and a debt line. - Throw on a zero-byte stream
sendmsgthat carries descriptors, and list it in the debt entry.
…irectory in SCM_RIGHTS A guest kqueue and a guest /dev/urandom are /dev/null placeholders with their behaviour in libkernel's tables, and a guest directory descriptor keeps its reading state there too. sendmsg sent the placeholder, and the receiver got a descriptor that failed kevent or read as empty. FreeBSD's unp_internalize returns EOPNOTSUPP for a kqueue (no DFLAG_PASSABLE), so a kqueue now gets that; a random device or a directory throws. A zero-byte sendmsg carrying descriptors on a stream socket returned 0 and lost them, as Linux sends no record without data. It throws now. FreeBSD sends the control data alone there. guest_socket_rights checks the kqueue refusal and that the next send on the pair arrives without control data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@XairRrR thanks for the probe. Both are fixed in
The debt entry lists both. To fit the 1000-character limit, I tightened the rest of its wording without dropping anything.
On AI-assisted: yes (Claude Code) |
Progress report (2960e9a → 1e19b32)📉 System libraries: 45.9% (-0.01%, -1 reverted functions)
|
| Library | Name |
|---|---|
| libkernel | sendmsg_nid_postfix |
Changed libraries (implemented exports)
| Library | Before | After | Change |
|---|---|---|---|
| libkernel | 693/737 (94.03%) | 692/737 (93.89%) | -0.14 pp |
XairRrR
left a comment
There was a problem hiding this comment.
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 toPassedDescriptorsand the zero-byte stream check toSendPassing, adds aCheckRefusedKqueuecase toguest_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
Testedline. - The progress bot now counts
sendmsg_nid_postfixas a stub. That is howtools/progress.pyworks:sendmsgreaches a helper that callsNotImplemented_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-ffin 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
- 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/urandomopened withsceKernelOpennow throws. The archived-directory/dev/nullplaceholder is ing_directories(OpenDirectoryDescriptorregisters the descriptor thatOpenPlaceholderreturns), soIsDirectoryDescriptorcovers 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. - Blocking 2 (zero-byte stream send): resolved. In the probe it throws. A zero-byte datagram send still delivers its 24-byte record.
- Non-blocking (
getpeernameon a received socket): still open, unverified. Neither of us reproduced it, so leaving the entry as it is seems fine.
New findings
Blocking
-
The head does not compile on current
main. #11296, merged on 2026-10-28, renamedIsKqueueDescriptortoIsKqueueDescriptor_nid_no_patch(commitf87b6289ac). The new check atUdp.cppL1614 still uses the old name. Git merges the files without a textual conflict, butlibkernelthen fails to build. The branch's merge basef759e165d9is older than the rename, which is why it built for the author. Fix: merge or rebase onto currentmainand callIsKqueueDescriptor_nid_no_patch(passed). With that one-line rename, everything above passes. -
A JIT shared-memory descriptor is still sent as if it were complete.
sceKernelJitCreateSharedMemoryreturns a real host memfd, but its size object and maximum protection live in libkernel'sg_jitDescriptors.sceKernelJitMapSharedMemoryreturnsEBADFfor any descriptor that is not in that table.dupcopies the entry (Stdio.cppL862), but the receive side ofSCM_RIGHTSdoes not. In the probe,sendmsgreturns 1 and the record arrives. Mapping the original descriptor returns 0, but mapping the received one returns0x80020009(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 fromJit.cpp(asIsRandomDeviceis exported), throw for it inPassedDescriptorsnext to the random-device and directory check, and add "JIT shared memory" to the debt entry atdocs/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 thatsendmsghands over on Linux. TheSharedMemory.cppaccess table is Windows-only, andSCM_RIGHTSthrows on Windows.
To get this to a good state
- Bring the branch up to current
mainand rename the call toIsKqueueDescriptor_nid_no_patch. - Refuse JIT shared-memory descriptors in
PassedDescriptors, or register them on receive, and list the case in the debt entry.
…and use the renamed kqueue check sceKernelJitCreateSharedMemory's size object and maximum protection live in libkernel's g_jitDescriptors, which the receive side of SCM_RIGHTS doesn't fill, so a received JIT descriptor failed sceKernelJitMapSharedMemory with EBADF (XairRrR's review). Passing one now throws, with the random device and directory cases; IsJitSharedMemory answers it. The merge of main brought boykopovar#11296's rename of IsKqueueDescriptor to IsKqueueDescriptor_nid_no_patch, which the kqueue check now calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@XairRrR thanks, both fixed. The head is
At this head, the 19 tests matching AI-assisted: yes (Claude Code) |
XairRrR
left a comment
There was a problem hiding this comment.
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 ofmain52c09d567dinto the branch. Git reported no conflicts, and it brings in #11296's rename.1e19b327f7: addsIsJitSharedMemory(a lookup ing_jitDescriptorsunderg_jitLock), throws for it inPassedDescriptorsnext to the random-device and directory cases, callsIsKqueueDescriptor_nid_no_patch, and adds JIT shared memory to the debt entry atdocs/dev/debt/libkernel.md:242.- The author replied in the thread, and the description has a new top
Testedline.
What I ran
- PR head:
1e19b327f7f0262d5e3c4df150ec3f04b9adad2d main:2960e9a6e7e1fc99c4ed180c71495b5eb83464c7- I merged with
git merge --no-ffin 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
- Blocking 1 (does not compile on current
main): resolved. The head callsIsKqueueDescriptor_nid_no_patch(Udp.cppL1628). Onmain2960e9a6e7, the merged tree buildslibsand the tests without my local rename. - 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
dupcopies have their own entries ing_jitDescriptors, so the lookup covers them. Closing the descriptor removes its entry (ForgetJitSharedMemoryinStdio.cppandOpen.cpp), so a later descriptor that reuses the number is not refused by mistake. The debt entry lists the case. - Non-blocking (
getpeernameon 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
- The JIT refusal has no regression test.
NotImplemented_nid_no_patchthrows an exception that a test can catch. My probe shows this, and the random-device and directory refusals have no test either. ACheckRefusedJitcase inguest_socket_rightswould keep the check from disappearing quietly. It could catch the exception for asceKernelJitCreateSharedMemorydescriptor, then confirm that the next plain send arrives without control data. This is optional. - A stray line in the description's
Testedsection. "Ubuntu 24.04, GCC 13.3, Release. The results below are frommain673f740, 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.
IsJitSharedMemoryis defined outside the platform blocks inJit.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_multicastwith a network. Its failure here matchesmain.
What
sendmsgthrewcontrol data is not supportedfor 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_RIGHTScontrol messages now pass descriptors, as FreeBSD 11'sunp_internalizeandunp_externalizedo.sendmsg: reads FreeBSD's layout: a 12-bytecmsghdrwith the descriptors at offset 16, and recordsCMSG_SPACEbytes apart. It sends the descriptors with the host'sSCM_RIGHTS, because a guest descriptor here is a host descriptor (a guest socket's number is a duplicate of its host socket).EBADFfor a descriptor that is not open, andEINVALfor a level other thanSOL_SOCKETor a record longer than the buffer.recvmsgwith a control buffer: receives with the host'sSCM_RIGHTS. A received socket is installed as a guest socket (family fromgetsockname(), type fromSO_TYPE); any other descriptor is used as it is.CMSG_LENincmsg_lenandCMSG_SPACEbytes, when the whole record fits the caller's buffer. Otherwise it copies nothing, setscontrolLength0 andMSG_CTRUNC, and closes the passed descriptors. That is what 11.4'skern_recvitdoes: it copies only control mbufs that fit whole and disposes the rest withm_dispose_extcontrolm. A fault writing the record, the data or the address also closes them and returnsEFAULT, askern_recvit'sout:path disposes of the control descriptors whenever it returns an error.MSG_CMSG_CLOEXECmarks the received descriptors close-on-exec. Where the host has noMSG_CMSG_CLOEXEC(macOS), each received descriptor getsfcntl(F_SETFD, FD_CLOEXEC)before it is installed.msghdrwrite included, is written back. Any earlier return closes each of them exactly once, including a failure part-way through installing them.MSG_PEEKwith control space reads only the data, as onmain, and leaves any passed descriptors queued.b9e987b82e, from XairRrR's review): a guest kqueue returnsEOPNOTSUPP, as in FreeBSD'sunp_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.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 theSCM_RIGHTSsetup above it) and add neighbouring entries todocs/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):main52c09d567dmerged in, with the kqueue check renamed toIsKqueueDescriptor_nid_no_patch(fix(libkernel_sys): fail fpathconf on a kqueue or shm descriptor with EOPNOTSUPP #11296). A JIT shared memory descriptor (IsJitSharedMemory) now throws too. The 19 tests matching^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcp|^guest_jitpass 3 of 3.This head (
b9e987b82e, XairRrR's review): the 18 tests matching^guest_socket|^guest_recvmsg|^guest_udp|^guest_tcppass 3 of 3. The new kqueue case inguest_socket_rightsrequires-1/errno45 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 basef759e165d9and on this head.guest_socket_options,guest_socket_options_multicastandguest_socket_stream_optionsfail the same way on both (0xc0000409).Review rework (
1db8d77c9a,mainef90ce0452merged in), after oneandonlydean's review:ReceivedRightsowns the received descriptors until the final header write. The old rollback could close a descriptor twice: after a failedInstalltheSockethad already closed it, and the loop closed it again. PlainMSG_PEEKworks again. The test includesprx/libkernel/include/Api.hppandprx/libc/include/Api.hpp(thepublic_headersaudit passes) and counts host descriptors withfcntl(F_GETFD)instead of/proc. New cases:msghdrwhose final header write faults after the data and control copies succeeded:EFAULTwith the host descriptor count unchanged;AF_ROUTEsocket passed together in both orders, where installing the route socket fails: the host descriptor count is unchanged;MSG_PEEKwith 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_udpandguest_tcppass 3 of 3. With the previousUdp.cppunder the new test,guest_socket_rightsaborts. 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 atmainf759e165d9.Merged
main1e740a2 into the branch (04eeeb9d11), then added484bc8c2c3.mainhad changedrecvmsgin fix(libkernel): answer zero-length datagram receives and recvmsg flags as measured on a PS5 #10308: the host receive runs only for data, a stream socket or a readable one, andmsg_flagsstarts from the call's flags as measured on a PS5. The descriptor-passing receive now sits inside that condition, and the two-socket case ofguest_socket_rightsnow expectsMSG_CMSG_CLOEXECback inmsg_flags(it expected 0, and failed 3 of 3 against fix(libkernel): answer zero-length datagram receives and recvmsg flags as measured on a PS5 #10308). On Linux (Ubuntu 26.04.1, GCC 15.2), the 14guest_socket*tests pass 3 of 3 on484bc8c2c3, and the 649 tests matching^guest_|libcpassed 3 of 3 on04eeeb9d11apart from that case.Title run on
484bc8c2c3(by @babyhuey, Linux CI image with lavapipe, Ubuntu 24.04, GCC 13, Release): the 14guest_socket*tests pass, and Forever Launcher (PPSA99030) is still running at the 60 s timeout in 2 of 2 runs, with nosendmsg: control data is not supported,what()orFATAL(mainf3456a4 stops at thatsendmsgline).Ubuntu 24.04, GCC 13.3, Release. The results below are from
main673f740, 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,mainf3456a4 still stops Forever Launcher withsendmsg: control data is not supported. With this head (1142d3a6bc, clean merge) the 14guest_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 (516263f), 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_rightscase: two pipe ends are passed and received into a read-only data buffer, and the receive must returnEFAULTwith the count in/proc/self/fdunchanged. It aborts with the previousUdp.cppand passes with the fix, and the 12guest_socket_*tests pass 3 of 3. The debt entry also says now that severalSCM_RIGHTSmessages in onesendmsgarrive as one record. @wachi35676 re-checked 516263f8f6 merged ontomaina020d02: the 14guest_socket_*tests pass 3 of 3, reverting only theUdp.cpphunks makes the faulted-receive case abort, and their probe now leaves no descriptor open after a fault on the data buffer. The Windows build ofUdp.cppandlibkernelsucceeds on the same merge.Truncation fixed (223a7c1), after @wachi35676 found that a short control buffer leaked the passed descriptors. With the old record copy and the new test,
guest_socket_rightsaborts. With the fix, the 12guest_socket_*tests pass 3 of 3, andctest -R '^guest_|libc'passes 475 of 476.guest_module_directories(a relinker test) fails the same way onmainin that tree.Rebase onto
mainbf2c63f (5f492d3).recvmsgonmainnow reads the guest'smsghdrand iovecs into a copy and writes its results back withReadGuest/WriteGuest. The control record is written the same way: into the copiedcontrolpointer, withcontrolLengthandMSG_CTRUNCin the copied header that is written back.guest_socket_*(12 tests,guest_socket_rightsincluded) pass 3 of 3.ctest -R '^guest_|libc': 474 of 476 pass.guest_bad_optional_accesswas not built in that tree, andguest_module_directories(a relinker test) fails the same way withmain's sources.New
guest_socket_rightstest (Linux), over a stream socket pair:MSG_CMSG_CLOEXEC, and checks that both received sockets are close-on-exec and send and receive.MSG_CMSG_CLOEXECand 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.controlLength0 andMSG_CTRUNC. So does a record of two descriptors with room for one (20 bytes), and in both cases the count in/proc/self/fdis unchanged, so no descriptor leaks. A receive without a control buffer gets the data only.EBADF, and another level or an overlong record givesEINVAL.main'sUdp.cppit aborts onsendmsg: control data is not supported. It passes 3 of 3, withguest_socket_pairtoo.ctest -R '^guest_|libc': 402 of 402 pass.Forever Launcher (PPSA99030, 01.000.012), in gdb: Wine's first such call is
sendmsgon a socket-pair end withMSG_NOSIGNAL | MSG_DONTWAIT, one byte of data and a 24-byte control buffer holding oneSOL_SOCKET/SCM_RIGHTSrecord (cmsg_len20) that passes the end of another socket pair.mainwith the PRs for its earlier stops merged locally (feat(libkernel): declare physhm_open and physhm_unlink #6915, fix(libkernel): export sysarch so modules that import it load #6028, fix(libSceSystemService): declare the PsmKit local process exports #6939, feat(libSceKeyboard): export missing firmware functions from database #6787, feat(libkernel): report the guest address-space map through kern.proc.vmmap #7070, fix(memory): honor low guest mapping hints #6469), it stops at 0 s onsendmsg: control data is not supported, 2 of 2.kevent: NOTE_LOWAT(wineserver's kqueue registersEVFILT_READandEVFILT_WRITEwithNOTE_LOWAT1). That is a separate PR.NOTE_LOWAT) merged, that next stop is gone. Onmain98c251f with feat(libkernel): declare physhm_open and physhm_unlink #6915, fix(libSceSystemService): declare the PsmKit local process exports #6939, feat(libSceKeyboard): export missing firmware functions from database #6787, feat(libkernel): report the guest address-space map through kern.proc.vmmap #7070, fix(memory): honor low guest mapping hints #6469 and this PR (17d9e0a), Forever Launcher runs the whole 60 s in 2 of 2 runs with no unimplemented call. Its first-start prefix setup then reportstitle wineboot skipped; prefix must be initialized by payload Wineandfailed 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
mainwith 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.main7fea87746both abort onsendmsg: control data is not supported.main319621ba2e(4fa9ea8a0f, clean), neither stops there. Both start their wineserver, and Wine runs and shuts down in order.scm|rights|unix|sendmsg|recvmsgctests pass on the merge.Windows build: @wachi35676 found that
Udp.cppdid not compile there:GuestControlCloseOnExecwas declared inside the non-Windows block. 17d9e0a moves the declaration out of it. A MinGW-w64-fsyntax-onlycompile ofUdp.cppstops 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 andlibs). 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,sendmsgwith anSCM_RIGHTSbuffer still stops withcontrol 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 1142d3a and its merge base eaff876: 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_RIGHTSstill 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_DOMAINandMSG_CMSG_CLOEXECdon't exist in XNU's headers, soUdp.cppdidn't compile on top of feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332. aff8c2a takes the received socket's family fromgetsockname(). WhereMSG_CMSG_CLOEXECdoesn't exist, it marks each received descriptor withfcntl(F_SETFD, FD_CLOEXEC)when the guest asked for it. Their local equivalent compiled with-Wall -Wextraon arm64 and x86_64, andguest_socket_rightspassed 5 of 5 under Rosetta. They also found that the test didn't check the host flag, so a3b3801 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 thefcntlpath. With the flag forced to 0 and thefcntlloop removed, the test fails.^guest_|libcpassed 411 of 411 on aff8c2a. @jotitadev then checked head a3b3801aa6 on feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332 (57bccfb, M2 Max, macOS 27.2, Apple clang 21.0.0):Udp.cppcompiles with-Wall -Wextraon arm64 and x86_64 with no warnings of its own, through thefcntlfallback. Under Rosettaguest_socket_rightspasses 5 of 5, and with thefcntlloop removed it fails 3 of 3 on the new pipe check. The 20 socket, UDP, RUDP, poll and select tests pass, except an intermittentECONNRESETinguest_socket_read_writethat also happens on feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332 alone.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)sendmsgabort (p3n1cillin's run); PPSA99030 Game bring-up: Forever Launcher (PPSA99030): past sendmsg with #7090; first-start Wine prefix setup stops #12712 (Forever Launcher): feat(libkernel): declare physhm_open and physhm_unlink #6915, fix(libkernel): export sysarch so modules that import it load #6028, fix(libSceSystemService): declare the PsmKit local process exports #6939, feat(libSceKeyboard): export missing firmware functions from database #6787, feat(libkernel): report the guest address-space map through kern.proc.vmmap #7070 and fix(memory): honor low guest mapping hints #6469 have landed, and this is its last stop onmain(babyhuey's run)🤖 Generated with Claude Code