$ show hexagonal-sun/moss-kernel
This repository implements 'moss', a monolithic, Unix-like operating system kernel written in Rust, targeting AArch64 (with stubs for x86_64). It boots on QEMU and aims to run unmodified Linux userspace binaries (e.g., bash, coreutils, strace) by providing a Linux-compatible syscall interface. The kernel features an asynchronous core: all non-trivial syscalls are async functions, and the scheduler (EEVDF) and synchronization primitives are designed for async operation. The architecture includes a Hardware Abstraction Layer (HAL) via the `Arch` trait, but the majority of the code is ARM64-specific, covering boot, exception handling, MMU, interrupt controllers (GICv2/v3), UART drivers, timers, RTC, virtio, and a virtio-GPU display driver. The kernel provides a full process model with clone, execve, signals, futex, epoll, inotify, ptrace, and POSIX credentials. Memory management includes demand paging, copy-on-write, mmap, brk, a slab allocator with per-CPU caches, and a buddy allocator for physical frames. The VFS supports multiple filesystems: tmpfs, ext4 (via the ext4plus crate), FAT32, procfs, devfs, sysfs, and a cgroupfs stub. Networking uses the smoltcp stack for TCP/UDP and provides Unix domain sockets. The codebase is experimental and contains many stubs and unimplemented syscalls, but it is actively developed with a working init process, shell, and basic tools. Key strengths include the clean separation of architecture-independent kernel building blocks in the `libkernel` crate, the async-friendly synchronization primitives (`WakerSet`, `CondVar`, `Mutex`), the generic page table framework, and the driver registration macro. The code is well-structured for a kernel of this complexity, with extensive use of Rust's type system for safety (e.g., typed addresses, user-copy abstractions). However, the project is not production-hardened, relies on nightly Rust, and has significant architecture-specific code that limits portability.
The LLM identified 5 files worth highlighting for reuse:
Defines type-safe physical (PA), virtual (VA), user (UA), and typed physical/user (TPA, TUA) addresses with alignment, page rounding, and offset operations. This pattern prevents mixing up address spaces and is reusable in any systems-level Rust project.
Implements a generic `WakerSet` that manages a queue of wakers with FIFO ordering, supporting `wake_one`, `wake_all`, and `take_if`. This is a foundational async primitive for kernel I/O. It is decoupled from the rest of the kernel except for a spinlock, making it extractable into a no_std crate.
A multi-level slab allocator with per-CPU caches, fallback to a frame allocator, and batch freeing. It manages size classes and partial/free lists. This is a high-performance allocator pattern that could be extracted as a standalone crate with a generic physical allocator trait.
Provides the `kernel_driver!` macro for registering platform drivers with a `DriverManager`. Drivers can declare compatible device tree matches and init functions. This pattern is clean and reusable for any kernel or embedded system that uses FDT.
Defines a `register_test!` macro that collects test functions using the `inventory` crate, allowing tests to be registered in separate files and run by the main runner. This pattern is reusable for any Rust project that needs a lightweight test collection with fork-based isolation (since tests are run in separate processes).