runtime: Unix domain socket natives (step 1 of #119) #428
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
First step of #119 (Unix domain sockets for
std/network, FIRST-PARTY.md gap 21): the runtime can listen on a path,accept, and connect to a path, behind two new natives, with the existing stream natives (
networkReceive,networkSend,networkShutdown,networkClose) working on the resulting handles unchanged. Nostd/source changesin this step, so the seed that builds the compiler (which imports
std/networkincompiler/src/debugger/adapter.trb) still compiles everything.Design
std/network, ownernetwork, verdictkeep(NATIVES.md):networkListenUnix(path: String, backlog: Int): Intanswers the listener's handle or a failure;networkConnectUnix(path: String): Task<Int>answersthe stream's handle or a failure. Accept is the existing
networkAccepton the listener handle, so no third native.runtime/io.c,runtime/include/torb_network.h):torb_network_listen_unixandtorb_network_connect_unix. The socket records learn the familyAF_UNIX; thetorb_io_addressof the core staysIP-only, and the path crosses as text and is checked in the hook.
torb_io_system_socket/torb_io_system_listen:runtime/os/posix_io.c(sockaddr_un, epolland kqueue unchanged: readiness is family-blind) and
runtime/os/iocp.c(Windows 10 1803 and later;AcceptExandConnectExget a third slot beside IPv4 and IPv6; if the system refusesConnectExforAF_UNIX, the connect runson the core's helper thread as the resolver does, and the commit message or the header says which was needed).
Written for both; run on Linux in the forge CI like UDP's kqueue/Windows split in NETWORK.md section 4.
sun_path(108 bytes on Linux and Windows, 104 on macOS/BSD, theterminating zero included) or containing a NUL byte is
invalid argument, never truncated. Linux abstract names(a leading
@/NUL) are not supported in this step. A path that exists makeslisten_unixfail with the system'sEADDRINUSE(isAddressInUse()inNetworkError); a path nobody listens on makes connect fail withECONNREFUSED/ENOENT(kinds map toConnectionRefused/Unreachablethrough the existing error-kind table).this handle bound; nothing else is unlinked. A stream accepted from it has no peer path.
torb_sandbox_check_unix(verb, path)inruntime/sandbox.cthat stops the script (TORB_SANDBOX_REFUSED) while anysandbox is open, with the message
The script may not <verb> the Unix socket `<path>`: a sandbox grants no Unix sockets. The grant language for socket paths is a later slice (see #119);unrestricted(torb repl) allows them.std/API (step 2 of #119), datagram Unix sockets (SOCK_DGRAM), socket-pair, credentials ofthe peer (
SO_PEERCRED), file descriptor passing, abstract names,chmodof the socket file.Acceptance criteria
torb_network_listen_unixandtorb_network_connect_unixinruntime/io.c, declared inruntime/include/torb_network.h, with hooks inruntime/os/posix_io.candruntime/os/iocp.c; the existingaccept, receive, send, shutdown and close work on their handles.
torb_sandbox_check_unixinruntime/sandbox.c, called by both natives, and listed in the file's header comment.nativeEntries()ofcompiler/src/backend/c/natives.trb(stateReady);runtime/include/torb_natives.handruntime/machine_natives.cregenerated withtorb natives --header, thegenerated-file check green.
keep,network) in thestd/networktable ofdocs/design/NATIVES.md; the audit check stays green.runtime/tests/io_test.c, run in the forge CI (sh runtime/build.shjob) on Linux: listen on apath in a temp directory, connect, accept, exchange bytes both ways, shutdown gives the peer the end of the
stream; a path that exists is address-in-use; a path nobody listens on is refused; a path over the limit and a
path with a NUL are
invalid argument; the file is gone after the listener's handle closed; a closed handle and aTCP handle passed where a Unix one is expected fail with the closed/invalid kind. With a sandbox open (the
existing sandbox test harness of
runtime/tests/) both natives are refused.docs/design/NETWORK.md: a section 4 paragraph "Unix domain sockets, as built (step 1)" with the path rules,the unlink-on-close rule and the sandbox rule above; section 10's "Where the checks are" sentence names
torb_sandbox_check_unix.sh tools/gates.sh a);btoo, sinceruntime/changes.Seed
Touches the seed: yes (two new natives in the manifest,
docs/design/NATIVES.md, CLAUDE.md "Seed and breakingchanges"). This is the first of the two commits of that rule, landed alone as its own PR: "teach the form". The seed
refresh and the publishing of the seed (
seedworkflow) after it lands are Torben's and the merge gate's, not theloop's. The second commit is step 2 of #119 and is filed only once the published seed knows the natives.
Commit
One commit:
feat(runtime): Unix domain socket natives(at most 100 characters).Dependencies
None. Not blocked by #426 (socket option natives for TCP streams, step 1 of #120), which is implemented in parallel and
also touches
runtime/io.c,runtime/include/torb_network.h,compiler/src/backend/c/natives.trb, the NATIVES.mdtable and the two generated natives files: whichever lands second rebases and regenerates
torb_natives.handmachine_natives.con top of the other. Not a dependency, a note for the rebase.Source
docs/design/NETWORK.mdsection 10 ("A new one - Unix domain sockets ... calls one of the checks there, or refuseswhile a sandbox is open: the grant fails closed, never open")
[loop:torbscript] claim implement by session:loop-torbscript-20261023 until 2026-10-23T19:50Z
[loop:torbscript] implement: both natives, the hooks (POSIX and Windows),
torb_sandbox_check_unix, manifest entries, regeneratedtorb_natives.h/machine_natives.c, NATIVES.md rows, NETWORK.md paragraph and the runtime and sandbox tests are in one commitfeat(runtime): Unix domain socket natives, PR #430, CI success on the first run (tier A, tier B, gates, bootstrap linux-x64, generated-file check all green; the Windows, macOS and cross jobs were skipped by the change filter), next: reviewNotes for the reviewer:
ConnectExis not used forAF_UNIX(it needs a bound socket andAF_UNIXhas no unnamed address); the connect runs on the core's helper thread.AcceptExhas the third slot. That code is written against the Winsock documentation and was not compiled or run (the Windows jobs were skipped).torbbinary or C compiler was available while writing, so the generated files were produced by a script that mimicstorb natives --header; CI's check accepted them.std/,seed/; the seed refresh is the second commit of the rule and is not part of this PR.Tokens: not metered inside this worker session; about 2 context windows of Sonnet work.