Repository navigation
host/net: opt-in nn::socket network mode on the host's own IPv4 sockets - #3324
Open
RobiiAragon wants to merge 2 commits into
Open
RobiiAragon wants to merge 2 commits into
RobiiAragon wants to merge 2 commits into
Conversation
DM_NETWORK=lan sends each dm_sk_* call for a network descriptor to hle_net_backend.c, so every enum, plain-argument and C entry point follows without a hook of its own. Without it, main's offline local UDP/EventFd service answers every call unchanged. Network descriptors start at 64, above the service's EventFds, in one 1024-entry fd_set namespace; a mixed Poll/Select alternates the EventFd check with short host waits. The transport translates Horizon's sockaddr, Linux errno numbers, O_NONBLOCK and option numbers, keeps SO_NOSIGPIPE on every native socket, prepares guest output before the kernel's copyout, and ends a blocked call with EBADF when another thread closes its socket. nifm keeps its on-hold sequence, then reports the host interface. Name resolution, TLS, LDN and the online services stay offline. t_net covers the transport on loopback UDP and TCP, including under ASan, UBSan and TSan.
… descriptors clang-tidy's analyzer could not see that the sockets t_net indexes fd_sets with are valid, or that RecvFrom filled the source address before it is compared. The test now starts the address buffers at zero and asserts both descriptors are the transport's before using them as fd_set indexes.
RobiiAragon
force-pushed
the
net/socket-transport
branch
from
November 27, 2026 10:03
e568cb2 to
2ceec60
Compare
This was referenced Nov 27, 2026
|
@RobiiAragon thanks for extracting this. I rebuilt my four fixes on top of it and opened them as drafts, one PR each, so they can be reviewed against your code now:
Name resolution isn't in any of them, since that's your #956 slice. They're stacked on this branch, so each one also shows your two commits until this merges. Only the last commit in each is new. I'll mark them ready after this goes in. |
Contributor
|
awesome are we finally going to get LDN support? |
2 tasks done
This was referenced Nov 29, 2026
This was referenced Nov 29, 2026
2 tasks done
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
This is the first small, standalone piece of host networking we agreed on in #2589: an opt-in network mode for
nn::socket. It runs the game's sockets on the host's own IPv4 TCP/UDP sockets. I wrote this transport for NX Port Studio, where it carried my completed Mac–Switch LAN race in Mario Kart 8 Deluxe 3.0.5 (2026-10-31). Later it went into #846 and #961. Here I extracted only the transport, on top of currentmain(4fdfd479).The default is unchanged. Without
DM_NETWORK=lan,main's offline local UDP/EventFd service answers every call as before, andt_net_loopbackandt_net_eventfdpass unmodified.How it fits
maindm_sk_*function inhle_net.csends a network descriptor tohle_net_backend.c(net_socket.h). Every entry point (the enum, plain-argument and C overloads inhle_net.candhle_offline.c) follows without a hook of its own. The only hook changes are thatListenandAcceptnow calldm_sk_listenanddm_sk_accept; offline they still return -1.fd_set.Selectand aPollthat mixes both kinds keep working. A mixed set alternates the EventFd check with 5 ms host waits. An endless wait comes back after 100 ms, asmain's offline one does. EventFd staysmain's.dm_sk_set_errno, soGetLastError,GetLastErrnoandnnsocketGetLastErrnostay as they are. Network mode uses Horizon's Linux numbers: an empty non-blocking receive is EAGAIN 11, which Mario Kart 8 Deluxe's receive loop compares.What the transport handles
{u8 length, u8 family}sockaddr (sin_len0 is accepted), short address buffers, O_NONBLOCK 0x800, and SOCK_NONBLOCK / SOCK_CLOEXEC. Option numbers at the socket, TCP and IP levels are mapped explicitly, because Darwin numbers some of them differently. Unknown options get ENOPROTOOPT instead of passing through. SO_ERROR comes back as a Horizon errno and SO_TYPE as Horizon's value.GetSockOptcallsdm_guest_write_prepareon its output before the kernel writes it, and again after each wait. The kernel's copyout into a protected page fails with EFAULT instead of reaching the dirty-page fault hook.dm_thread_native_wait). Each call borrows a duplicate of the native descriptor. A Close on another thread ends a blocked call with EBADF through the slot's generation, and the shutdown on close wakes a TCP waiter at once.Name resolution, TLS, LDN, BCAT and the online services keep their offline answers and are not part of this PR.
Follow-ups, each its own PR on top of this
RecvMsg/SendMsg, EventFd in the socket table (a mixed wait in one host poll), default-route IP selection.HLE_FORCE_WAIT, which publishes the guest's register context during a blocking host call so a pause (GetThreadContext3, a stop-the-world collector) can stop the thread.main's own blocking hooks don't have that yet either. It changesentry.Sandhle_thread.cfor every hook, so I'm keeping it separate. Until then, a thread blocked in a network-modeRecv/Acceptcan't be paused, which only matters withDM_NETWORK=lan.Verification
I ran these on an Apple Silicon Mac, macOS 27.2, Xcode 27.2:
make -C dm/host/tests GAME=010015100B514000 run: the full host suite passed, including the newt_net(61 checks over loopback UDP and TCP through the game's entry points) and the unchangedt_net_loopback/t_net_eventfd/t_server_environment.make … asanandmake … tsan-threads(t_netadded toTSAN_T): passed.t_netcatches what it claims, I removed SO_NOSIGPIPE: the test process died of SIGPIPE. Without the write preparation, its check failed.make -C dm/host GAME=010015100B514000anddmhost --check-tables: no new warnings, tables pass.clang --analyzeonhle_net_backend.candhle_net.c: no findings.DM_GAME=010015100B514000 python3 dm/ios/tools/compile_check.py: 271 files, 0 failed.python3 dm/tools/tests/test_docs.pyandtest_env_switches.py: passed (DM_NETWORKadded todocs/env_switches.tsv; reference entry indocs/reference/services.md; symptom index regenerated).I haven't run this exact branch in a LAN game session. The in-game evidence above comes from the NX Port Studio transport it's extracted from. I didn't run clang-tidy locally (no LLVM here), so the ratchet job in this PR's CI is its first run.