Execution model
Syx targets IA-32 and runs on one CPU. The kernel runs with interrupts
disabled: every IDT entry is an interrupt gate and the only
sti are the return to user mode and the idle loop. The kernel
is therefore never preempted, and that is the only mutual exclusion most
kernel data needs. There are no locks in the kcall paths.
The cost is explicit: the length of a kernel path is time during which IRQs wait, and timer ticks beyond one pending period are lost. So kernel paths must be short and bounded; scans of all pages or all page-table entries are not allowed on frequent paths. User code is preempted at the end of its time slice; the scheduler picks the ready thread with the highest weight, with ageing.
User code enters the kernel through a trampoline page mapped in every
process at 0xB0000000 (int $0x91). All
arguments and results are 32-bit registers; larger data travels through
validated user pointers. Errors are negative values that encode whether
they come from the kernel or from a server, a category and a code.
Objects and handles
A handle is a per-process capability: an index, a 15-bit generation and a set of rights. The object it names is shared by every handle to it. Rights live in the handle, capabilities in the object; an operation needs both. A stale handle is rejected by its generation. Handles move between processes during an invoke in three modes: borrowed for the duration of the call, transferred, or cloned.
| Object | Role |
|---|---|
VMO | Memory object; mapped, read, written, resized; may have a pager. |
RES | Resource hosted by a server process; the target of an invoke. |
PAGER | Handler in a server that supplies the missing pages of a VMO. |
WATCHER | Waits on many objects: bindings with a filter mask and a tag, level-triggered. |
OPERATION | One-slot completion object: status, result and optionally a handle. |
TIMER | Signaled at a deadline, optionally periodic. |
CELL | Up to 32 bytes with a lock owned by a process; a held lock is a request queued on an OPERATION, never a wait. |
PROCESS | Address space, threads and handle table. |
IRQ | A hardware interrupt line delivered to a user-space driver. |
INTERRUPT | Per-thread object used to deliver POSIX-style signals to user code. |
Each object has a 32-bit signal mask, which is state rather than events. A watcher reports a binding when its pending bits become non-zero and keeps reporting it until they are cleared; pending bindings take turns, so one object that stays signaled does not hide the others.
The invoke
The invoke (kcall 68) is a synchronous, migrating-thread call. The calling thread checks the handle, copies the request, switches to the server's address space and returns to user mode in the server's handler, on one of the server's invoke stacks. When the handler ends (kcall 69, or a plain return) the response and its handles are copied back and the thread returns to its client. No server thread is involved and nothing is queued in the kernel.
| Limit | Value |
|---|---|
| Request or response data | up to 1024 bytes, a multiple of 4 |
| Handles per request or response | up to 4; created in two phases, all or nothing |
| Invoke stacks per server process | 16, of 64 KiB, with guard pages |
| Kernel stack per thread | 8 KiB, shared by all its nested invokes |
| Nesting today | 3 levels, enforced by free kernel stack |
Bounded nesting
A handler may invoke another server. The depth is bounded twice: by a
maximum IPC level, and, before that, by the space left on the thread's
8 KiB kernel stack. Each level costs about 1.6 KiB; the
deepest path a handler can start without invoking again was measured at
about 2.1 KiB. The kernel refuses a new level with
KERR_INVOKE_TOO_MANY_NESTS when less than 3712 bytes remain,
which allows three nested levels today. A canary at the bottom of every
kernel stack is checked on each schedule and invoke, and the kernel
builds with a per-function stack usage limit, so a new large frame
breaks the build instead of the stack.
Handlers never sleep
A handler runs on its client's thread and holds one of the server's sixteen invoke stacks. A handler that sleeps keeps both, so it makes other clients wait or fail; its client cannot be interrupted while it is inside the server; and a wait that depends on another request to the same server is a deadlock.
Syx therefore moves every wait out of the server. A handler either
answers, or starts the work and answers at once; the client waits
outside, at IPC level 0, on an OPERATION it passed with the
request. The server completes it later from its own threads (a watcher
loop and a few workers). This was introduced service by service
(pipes, wait4, the terminal, then the filesystem), measured
with a kernel inventory of every wait made inside a handler, and then
enforced:
A thread running a handler on behalf of another process gets
KERR_INVOKE_WAIT_IN_HANDLER at once, without sleeping, from
a sleep, a wait on an object, or a wait with a deadline. A poll still
works. Futex waits on leaf locks, held for a few instructions, are
allowed and reported. A server's own threads may wait: they hold no
client.
Invoke stacks
Even with no handler sleeping, a server can run out of invoke stacks: a client preempted at the end of its time slice inside a handler keeps its stack until it runs again. With many ready clients in a tight loop, more than sixteen can be inside one server at once.
Since ADR 0028 a pure client (a thread at IPC level 0 whose
process hosts no resource and no pager) waits for a stack instead of
failing, and freed stacks are handed to waiters in FIFO order, so a new
request never overtakes them. The argument that this cannot deadlock is
the previous rule: such a client holds nothing the holders need, and
the holders are handlers that need only the CPU. Pager requests wait in
the same queue. Any other invoke with no free stack still fails at once
with KERR_INVOKE_NO_STACK.
VMOs and pagers
A missing page of a VMO with a pager is requested by a kernel-initiated invoke into the pager's process, on the faulting thread: a page fault in one process runs pager code in another. The pager supplies the page with a kcall, either from a buffer or, for a filesystem, directly from the VMO the device read into.
A pager that has started a device read may answer
PAGER_PENDING. Its invoke stack is released at once, and the
faulting thread sleeps in the kernel until the request is closed: by a
supply, by an explicit failure, by a resize, a pager change, or the death
of the pager's process. The request is recorded before the pager is
called, so a second fault on the same page joins it instead of invoking
the pager again.
Asynchronous filesystem
The filesystem servers (fatfs, ramfs,
bifs) share a library, fscore, that keeps one
resizable VMO per file node as its cache, kept coherent by the write path,
and a per-mount buffer cache for metadata. Device reads go through
fscore; the backend maps a file block to a device block.
-
Two-step requests. Every request keeps a synchronous
form that never waits in the server. Only the three requests that may
need the device — read, lookup, and directory read — have
an asynchronous form completed on an
OPERATION. - Server threads. Each server has a watcher loop that completes device reads, and four workers with a bounded queue of 64 jobs for the requests that must wait for a lock or for the device. Past the bound a request is answered busy and the client retries.
-
No open-file state in the server. Requests carry their
offset (
readat/writeaton the node). The file position is POSIX state, kept by the POSIX layer; a description shared afterforkkeeps its position in aCELL. -
Writable storage.
ramfshas no fixed limits on files or sizes and may use half of RAM; FAT is read-only.
The POSIX layer
Syx is not Linux; it emulates Linux for programs linked with musl. Whatever exists only because Linux programs expect it lives in the emulation layer, never in the kernel or the native services.
-
posixrt runs inside every POSIX process. musl calls it
instead of trapping, through a table of Linux i386 syscall numbers. It
holds file descriptors, positions and signal state, and implements
forkandexecveitself; it stays in the process across both. -
svc/posix is the POSIX server: pids, process groups
and sessions, zombies and reparenting, pipes,
wait4,alarmand interval timers. -
Blocking calls such as a pipe read or
wait4returnIO_PENDINGfrom the server and complete on anOPERATION; posixrt waits with a deadline and is interruptible by a signal.selectandpolluse one readiness wait across pipes and terminals, with the signal mask applied atomically forpselect. -
Faults reach posixrt and become
SIGSEGV,SIGBUSorSIGFPE; a bad pointer passed to a syscall becomesEFAULT.
Time
The kernel knows only a monotonic clock with microsecond resolution (the PIT at 1000 Hz, with the current period read from the counter) and a timer queue with no fixed limit. Date and time of day belong to a user-space time service, which reads and sets the CMOS clock through a separate RTC driver and publishes the offset in a page shared with every POSIX process.
Measurement
Performance work starts from measurement. The profiler records tick samples, kernel time per entry reason (using the TSC, since the kernel runs with interrupts off), invoke time per server, and per-syscall counts and times in posixrt. A session is controlled from inside Syx and reported on the host. Run-time log levels can be set per module without rebuilding.