14. Monolith, microkernel, exokernel, library OS

The isolation budget A table of four shapes of operating system against three axes. Monolith, Linux: one kernel address space with every subsystem in it, the whole kernel trusted, by default the copy at the syscall boundary; ember is placed here. Microkernel, seL4: a space per server, the kernel alone trusted, the copy an IPC message. Exokernel, Aegis 1995: raw resources split by secure binding, the thin multiplexer trusted, no copy in the kernel. Library OS, unikernel: one address space, the whole image trusted, no copy; hearth is one, hosting these. what is shared who is the TCB where the copy is monolith Linux; ember is here, with a U bit one kernel space, every subsystem in it the whole kernel: drivers, fs, net by default at the syscall boundary, user to kernel microkernel seL4 nothing by default; a space per server the kernel alone; servers sit outside an IPC message, through the kernel exokernel Aegis, 1995 raw resources, split by secure binding the thin multiplexer; the libOS is yours none in the kernel; the libOS decides library OS Unikraft; hearth is one, hosting these one address space, everything in it the whole image, app and libraries none: a call is a function call Each shape spends the same three things; the rows differ in where the cost lands.

Why this layer exists

The reader has built a kernel and is about to build two more objects: a hypervisor in Part VII and, in Part VI, the unikernels it hosts. These are not history. This chapter names four shapes an operating system can take, and three of the objects in this book are placed among them: the kernel the reader owns, the hypervisor and the VMM. A reader who can place each on the same three axes can say what an isolation claim in any later chapter actually costs.

Every design spends the same three things, which this book calls the isolation budget. What is shared: the address space, the page table, the kernel objects two programs can both name. Who is trusted: the code whose bug breaks the isolation, the trusted computing base (TCB) of that isolation. Where the copy is: the boundary a byte crosses when it moves from one program to another. A design cannot spend none of them. Sharing less costs a copy; trusting less costs an interface that has to be narrow enough to check; removing the copy costs a shared page and therefore a bigger TCB. The shapes are four different ways of making that trade, and chapter 41 comes back to the same three axes to place the isolation mechanisms of Part VIII.

Mechanism

The three axes, from what Part II built

The axes are not new vocabulary; ember already has a worked example of each.

Shared. Chapter 7 put the kernel and every process into one page table. What separates them is a bit in the PTEs, not a second table, so what two ember processes share is everything the U bit does not hide: the kernel’s identity map is there for both, and each other’s user pages are there too, mapped U=1, reachable by a stray address. Chapter 10 is the opposite choice in miniature: a pipe is a kernel page that neither process maps. The processes share a kernel object (the open-file table) and no memory at all.

Trusted. Chapter 7 reduced isolation to two objects: the U bit in the page table and the privilege mode that sret restores. The TCB of ember’s isolation is therefore every line that can set either one wrongly: every map_page call that passes PTE_U, and every path that can write sstatus.SPP or execute sret. That is not small: it includes sbrk, which maps user pages as the heap grows, and the loader that fabricates a frame. But it is countable, and the count is what the word means. A bug anywhere else in ember/ is a crash; a bug there is an escape.

The copy. Chapter 10’s copy_in_user and copy_out_user are the boundary made into code: the kernel walks the page table itself, finds the physical page behind a user address, and moves the bytes through its own mapping, refusing any address that is not a mapped U page. Chapter 13’s spawn argument is two such copies in a row: the parent’s string comes in through copy_in_user, and the kernel then writes it into the child’s stack page, whose address the child finds in a2. No byte reaches the child without the kernel handling it.

Four shapes

A monolith is a kernel in which every service (scheduler, file system, network stack, drivers) runs in one address space at the highest privilege, so a call from one service to another is a function call. Linux is the shape’s working example, and ember is a small one. By default the copy is at the syscall boundary: a program’s ecall enters the kernel at one door and the bytes that cross it are copied. The TCB is the whole kernel, including every loaded driver. By default what is shared, between two programs, is the kernel and nothing else: each has its own user address space over one shared kernel. A program can spend on the shared axis when it asks the kernel to map a page into both address spaces (mmap with MAP_SHARED, POSIX or System V shared memory). Such a page is shared memory, and bytes written to it cross no copy, exactly the trade chapter 10’s exercise (c) makes. fork shares differently: it maps every writable page copy-on-write, read-only in both processes until one of them stores to it and is given a private copy of that page; chapter 16 builds that. Chapter 15 reads Linux from inside a boot of it.

A microkernel is a kernel reduced to what cannot be done outside it. Liedtke’s criterion, in On µ-Kernel Construction (1995), is that a concept is tolerated inside the kernel only if moving it outside, permitting competing implementations, would prevent the implementation of the system’s required functionality. File systems, drivers and network stacks become servers: ordinary programs, each in its own address space. seL4 is the shape’s working example. A program that wants a file sends a message to the file server, and the copy is that message: the kernel moves a few words from the sender to the receiver (a comment in seL4’s copyMRs calls them “IPC MRs”; libsel4/include/sel4/syscalls.h spells MR out as message register). The kernel is the TCB of the isolation between two programs; a server is trusted only by the programs that depend on it. A capability is an unforgeable reference to a kernel object that carries the right to use it; seL4 uses one where ember uses a descriptor, for endpoints, address spaces and the rest. Chapter 17 reads them.

An exokernel inverts the microkernel’s question. Engler, Kaashoek and O’Toole (1995) describe the architecture as a thin kernel that multiplexes physical resources securely and leaves the abstractions to the application’s own library. A library OS is that library: the code that would be a file system or a network stack in a monolith, linked into the program and running in its address space with no special privilege. The mechanism that lets an untrusted library hold a resource is the secure binding: in the paper’s words, a protection mechanism that decouples authorization from the actual use of a resource, performing the authorization only at bind time. The kernel checks once that a program may have a physical page, a disk block or a TLB entry, then gets out of the way. The exokernel’s TCB is the multiplexer, which is small because it manages nothing: it tracks ownership and checks bindings. The kernel has no copy of its own; what crosses between two programs is whatever their libraries arrange.

A unikernel is the library OS with the kernel deleted. Madhavapeddy and colleagues (2013) describe unikernels as specialised, sealed, single-purpose library OS VMs that run directly on the hypervisor, all services from the scheduler to the device drivers to the network stack implemented as libraries linked with the application. There is one address space. There is no copy, because there is no boundary inside the image: a call from the application to the network stack is a function call. The price is the TCB: the application, every library and every driver are all one image, and a bug in any of them is a bug in all of them. Isolation moves outside the image, to whatever hosts it. Chapter 29 builds the idea out; chapter 30 builds and reads a real one.

Placing ember and hearth

After chapter 13, ember is a monolith with a U bit: one kernel address space, one page table shared by kernel and processes, the U bit and the mode bit as the whole of the isolation, and the copy at the syscall boundary. It has a boundary and little else, which is why it teaches the boundary: there is no per-process table to hide the mechanism.

hearth is a library OS whose “applications” are library OSes. It is one image that owns the machine, with no syscall table, and what it runs are unikernel guests. Between a guest and the machine sits a second translation, the G-stage table that chapter 19 builds, and it is the object that makes hearth’s copy line: a guest’s physical address means nothing until the hypervisor has translated it or refused. That is one paragraph of placement; the mechanism is Part IV and Part VII and none of it is used here.

What the budget says about the two floors

wick inherits Linux’s spend. It is a process on a Linux host, so the host kernel is in its TCB (as it is in ward’s, which jails it from a program on the same kernel), and whatever it hands a guest passes through that kernel’s syscall boundary. hearth spends nothing it did not write. There is no host kernel in its TCB and no syscall table on its boundary; every line in the TCB is a line the reader wrote in Part VII. This is what “no Linux in the trusted computing base” means, and the two floors of the book are the two columns of that sentence.

Walkthrough

There is no listing. The walkthrough is five kernels on the three axes, three answers each (Shared, TCB, Copy), and for each answer the file at its pin that justifies it. ember paths are in this tree; xv6, Linux and seL4 are at the pins in labs/ch14/README.md. The Linux files are named, not quoted: chapter 15 reads most of them.

ember (this tree)

  • Shared: one page table for the kernel and every process; the U bit tells them apart (ember/proc.h, ember/proc.c).
  • TCB: all of ember/; in particular every PTE_U mapping (ember/proc.c, ember/syscall.c’s sbrk) and the path to sret (ember/proc.S, ember/trap.S).
  • Copy: copy_in_user and copy_out_user in ember/copyio.c.

xv6-riscv

  • Shared: the kernel; each process has its own user page table (kernel/vm.c: kvmmake, uvmcreate).
  • TCB: the whole kernel; kernel/syscall.c is the table.
  • Copy: copyin and copyout in kernel/vm.c.

Linux

  • Shared: one kernel address space under each process’s own user space (kernel/fork.c).
  • TCB: the whole kernel and every loaded module.
  • Copy: the syscall boundary, entered in arch/riscv/kernel/entry.S; the bytes cross in copy_from_user and copy_to_user (include/linux/uaccess.h).

seL4

  • Shared: nothing by default; an address space is an object a program holds (src/arch/riscv/kernel/vspace.c).
  • TCB: the kernel; servers are programs (src/object/endpoint.c).
  • Copy: an IPC message: sendIPC (src/object/endpoint.c) calls doIPCTransfer (src/kernel/thread.c), which moves the words with copyMRs (src/object/tcb.c).

Unikraft

  • Shared: one address space, application and libraries linked together.
  • TCB: the whole image.
  • Copy: none: a call is a function call (read in chapter 30).

The Unikraft answers are placed from the unikernel definition above (Madhavapeddy et al.), not from a checkout; chapter 30 reads the tree.

Exercises

(a) Place ember after chapter 13 on the three axes. Name the file behind each answer.

Answer

The Walkthrough’s ember list. Shared: one page table for kernel and processes, stated in the header comment of ember/proc.h (“One page table holds everything… what separates the two worlds is the U bit in the PTEs and the mode bit sret sets”) and built by proc_create in ember/proc.c. TCB: the sites a grep for PTE_U finds that map a user page, which are proc_create (code and stack), sbrk in ember/syscall.c, and the one fixed page mem_init maps in ember/mem.c; and the writes that reach the privilege the next sret restores: the frame proc_create fabricates with SPP=0, the csrw sstatus in ember/proc.S, and the sret in ember/trap.S. Copy: copy_in_user and copy_out_user in ember/copyio.c, reached from ember/syscall.c, ember/pipe.c, ember/console.c and ember/fs.c. Everything else in ember/ is outside the isolation claim: a bug in the allocator crashes the machine, a bug in a PTE_U mapping lets a program read another’s pages.

(b) Which of the three axes does chapter 10’s pipe spend, and which would a shared-memory pipe spend instead?

Answer

The pipe spends the copy. ember/pipe.c’s header says it in so many words: neither process maps the page, the writer’s bytes come in through copy_in_user and the reader’s leave through copy_out_user, and “the two processes share nothing”. The kernel’s ring is shared only in the sense that the kernel holds it. A pipe page mapped into both processes with U=1 (chapter 10’s exercise (c)) spends shared instead and gets the copy back for free. The price is on the TCB axis too: each process is now in the other’s TCB, because either can move the cursors, write past the ring, or hand the other a bad pointer, and the kernel has nothing left to refuse because nothing crosses it.

(c) State an exokernel’s secure binding in Engler’s terms, and name the Part II object that ember has closest to one.

Answer

Engler, Kaashoek and O’Toole define a secure binding as a protection mechanism that decouples authorization from the actual use of a resource, and they say it performs authorization only at bind time. The kernel checks once that an application may have a resource (they name physical pages and TLB entries), and later uses need no check. The closest ember has is the file descriptor of chapter 10: open checks the name and allocates a slot in the kernel’s open-file table, the struct file in ember/fd.h records readable and writable when it is allocated, and what the program holds afterwards is a small integer that only indexes its own table. The resemblance stops at the resource. A secure binding is to a hardware resource (a page, a block); an ember descriptor is to a kernel abstraction (a console, a pipe, a file), and the kernel still copies every byte through that abstraction on every use. An exokernel hands out the page and leaves the abstraction to the library.

(d) Why is a microkernel’s IPC copy the same object as a monolith’s syscall copy, and what differs?

Answer

Both are the kernel moving bytes between two address spaces so that neither side ever dereferences a pointer into the other’s. ember’s copy_in_user moves them through the kernel’s own mapping of the user’s page; seL4’s copyMRs moves them from the sender’s message registers to the receiver’s (the call chain is the Walkthrough’s seL4 Copy answer). What differs is who is on the other side. In a monolith the far end of a copy is the kernel, whose code is the TCB. In a microkernel the far end is another program, a server, and the kernel is only the courier. So the same boundary now separates two things outside the TCB, and the TCB shrinks to the courier, at the cost of a message for every service call that would have been a function call.

(e) A unikernel’s TCB is the whole image. State what that buys and what it costs, in the budget’s terms, using chapter 13’s exercise (e) as the worked case.

Answer

Chapter 13’s exercise (e) strips ember on paper: delete the programs as separate address spaces, the stub, the ecall path (the frame save, the syscall table, copy_in_user and copy_out_user) and the U bit as a boundary, and keep the allocator, file system, block driver and console. cat hello.txt becomes a function that calls fs_open and fs_read directly. On the budget it lands where the unikernel paragraph above puts it: no copy, everything shared, the whole image trusted. It buys the removal of every cost the boundary had: no trap, no frame save, no copy, no table, and a smaller image. It costs the boundary’s protection: every bug in the application is now a bug in the kernel. The isolation moves to whatever hosts the image. This is the exokernel’s library OS with the kernel’s last duty, multiplexing, handed to a hypervisor.

(f) Place hearth on the three axes from the spec alone, and say which axis Part IV’s nested paging changes.

Answer

The spec (docs/superpowers/specs/2026-09-29-hp-course-design.md) calls hearth a type-1 hypervisor that is itself a unikernel: “one address space, no host kernel, no syscall table”, entering a unikernel guest, and says chapter 32 boots the ember image “with its userland stripped as a guest”. It puts nested paging in chapter 19 as the lab that is hearth’s chapter zero. On the axes: Shared: nothing between guests; each sees only what the hypervisor maps into its G-stage table. TCB: hearth’s own image and nothing under it: no host kernel, which is the difference from wick. Copy: the G-stage translation, as placed above (chapter 11 already notes that a guest’s ring holds guest-physical addresses the hypervisor must translate or refuse). Nested paging changes the shared axis: chapter 4 says it is two walks with two owners, so the page table stops being one object the trusted code owns alone and becomes two, the guest’s own and the hypervisor’s. The U bit and the mode bit of chapter 7 are the same two objects with new names; the copy line is not a second change, it is where the second table puts the boundary.

Lab

A reading lab: nothing boots. For each of ember, xv6, Linux, seL4 and Unikraft, write three one-line answers, Shared (what two programs share), TCB (which code is trusted for the isolation between them) and Copy (where a byte crosses from one to the other), each with the file or line that justifies it. labs/ch14/README.md lists the sources and their pins. The Walkthrough’s lists are the reference; an answer that disagrees with one is either a mistake or a better reading, and the file named in the answer says which.

Further reading

results matching ""

    No results matching ""