High-Level Architecture
SerenityOS follows a layered architecture:Core Components
Kernel
Modern 64-bit kernel with pre-emptive multi-threading, memory protection, and hardware support for x86-64, ARM, and RISC-V
Userland
Complete userspace including system services, applications, utilities, and libraries
Libraries
Rich set of libraries from LibC to LibWeb, all built from scratch
IPC
Modern inter-process communication system for service coordination
Design Principles
From-Scratch Philosophy
From-Scratch Philosophy
Every component of SerenityOS is written from scratch with no external dependencies. This includes:
- Custom kernel implementation
- Complete C library (LibC)
- All system libraries and frameworks
- Web browser engine (LibWeb)
- Graphics stack
- Network stack
Security by Design
Security by Design
SerenityOS implements multiple security features:
- Hardware memory protection (NX, SMEP, SMAP)
- W^X (Write XOR Execute) memory policies
pledge()andunveil()system calls (inspired by OpenBSD)- Kernel and userland ASLR (KASLR)
- OOM resistance
- Web content isolation
- Limited userland capabilities
Modern C++ Design Patterns
Modern C++ Design Patterns
The codebase extensively uses modern C++ patterns:
- Smart pointers (NonnullRefPtr, RefPtr, OwnPtr, NonnullOwnPtr)
- Error propagation with
ErrorOr<T>andTRY()macro - Value semantics and move semantics
- Template metaprogramming
- Custom data structures in AK (Application Kit)
POSIX Compatibility
POSIX Compatibility
While not strictly POSIX-compliant, SerenityOS provides:
- Standard Unix syscalls and signals
- POSIX-like virtual filesystems (/proc, /dev, /sys, /tmp)
- Pseudoterminals (PTY)
- Filesystem notifications
- Shell and standard Unix utilities
- Good LibC compatibility
Directory Structure
The source tree is organized into clear, functional directories:Platform Support
SerenityOS supports multiple hardware architectures:
- x86-64: Primary architecture with full feature support
- ARM (aarch64): Growing support for ARM64 systems
- RISC-V (riscv64): Experimental RISC-V 64-bit support
Kernel/Arch/ directory, allowing for portable kernel code.
Build System
SerenityOS uses CMake as its build system with custom toolchain configuration:- Cross-compilation support from Linux, macOS, Windows (WSL2), and other Unix systems
- Separate toolchains for each target architecture
- Incremental builds with dependency tracking
- Integrated testing framework
- QEMU integration for easy testing
Memory Architecture
The system uses a sophisticated memory management approach:- Virtual Memory: Full MMU utilization with page-level protection
- Kernel Space: Higher-half kernel (separate from userspace)
- Userspace: Each process has isolated address space
- Shared Memory: VMObject-based shared memory regions
- Copy-on-Write: Efficient fork() implementation
- Memory-Mapped I/O: Direct device access via mmap()
Filesystem Architecture
SerenityOS implements a VFS (Virtual Filesystem) layer supporting:- On-Disk Filesystems
- Virtual Filesystems
- Ext2: Primary filesystem (read/write)
- FAT32: FAT filesystem support
- ISO9660: CD-ROM filesystem
- Plan9FS: Network filesystem
Network Architecture
The network stack is implemented entirely in the kernel:- IPv4: Full IPv4 support with routing
- IPv6: Growing IPv6 implementation
- TCP/UDP: Reliable and unreliable transport protocols
- Sockets: BSD-style socket API
- Protocols: HTTP, DNS, DHCP, NTP, and more in userland
Graphics Pipeline
Next Steps
Explore the Kernel
Deep dive into kernel architecture, subsystems, and design
Understand Userland
Learn about services, applications, and the userspace environment
Study Libraries
Examine the library architecture and organization
Learn IPC
Understand how processes communicate in SerenityOS
