How the kernel works
A plain walk-through of how WillowOS is put together.
The short version
WillowOS runs its own kernel, written in Rust from scratch. It isn't Linux or BSD underneath. It's a hybrid kernel: the core parts that need to be fast live in the kernel, and the riskier parts, like the code that handles secure web connections, run outside it as normal programs that can crash and restart without taking the system down.
Top half runs as normal programs. Bottom half is the kernel. The dashed line is where every request from a program gets checked.
What's in the kernel
- Scheduler. Preemptive, ticking 1,000 times a second. Spreading apps across all CPU cores is still in progress.
- Memory. Each program gets its own address space, laid out randomly (ASLR). Forking copies pages only when they change. Every kernel stack has a guard page under it so an overflow gets caught instead of corrupting memory.
- CPU protections. SMEP, SMAP and UMIP are on, so the kernel can't be tricked into running or reading program memory by accident. Spectre v2 protection is on, and branch predictions get cleared when switching between programs.
- Files. A virtual file system with NovaFS underneath (more below), plus FAT and exFAT for USB sticks.
- Network. A custom TCP/IP stack with DHCP and DNS, a WireGuard VPN, and a firewall that blocks incoming connections by default.
- Drivers. NVMe and SATA disks, USB, Intel network cards, HD audio, and the virtual devices used for testing.
The kernel is written in no_std Rust. Rust stops whole kinds of memory bugs at compile time, the kind behind a lot of the worst security holes in other systems. The rules say kernel code never uses unwrap(), and nothing allocates memory inside an interrupt handler.
What runs outside the kernel
The desktop, the apps and some drivers run as normal programs in user mode. That means a bug in them can't touch kernel memory.
- The TLS service. All secure web connections (TLS 1.3) are handled by a separate service. If it crashes, a supervisor restarts it, and a crash-loop breaker stops it from restarting forever.
- USB input. A user-mode keyboard and mouse driver exists and is opt-in for now. If it isn't running, the kernel's own driver takes over.
These services talk to the kernel through shared request and completion rings, so they don't pay for a system call on every small message. Moving more drivers out this way, including graphics, is planned.
How programs get limited
Every request a program makes goes through one gate, the system call layer. There are over 75 native system calls, kept small on purpose. New ones get added only when a feature needs them. Network, device and file requests are each checked against what that program is allowed to do. If the answer is no, the program gets "access denied" and the attempt is logged.
- Apps with a permission list get only what the list says. Anything not listed is denied.
- Programs you download without one (Linux programs, for example) can read your home folder, but can only change files in their own folder and the folder you started them from. They get no network.
- The file picker hands an app one file you chose, not your whole drive.
- Honest gap: a few built-in programs without a permission list still have full access. Locking those down is a later step.
Linux programs use a separate compatibility layer that currently handles 88 Linux system calls. That's enough for test programs, not real apps yet.
Storage: NovaFS and DuperDB
NovaFS is the file system. It's copy-on-write, so a change never overwrites the old data in place, which means a crash mid-write can't leave a file half changed. Turn on encryption and each file is encrypted with AES-256-GCM, and the disk unlocks with your passphrase at boot. Because old data sticks around, the system can take a snapshot of your files every hour, and the Rewind app can take them back. Ctrl+Z in Files works the same way.
DuperDB is a small database built into the kernel. It holds settings, file tags, the activity timeline, saved passwords and which services are turned on. Every change is all or nothing, it keeps 64 past versions so settings can be undone, and its pages can be encrypted with the same passphrase. It has its own space on the disk, apart from NovaFS. Database calls only happen from normal program context, never from interrupt handlers, and nothing else gets locked while it's held, so it can't cause a deadlock.
Booting, updates and crashes
- Boot. UEFI and older BIOS PCs, through a patched copy of the open-source rust-osdev bootloader.
- Updates. Every update is signed (ECDSA P-256). On UEFI PCs a new version boots on trial. If it doesn't come up, the old version boots again and your files go back to the snapshot taken before the update.
- Crashes. If the kernel crashes, it records what happened and restarts. If it crashes several times in a row, it boots into safe mode and opens the Recovery Center, which can read the boot log and check your files.
How it's tested
Every change has to boot in a virtual machine and pass the built-in self-tests before it can merge. There are 170+ of them right now, covering things like the crypto code, the permission gate, and the database surviving a crash in the middle of a write. The tests run inside the real kernel at boot, not in a separate test harness, so they test the code that actually ships.
Outside code
Almost everything is mine. The kernel uses a handful of small outside Rust crates (x86_64, spin, pc-keyboard, lz4_flex, ruzstd and a few others), all under MIT or Apache licenses. There's no GPL code in it, and no code copied from Linux or Windows. Where I needed hardware details, I wrote my own code from datasheets and public specs.
Back to the homepage