SchOS/docs/plan
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz 9e6d8dd4e3 sockets: a descriptor can cross between processes
sendmsg/recvmsg with SCM_RIGHTS. Item 1 of docs/plan/foundations.md and
mechanism 1 of docs/plan/hybrid.md, which are the same primitive seen from two
directions: Wayland's wl_shm_create_pool passes a file descriptor with no
integer-shaped alternative, and handing a driver process the device it is
allowed to touch is the same act. Both plans stopped here.

Linux's structures byte for byte -- msghdr, cmsghdr, the CMSG_ macros -- because
the programs that need this are not ours. libwayland and toybox both call
recvmsg with Linux's headers and would not notice a friendlier door.

The delivery rule is the whole design. A batch of descriptors is pinned to the
stream position of the first byte of the message that carried it, and that has
two halves: a reader arriving at that position is handed them, and a reader that
has not reached it is stopped SHORT of it. Leave out the second half and a
program asking for 4096 bytes swallows three messages and is handed one
message's descriptors, with nothing in the result saying which. socktest checks
exactly that: two one-byte messages, an eight-byte read, one byte back.

The kernel holds a reference to every descriptor in flight, so a sender may
close its own copy the moment sendmsg returns. Giving that reference back is the
part that leaks if it is not written down, and there are three ways a message
ends:

  - received with room            installed in the receiver's table
  - received without room, or by
    plain read(2)                 closed; MSG_CTRUNC for the first case
  - never received, socket closed closed by sockclose

The middle row looks like a choice and is not: holding kernel references for a
receiver that has proved it is not looking is a leak with extra steps.

No garbage collector. A socket descriptor sent over that same socket and never
received holds a reference to the socket that holds the reference to it, and
neither close reaches zero. Linux carries several hundred lines for this.
Nothing on either plan passes a socket over a socket -- Wayland passes memory,
the driver work passes devices -- so it is a bounded leak that is documented
rather than a silent one.

Fourteen checks in cmd/socktest, and every one moves data through the descriptor
rather than inspecting it. The descriptor passed is always a pipe end, because a
pipe announces its own lifetime: a read of a pipe whose writers are all gone
returns 0, which turns "was the kernel's reference released" -- otherwise
invisible from userspace -- into a value a test can compare.

Two bugs fell out, neither in the new code:

  - sockpair() never set the socket's domain, so every socketpair() socket
    claimed domain 0. Invisible while the data paths asked only whether a socket
    was AF_INET or AF_NETLINK, since zero answers "neither" correctly.
    SCM_RIGHTS asks "is this AF_UNIX", and zero is wrong for that one.

  - pipe_poll() reports POLLHUP but not POLLIN at end of file, so a non-blocking
    read of a pipe whose writers had all gone returned EAGAIN forever instead of
    0 -- a program that polls and reads spins waiting for an end that already
    happened. sockreadable() always had the equivalent condition; the pipe path
    did not. Found because the test helper for "is this descriptor closed" is a
    non-blocking read of a pipe.

projects/schcom/README.md said SCM_RIGHTS was done for a long time while nothing
in the kernel implemented it, and an entire GUI plan was drawn on that line.
It is true now, which is not the same as it having been right, and the README
says so.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
2026-09-13 19:49:37 +02:00
..
1.0.md schfs: records at arbitrary offsets are packed, and the compiler is told 2026-09-12 17:56:36 +02:00
foundations.md sockets: a descriptor can cross between processes 2026-09-13 19:49:37 +02:00
hybrid.md sockets: a descriptor can cross between processes 2026-09-13 19:49:37 +02:00
init.md init: a hang is as detectable as a death, and PID 1 comes back 2026-09-13 14:27:22 +02:00
README.md docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00
roadmap.md net: a frame wakes the stack, instead of waiting for the clock 2026-09-12 17:23:46 +02:00
schapi.md docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00
wayland.md docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00

What happens next

Everything in this directory is unbuilt. When a piece of it is finished it leaves — deleted from here, rewritten as a description in ../architecture/. See the rule.

Read 1.0.md first.

It draws a finish line and puts most of the work below on the far side of it. Anything not named there is not being worked on, and the documents in this directory describe more than 1.0 contains.


The three current decisions

Taken together, because they turn out to need the same foundation.

wayland.md The GUI stack becomes Wayland. SchWM and SchDE are deleted; Schcom survives and changes its wire format.
hybrid.md The kernel becomes hybrid — drivers move out into userspace processes, starting with the GPU.
init.md PID 1 stops being a process and becomes a role the kernel guarantees is filled.

And the one they all wait on:

foundations.md Descriptor passing, shared memory, sockets in the filesystem. The critical path.

And the one that says which parts of the above are actually being worked on:

1.0.md The finish line. Four gates, and everything else explicitly deferred.

Two longer-horizon documents sit behind these: schapi.md, the API layering and the compatibility promise, and roadmap.md, which holds everything still open that is not one of the three above.


The order

Set by 1.0.md, which is the authority. In short:

0. Fix what is already wrong — first

Not a document of its own; it is Gate 0 of 1.0.md, assembled from the What it does not do sections in ../architecture/.

Before any new capability, and the reason is the one that put netdev_selftest() before the TCP/IP stack: a compositor built on a kernel with an unexplained hang and a socket layer that reports success for things it did not do will fail in ways indistinguishable from its own bugs.

1. foundations.md — the critical path

Both the Wayland work and the hybrid work stop here. Descriptor passing and shared memory are the substrate for handing a buffer to a compositor and for handing a device to a driver process. Doing it once for both is the entire reason these are one plan rather than three.

2. init.md — before the desktop, not after

A compositor being brought up for the first time crashes constantly, and something that restarts it and says why is worth far more during that work than at the end of it.

3. wayland.md — with the GPU driver still in the kernel

W1–W3 and a terminal. W4 and W5 are post-1.0.

4. hybrid.md — after 1.0

Deliberately last: designing a userspace driver interface with no driver consuming it produces an interface that is wrong in ways nobody can see. The compositor is the demanding consumer that makes the interface judgeable, so it has to exist first.


In one sentence

Fix what is broken, build the descriptor-passing and shared-memory substrate, make init survivable, put a terminal on the screen — and only then use the compositor as the pressure that shapes the userspace driver interface.


What this plan does not address

Stated here so it is not mistaken for covered:

  • No IOMMU, so the hybrid work isolates against bugs and not against a hostile driver.
  • No page cache, so foundations.md delivers a memfd and not a general answer to shared file mappings. The general answer is still owed.
  • No dynamic linking, so no Mesa, no accelerated clients, and no third party shipping a .so for anything.
  • A new compatibility surface between PID 1 and PID 2, created by a plan whose own schapi.md §3 spends a section warning about those.
  • The three open networking items — getsockname, routing, and interrupt-driven receive — are untouched by any of this and still open. They are in roadmap.md.