The guest joins a tailnet from Node or the page: ts2021 control over
WebSocket, DERP relays, WireGuard and the packet filter in JS, loaded as
a separate chunk only when the option is used. SDK net option, CLI
--tailscale* flags and a page panel. Relay only; exit nodes, IPv6 and
real peer traffic are not covered yet.
* js: hard links on host file systems: Fs gets an optional link(target, path), which the 9p server calls for Tlink of a regular file (it answered EPERM always); nodeFs makes them with fs.link, refusing a source that is not a regular file and undoing a link whose new name is not the file it lstat'ed (Darwin's link(2) follows a symlink, which would name a file outside the directory); MemoryFs still answers EPERM, as do a directory, a symlink and a read-only mount, and a fid restored without its file answers ESTALE; package managers that put a file in place with a link (uv's lock and cache, cargo, pnpm's store) work on a nodeFs mount and on tabc's volumes; tests in 9p.test.ts and api.test.ts (ln in the guest, one inode on the host)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* js: nodeFs runs a hard link alone, so the guest cannot rename, remove or symlink a source or a name into place during it (on Darwin, link(2) follows a symlink); link uses the bigint lstat; a restore leaves a file stale that was open under a removed name even when a hard link still names it (documented); the api hard-link test uses its own directory (below scratch it broke the vm.mount() test's listing) and no longer checks a directory link, which the guest's VFS refuses before 9p; the 9p test removes its directories and checks that a link and a rename do not overlap
* js: nodeFs's hard link checks that every directory on both its paths is a directory, not a symlink (ESTALE), and its lock is per host directory with waits and holds bounded to 10 s (EAGAIN), so a hung rename no longer stalls links and renames of every mount; tests for both, the Tlink test's title says EROFS, the api test unmounts in t.after; Fs.link says the target's type may have changed since the walk
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Pooya Parsa <pooya@pi0.io>
The SDK named the project's Wisp server (DEFAULT_WISP_SERVERS), and the
Node entry sent Origin: http://localhost to pass that server's allow
list (NODE_WISP_HEADERS). The server accepts only the page's origins,
so both are gone: wispBackend() takes the caller's server, and Node
sends handshake headers only when `headers` asks for them. The page
keeps wss://wisp.unkernel.dev:6680/ as its own default (web/src/net.ts).
The live Wisp test takes its server from UNKERNEL_TEST_WISP.
Sockets: sock_accept, sock_recv, sock_send and sock_shutdown on sockets the program inherited, with socket file types, poll and non-blocking; KWWASI_TCPLISTEN=ADDR:PORT[,...] opens listening TCP sockets at descriptors 4, 5, ... (exit 126 when one is already open); a write to a socket whose peer went away is EPIPE, not SIGPIPE.
Threads: modules that import wasi.thread-spawn and a shared env.memory run on the shared path, each wasm thread with a worker, a channel and a kwwasi connection of its own (a kwwasi pthread sharing the process's descriptors), so a thread blocked on stdin holds up no other; proc_exit or a trap in any thread ends the program; the message path refuses such a module with exit 126.
Clocks: realtime and monotonic follow the guest's (kwwasi sends both readings at START, no request per call); the CPU clocks are the worker's CPU time on Node, the process clock covering every thread through worker.cpuUsage(); unknown clock ids are EINVAL and the resolution is the timer's measured step.
Files: fd_allocate; fd_fdstat_set_flags refuses a sync flag change with ENOTSUP; more Linux errnos mapped; KWWASI_CWD=cwd resolves every path without a leading "/" from the cwd, with no guessing.
A wasm64 module is refused with exit 126, and a sleep on the message path no longer ends a fraction of a millisecond early. The kwwasi protocol is version 3. test/wasi-binfmt.ts runs its guest commands as root and covers the above.
Sessions and the console run as user in /home/user on Debian and Alpine (doas with a sudo shim there); the host asks for another user with SpawnOptions.user, the CLI's --user or kw.user=. The shims, the command-not-found installers, poweroff and the page's launcher and demos reach root through sudo, and apt, apt-get and apk typed by the user are aliases to it. /usr/lib/kw/shrc gives nested shells, sudo -s and sudo -i the prompt, the command-not-found handler and PATH that only login shells had. The framebuffer, input and sound devices are group-accessible, and host mounts show as the user's.
createKernel({ distro }), fetchDistro() and the CLI's --distro; the npm
package ships the distroless bundle only. HttpBase streams the image's
prefetch and reuses cached chunks after one validation.
binfmt_misc hands a wasm module to kwwasi (kernel/guest/kwwasi.c), which
connects to the host over AF_VSOCK port 1021 and serves the program's
file I/O with its own descriptors, cwd and credentials. The host
(js/core/wasi-exec.ts, serveWasiPrograms(), the CLI's --wasi) compiles
the module once and runs each program in a worker of its own
(js/core/wasi-program.ts) with WASI preview 1, or preview 0 adapted.
Requests cross through a SharedArrayBuffer where one can be used, else
with JSPI and messages. kwwasi sends a module only when the host has not
compiled it for that file, resolves paths against the cwd or / by what
exists, and maps open flags from their asm-generic values to the
guest's.
alpine.sh builds kwwasi and kw-binfmt.sh registers it; no image with
them has been built yet, so test/wasi-binfmt.ts brings kwwasi in through
a mount.
With more than one CPU, each CPU's fd_write puts its bytes into one
shared ring (js/core/console-ring.ts), reserving its place inside the
import, so the ring keeps the kernel's order. With the shared transport
the owner reads it (Atomics.waitAsync), independent of CPU 0, and a full
ring makes writers wait; inline and with --worker=messages CPU 0's host
reads it, and another CPU that finds it full posts the records as a
numbered batch instead of waiting for CPU 0.
Output from a secondary CPU no longer arrives as one message per write
nor waits for CPU 0 to suspend: seq 1 200000 on CPU 1 takes as long as
on CPU 0, and a shell on CPU 1 echoes in under a millisecond while CPU 0
runs user code (10 ms before).
ConsoleOutput's unread backlog dropped old chunks with Array.shift(),
which copied a long array per chunk: drop them by index.
pnpm build inlines js/node/cpu-entry.ts where js/node/cpu.ts starts it,
in the Node entries and inside the inlined Node kernel worker (WORKERS
nested), so the package starts SMP CPUs without source files. The page
build serves web/kernel/page/: the bundle without its SMP patch section
(the same bytes when there is none) and, only with a patch, the SMP
bundle it makes as a second hashed asset (kernelSmpUrl, unused until the
page has CPU threads).
A second kernel build (kw_smp.config) runs one instance of the module
per CPU, each in a worker thread on a shared memory. The host's Kernel
is CPU 0 with every device; wasm_cpu_start starts the others through
Platform.spawnCpu (js/node/cpu.ts), which run js/core/cpu.ts: their own
JSPI task switching, the clocks on CPU 0's time base, and console and
exit forwarded to CPU 0's host. The host sets IRQ bits atomically and
ends CPU 0's idle on Atomics.waitAsync of its word, which other CPUs'
IPIs notify. createKernel's cpus option and the CLI's --smp N (which
implies --worker) ask for CPUs; a UP kernel ignores them with a log
line, and more than one CPU runs the interpreter only.
kwemu built with -Dkwemu-atomics makes AMOs atomic, SC a
compare-and-swap against the value LR read, and FENCE a barrier (ABI
7). kwtest gains an smp check (threads on several CPUs counting
through AMOs, LR/SC and a mutex) and skips the park check on an SMP
kernel, which has no parking. The kernel side is in five new patches.