Вся документация
Инструменты
Структура проекта
docs/project-layout.mdОткрыть на GitHubЭта страница пока есть только на английском: документация собирается прямо из каталога docs/ репозитория и поэтому всегда совпадает с кодом. На русском у нас есть руководства.
Where things live in the tree. How the pieces work is in Boot,
Paging and memory, Scheduler,
Interrupts and Profiler; how the Rust side
is layered and written is in Rust in the kernel; the conventions
are in CLAUDE.md and the roadmap in plans/README.md.
C++ is the fundamentals, and everything that sits on them is Rust: there is
no src/base/{block,net,fs}, no virtio and no USB in src/base/drivers/.
src/base/
hal/ Portable HAL contracts: cpu and atomics, the semantic barriers, mmu/pte, irqchip, console, pci, power, Context, IRQ stub symbols, the cpu's random instruction. Each header selects the arch backend at compile time, and common code includes nothing else of an architecture's
arch/
x86_64/ Multiboot2 entry + AP trampoline (boot64.asm, NASM), CPU primitives (asm.asm, asm.h), IDT/GDT, exceptions, TSC/kvmclock, LAPIC/IOAPIC/PIC, PTE encoding (pte.h), GRUB info parsing, the string routines in assembly (stdlib_asm.asm), HAL inline/impl backends. Only arch code, x86-only drivers and three documented exemptions (kernel/main.cpp, kernel/cmd.cpp, kernel/irq_balance.cpp) may include these headers
arm64/ Linux-Image boot + PSCI SMP (boot.S), the boot path itself (main_arm64.cpp), EL1 vectors, GICv3 + ITS (LPIs for PCIe MSI), generic timer, PL011, FDT parser, PCIe ECAM, PTE encoding, the string routines in portable C (stdlib_c.cpp), link stubs for the x86-only entry points common driver code names (x86_driver_stubs.cpp), HAL backends
kernel/ Core: scheduling, tasks, interrupt dispatch, SoftIrq, timers, the timekeeping seam (time.h), locks (spinlock, mutex, seqlock, rwlock), panic and backtrace, the dmesg ring buffer, the command line (parameters.cpp), the interactive shell (cmd.cpp) and its line editor (line_editor.cpp), the input layer (input.cpp), the boot self-tests (test.cpp), the module loader (module.cpp), the Rust FFI bridge (rust_ffi.cpp), the NUMA topology from the SRAT and the SLIT (numa.cpp), the symbol table
drivers/ Hardware: serial, the console (screen.cpp picks EGA text on BIOS or the 8x16-font pixel framebuffer under UEFI), PIT, HPET, RTC, the 8042 keyboard, PCI, MSI-X and MSI, ACPI. No virtio and no USB: both are Rust (src/crates/drivers)
mm/ Memory: 4-level page tables (the virt_to_phys walk, protect_range), the page allocator (fixed-size block allocators) and the zeroing of its free pages ahead (page_zeroer), the pool allocator, the VA allocator, new/delete
lib/ Freestanding stdlib equivalents (stdlib::): list, vector, ring buffer, bitmap, formatting, errors and results, smart pointers. mem_set/mem_cpy/str_len and their like are per architecture (arch/x86_64/stdlib_asm.asm, arch/arm64/stdlib_c.cpp)
include/ Shared headers
src/crates/ The Rust half, one cargo workspace, a directory an area: what the image stands on (base/), its layers (layers/), the drivers by what they drive (drivers/), the hypervisor (hypervisor/), the loadable modules by area (modules/), and the crates with no kernel in them (common/)
kernel/ Rust entry points (rust_init, rust_fini), global allocator, the `sha256` and `crc32` commands, and the `system` provider on the management bus (system.rs: the kernel's version, CPUs, memory, tasks, log and modules, through kcore::system, and the few things about it the host API may change)
base/
ffi/ Raw extern "C" FFI declarations for kernel services
kcore/ Safe Rust wrappers around kernel services: sync, DMA, MMIO, MSI-X, interrupts, timers, tasks, PCI, what the C++ holds of itself (system.rs: its tasks, modules and log copied out) -- and the block, net, TCP and file layers *as a loadable module reaches them*, across the C ABI (inside the image the crates call each other as crates)
kmod/ Runtime of a loadable module: allocator, panic handler, the module! header
events/ The events a task waits on: one a task, which the kernel's objects made on it signal -- a mailbox, a device's queue, an image's -- so that a task that waits for several things sleeps on one; and the table a module's are held in, for the C ABI
random/ The kernel's random pool: ChaCha20 with fast key erasure, seeded from the CPU's instruction (through hal/random.h), timing jitter and the sources that register with it (virtio-rng); kernel_get_random, which the layers and the modules reach through kcore::random; the `random` and `entropy` commands (docs/random.md)
crypto/ ChaCha20-Poly1305 (RFC 8439) in CRYPTOGAMS' assembly -- x86-64's SSSE3 and AVX2 code, arm64's NEON code -- run in the kernel's SIMD sections (kcore::simd), each architecture's integer code where none can be had, and its check at boot; and its two halves on their own, ChaCha20 from any counter block and Poly1305. What TLS's ChaCha20-Poly1305 suites run on, vnet's tunnel (hv.ko's aead.rs) and sshd's cipher (the ssh crate's Primitives). cryptogams/ holds the perlasm sources as they came, with their license and where they came from; src/asm/ what scripts/cryptogams.sh makes of them (docs/tls.md, "The assembly")
hello/ Rust self-test module
layers/
block/ The block layer: the device table a driver registers a `BlockDriver` in (table.rs), the `Disk` the rest of the image reads and writes through (disk.rs), its claims, the partition tables (MBR and GPT) a disk is cut up by, the shell's disk commands (shell.rs), the kernel log written to a raw disk area (disklog.rs) and its provider on the management bus (provider.rs: the disks, their partitions, who holds each)
fs/ The filesystem layer: the VFS (vfs.rs -- the mount table, path resolution, open handles and the file API), the `FileSystem` trait and the filesystems that implement it (ext2.rs; ext4/, over extfmt and through its journal; ramfs.rs, procfs.rs), which of ext2's driver and ext4's a filesystem gets (extfs.rs), the arena of nodes each keeps its tree in (vnode.rs), what boot mounts where (rootfs.rs), the file logs under /logs -- their queue, their writer's task and their rotation (logs.rs, docs/logs.md) -- the shell's filesystem commands (shell.rs), its provider on the management bus (provider.rs: the mounts, their size and free space) and the self-test (selftest.rs)
net/ The network layer, over common/net/netwire: ARP (arp.rs), ICMP (icmp.rs), UDP (udp.rs), the DHCP client (dhcp.rs), the DNS resolver (dns.rs), NAT for what is behind a virtual NIC (nat.rs), TCP (tcp.rs), the HTTP client over either TCP or TLS (http.rs), the shell over UDP (udp_shell.rs), the kernel log over UDP (netconsole.rs), the recycled frame pool (frame.rs), the devices, the `NetDriver` a NIC registers as and the queues between it and the stack (device.rs), a device as the layer's own services hold one (nic.rs), the boot self-test over the formats (selftest.rs), the shell's network commands (shell.rs), wget (wget.rs), its provider on the management bus (provider.rs: the devices and their counters, TCP's slots and connections, ARP, the frame pool) and the C ABI C++ and the modules call them by (abi.rs)
tls/ The TLS client: rustls + RustCrypto + webpki-roots, driven through rustls' unbuffered API, over a transport it is handed as a trait; and with the `pinned` feature, which the kernel's own build leaves off, TLS between ends that know each other's keys: the host API's server and a host's client of another's (pinned.rs: TLS 1.3, a client let in by its key's fingerprint, every wait bounded) (docs/tls.md)
mgmt/ The management bus, in the image: providers registered by name -- the layers', and modules' through the C ABI -- their calls, made with no lock held and counted so that an unregister waits them out, the jobs that take long, and the `mgmt` command (docs/mgmt.md)
ipc/ The message channel, in the image: mailboxes with addresses that are looked up, names in the host's namespace under a module's own, messages, monitors and watches, the router to other hosts' channels and its peers, and the `ipc` command (docs/ipc.md)
drivers/
block/ ahci/ (SATA disks behind an AHCI HBA, by DMA: NCQ, the HBA's MSI, a task for its failures), ata/ (ATA disks behind a PCI IDE controller -- SATA in IDE mode, parallel ATA -- by PIO, polled), nvme/ (NVMe: PCI, MSI-X, admin and I/O queues), virtio_blk/ (virtio-blk, the disk the root filesystem lives on), virtio_scsi/ (virtio-scsi, a SCSI adapter and the disks behind it)
net/ e1000e/ (Intel 82574L, gigabit), igb/ (Intel 82576, I210 and I350, gigabit), mlx4/ (Mellanox ConnectX-3/3 Pro Ethernet, firmware HCA and EQ/CQ/QP), r8125/ (Realtek RTL8125, 2.5GbE), r8168/ (Realtek r8168), virtio_net/ (virtio-net, the card the network comes in on)
rng/ virtio_rng/ (virtio-rng, the host's entropy)
usb/ xHCI host controller (rings, contexts, root-port and hub enumeration) + the HID boot-protocol keyboard on it
virtio/ The virtio foundation the virtio drivers share: the split virtqueue, the transport contract, virtio-pci (modern and legacy) and virtio-mmio v2
hypervisor/
hvarch/ The CPU's virtualization extension: CPUID and the control MSRs, AMD-V (x86/svm.rs: turning it on, entering a guest; x86/svm/vmcb.rs: the VMCB's layout) and Intel VT-x (x86/vmx.rs), the Arm EL2 probe (arm64.rs). Almost all of the hypervisor's unsafe, so that the rest of it has next to none (docs/hypervisor.md)
hv/ The hypervisor above the CPU, safe but for the one call that enters a guest: the machine's extension and which CPUs it is on for (machine.rs), guest memory and its nested page table (memory.rs, npt.rs), the VMCB's policy and the exits (svm.rs), the VM (vm.rs), the built-in guests (guests.rs). Neither this nor hvarch is a default member of the workspace: they are compiled only into the hv module, so a kernel without it carries no hypervisor at all
hvboot/ The loader a guest of hv is started in, by PVH (hypervisor/hv/src/pvh.rs), to boot the kernel its own disk's GRUB would: legacy virtio-blk, GPT and MBR, ext2/3/4 read-only, grub.cfg and grubenv, Linux's 64-bit boot protocol -- a program of the guest's, built on its own and linked at 1 MiB by hvboot.ld into the PVH ELF the system image keeps as /lib/hvboot (docs/hypervisor.md, "A guest's own kernel")
modules/ Loadable modules, each built into a .ko (docs/modules.md), by area
cluster/ cluster (the cluster's registry on every host, through raft over ipc; docs/cluster.md), ipcnet (the message channel between hosts; docs/ipc.md), and raftmember -- no module, a library the modules that keep a raft group link: the member as a task over raft's rsm and a log in a folder of the root, its messages over ipc to its name on every host, commands handed to the leader, raft's membership kept to the voters and learners the group's state names; what every group's module does with its member -- its start over its log, with the `begun` mark that keeps a member whose log is gone from starting as the one it was, its stop, a probe and `recover` (host.rs) -- and for a group whose hosts are offered it, NBS's and vnet's, the offer, the listener of a host in no group, the member file and the members' commands (offered.rs); the group's own (its state, how its hosts are its nodes, its own messages) is the module's, through raftmember's `App`
hypervisor/ hv (the hypervisor -- its guests, their devices, and their switch with its DHCP server)
mgmt/ api (the host API; docs/api.md)
net/ sshd (an SSH server), netload (a UDP load test from either end), tlsbench (what TLS 1.3 costs this machine), vnet (the cluster's networks for VMs: a raft group of its own over raftmember's offered group -- networks, ports, public addresses, the cluster's firewalls -- the `vnet` command and provider; plans/vnet.md)
storage/ netblk (a disk served over UDP, zero-copy), blkload (a block I/O load test), nbs-mds (NBS's metadata service: the NBS cluster's members, its chunk servers and its volumes through raft over ipc, on raftmember, with the `nbs` provider; what a cs asks of its host's mds answered; `nbs io`, a volume's bytes through the cs's from the shell; docs/nbs.md), nbs-cs (NBS's chunk server: the devices the host's mds gives it, held with queues of its own and formatted as NBS's, the chunks on them written, read, fenced, opened, closed and given back as the metadata says, a request it has not checked asked of its host's mds first; docs/nbs.md), nbsload (a load test on a volume through NBS's client), and two libraries, no modules: nbsdrive (NBS's client driven over ipc, a volume's session in a mailbox of its own -- linked by nbs-mds.ko's `nbs io`, nbsload.ko and hv.ko's `nbs:` disks) and nbstrace (the records of a volume's requests, `trace on nbs`, at the client and at the chunk server; docs/tracing.md)
tools/ edit (a text editor for an SSH session with a terminal)
test/ hello; modtest, which the boot test loads; slowexit, an exit that takes its time; heapbench, what the kernel heap costs the Rust that allocates from it; numabench, each NUMA node's memory as each node's CPUs reach it
common/ The crates with no kernel in them and no unsafe (each `forbid`s it), by area: what a module, hvboot and the host's fuzzers link as they are, since a module is linked on its own and cannot link a layer
crc/ CRC-32, CRC-32C and CRC-16, each as a message has it and as the bare register, slicing by eight: the one copy of each GPT, the disk log, ext4 and raft's log are checked by (tests/crc-test.py)
calendar/ The calendar date and the time of day of a Unix time, in UTC (Howard Hinnant's civil_from_days): the one copy an X.509 certificate's validity, a guest's RTC, the dates in a VM's log and a file log's stamps are written with
boot/ bzimage/ (a Linux bzImage as a loader reads it, by the 64-bit boot protocol: its setup header held to what that protocol needs, and the zero page a loader hands the kernel -- the header copied in, the command line, the initrd, the RSDP and the memory map; hv loads a guest's kernel by it, and hvboot one off a guest's own disk)
codec/ Bytes in order: little-endian integers and strings with their lengths in front, every read checked -- what a replicated state's commands, answers and snapshots are made of (the registry's, NBS's metadata's)
cluster/ raft/ (Raft, the consensus protocol: a member as a state machine with no I/O -- node.rs: elections, PreVote, CheckQuorum, replication and its flow control, the commit rule, snapshots sent in pieces, learners and one-server membership changes, leadership transfer, ReadIndex -- its messages as bytes (wire.rs), a storage in memory with a group's bootstrap (storage.rs), the log on disk (log.rs), the replicated state machine (rsm.rs) and a member made a group of itself alone (recover.rs); docs/raft.md), registry/ (the registry of a cluster's hosts: their keys, addresses and labels, the hosts removed and the invitations open, and the commands that change it; docs/cluster.md), rsmkit/ (what a group's state machine over raft's rsm is made with besides its own: the digests its members hold each other's to, a snapshot read as a stream -- nbsmeta's and vnetmeta's), members/ (a group's members, as a group whose hosts are offered it keeps them -- NBS's metadata, vnet's state: the group, its members by incarnation, those removed, `Init`, `Add` and `Remove` as applied, who votes -- the first five, the registry's hosts too -- and the rules a snapshot read back is held to)
ipc/ ipcwire/ (ipcnet's wire: the frames two hosts say to each other inside TLS, the decoder that takes bytes as they come and the assembler that puts messages back together, and ipcnet's control mailbox), mgmtwire/ (what the management bus carries: JSON as the bus takes it -- whole numbers only, no key twice, every limit checked -- a writer that keeps to the rules it reads by, a method's parameters taken strictly by name, and the status codes)
net/ netwire/ (what is on the wire: the Ethernet, ARP, IP, UDP, ICMP and TCP headers read and written through byte slices, the internet checksum, a UDP datagram taken apart or put together whole, addresses parsed and printed -- the network layer is built on it, and so is a module that builds or rewrites frames itself), web/ (HTTP/1.1 and WebSocket as the host API serves them: a request read in place with a limit on everything and nothing allocated, a response's head nothing can be injected into, WebSocket frames, SHA-1 for the handshake, IPv4 networks for an allowlist, and a self-signed P-256 certificate with its key in PKCS#8), ssh/ (an SSH server's protocol; the sshd module serves it, docs/sshd.md), sftp/ (an SFTP server, version 3 as OpenSSH speaks it, over a trait of the files it serves -- the sshd module's over kcore::fs, the net fuzzer's a model -- run as a session's subsystem; docs/sshd.md, "Copying files"), firewall/ (a VM's firewall: its rules and how a person writes them, what of a frame they judge, the table of flows a port keeps, and the words a change of the rules is asked in -- hv's switch, `hv fw` and `vnet fw` use it; plans/vnet.md), vnetmeta/ (vnet's state: the cluster's networks, their ports, the public addresses and the cluster's firewalls, the commands that change them, an attach answered and an address given as pure functions, its snapshot as a stream; plans/vnet.md), vnetwire/ (vnet's tunnel between hosts: the datagram a cluster network's packet crosses the underlay in, sealed and opened with ChaCha20-Poly1305 -- the counter the nonce, the header the associated data -- the window of counters a key has seen, and the messages keys go in; hv.ko seals by it, tests/fuzz/hv holds it to a model)
storage/ nbscs/ (NBS's chunk server as its devices hold it: a device's format of its own -- its superblock twice, its fences and its table of slots each in two copies, every record with a sequence number and a CRC seeded with the format's id, so a torn write leaves the other good -- and the engine a cs runs over a device of the caller's: fences durable before they are answered, open marks before a generation's first write, a chunk held by its number and incarnation, a slot zeroed before it is taken, a close after its data; plans/nbs.md, docs/nbs.md), nbswire/ (what NBS's services say over the message channel: a client's requests to a cs and its answers, a cs's questions to its host's mds and what it is told, each read whole and held to its limits), nbsmeta/ (NBS's metadata, the state every host's mds keeps through raft: the NBS cluster's id and name, its members -- a host and the incarnation its mds made -- in the order they joined, the voters the first five, and the members removed, never taken again; each host's chunk server and its devices, the volumes, their chunks and the replica sets they share, placed by place.rs; its snapshot written and read back as a stream, and its digest every 64 entries; plans/nbs.md, docs/nbs.md), extfmt/ (the ext2/3/4 on-disk format as bytes: views of the superblock, group descriptors (32 and 64 bytes), inodes and their extra fields, extent trees and block maps, directory blocks (their checksum tails, an htree's index blocks) and extended attribute blocks; every checksum metadata_csum and gdt_csum put on them, computed as the kernel computes it; what a driver that writes through a journal, by extents, may do with a filesystem's features (features::classify); the journal's own format, JBD2's (jbd2.rs), and what replaying it writes worked out as a plan before anything is written (recovery.rs) -- hvboot reads through it, and so does the kernel's ext4 driver), diskimage/ (a cloud's disk image made raw: QEMU's qcow2 -- versions 2 and 3, every cluster size and kind, extended L2 entries -- read through a source and written through a sink of the caller's, its holes kept, its compressed clusters inflated by a DEFLATE decoder of its own whose every answer is zlib's, and a file of any other kind named by its first bytes; and an ISO 9660 of a few files with Rock Ridge's names, cloud-init's NoCloud seed -- the hv module serves it as `hv convert` and `hv create <name> <url>`)
text/ conf/ (a configuration file's text as a strict subset of TOML: `key = value` a line, strings with TOML's escapes, whole numbers, booleans and lists of strings, and nothing else -- a key the file does not have, or one given twice, refused with its line; a VM's vm.toml and the host API's api.toml are written in it), edit/ (a text editor for a terminal: xterm's keys decoded, the file's bytes line by line and back out byte for byte, undo, the selection, finding, and the screen drawn a changed row at a time; the edit module runs it in an SSH session)
vendor/ The sources of the external crates (rustls and the RustCrypto and dalek crates tls, ssh and web depend on, sha2, zeroize, and what std itself resolves to), so that a build runs `cargo --offline`; scripts/vendor.sh refreshes it
rust-toolchain.toml The dated nightly everything is built with
build/ Linker scripts, GRUB configs, the awk script that makes the module export table; image/, the system image's GRUB entries and default /etc/rc (docs/install.md)
scripts/ Build, run, debug and GDB helpers, nos-install and nos-deploy.py, which put the system image on a server (docs/install.md), installer/, which builds the installer ISO a server boots to make a disk nos's own (docs/install.md, "From an ISO") and holds install.sh, the one-line installer a provider's rescue system runs -- every release carries it, and https://nos-os.tech/install.sh (web/public/install.sh) runs the newest's (docs/install.md, "From a provider's rescue system"), nosctl, the host API from the command line (docs/api.md), and demo-stand/, three hosts for trying the panel on (its README)
tests/ The gates (docs/testing.md), a runner each: the smoke boots, the tests that boot nos under QEMU and drive it, and those that build a fuzzer or a check of fuzz/ below and run it on the host; with what only they use -- hub.py, the LAN of QEMUs the cluster's tests run on
fuzz/ The fuzzers, host programs built from the kernel's own sources and run by their gates above: hv/ (the hypervisor's devices, its run loop, the guests' switch and NAT; hv-fuzz.py), net/ (the network layer, TLS, sshd and its SFTP server, against a model of the world around the machine; net-fuzz.py) and fs/ (the block and filesystem layers, on disks with a write cache and a power switch, the images made and judged from the formats; fs-fuzz.py). common/ is what net/ and fs/ share, each including it as a module of its own: the kernel's C++ half stood in for, its tasks run one at a time with the lock rules checked, and the runner that forks each input. cpp/ is the kernel's C++ itself -- the device tree reader and Board, Multiboot2's tags, the ACPI tables, the memory map, the command line, the GRUB environment block, the module loader, the printf, the page tables, the heap -- compiled for the host under ASan and UBSan, a program a target, by its own Makefile, over stand-ins for the kernel around each (cpp/common/) and a host HAL that takes the place of each arch's inline one (cpp/host/); cpp-fuzz.py. insn/ is the hypervisor's MMIO decoder and guest page walker on their own: the decoder held to the assembler, cut short at every length and fed random bytes, the walker to page tables built by hand; insn-test.py. extfmt/ is the ext2/3/4 format crate over filesystems mke2fs makes: every checksum held to e2fsprogs', bytes changed with e2fsck held to agreeing, and the images walked damaged at random; extfmt-test.py. hvboot/ is hvboot's partition, ext and GRUB readers and its bzImage header over a disk image: what it would boot off one, read by its own code to compare with e2fsprogs', and the same image with its metadata changed at random; hvboot-test.py. diskimage/ is the disk image converter over qcow2 images and DEFLATE streams: converted to compare with qemu-img, decoded to compare with zlib, and the images with their metadata changed at random; diskimage-test.py. edit/ is the editor, run on sessions of keys, files saved back byte for byte and random sessions on a terminal of its own; edit-test.py. web/ is the host API's wire crates, web and mgmtwire: known answers, every parser fuzzed, and the certificates they make judged by OpenSSL and Python's ssl; web-test.py. raft/ is the raft crate: known answers, the known traps played out step by step, groups of one to seven fuzzed over a network that loses, doubles, reorders and cuts and held at every step to Raft's properties, the wire fed noise, a member fed messages no correct member sends, every allocation held to the kernel heap's 512 KiB block (heap.rs), and the mutants each rule taken out must make fail (mutants.py); raft-test.py. nbs/ is NBS's crates held to models of their own: the metadata (nbsmeta) -- every command's answer and everything it shows, its placement against the plan's rules, an fsck of its own after every step, its snapshot read back in pieces, spoiled and continued, and its digests; the chunk server's engine (nbscs) over disks with a write cache through power cuts, torn sectors and rot, every fence, open mark, close and sector held to what it may be after each; and NBS's messages (nbswire) read back and fed noise -- with mutants of its own (mutants.py); nbs-fuzz.py. crc/ is the CRC crate held to each CRC's definition, computed a bit at a time, and CRC-32 to zlib's; crc-test.py. Outside src/crates, whose .cargo/config.toml would make any cargo build under it a kernel build
bench/vm/ A VM under nos against the same VM under KVM on one server: the benchmark suite the guest runs at boot (guest/), the server's Linux side that makes the image and runs it under QEMU/KVM pinned where nos's hv would put it (host/), the workstation's scripts that take the server between the two and fetch the results (kvm.sh, nos-deploy.sh, nos-run.sh), and every run's results so far (results/)
docs/ This directory
plans/ The roadmap