Convert Figma logo to code with AI

nuta logokerla

A new operating system kernel with Linux binary compatibility written in Rust.

3,332
89
3,332
25

Top Related Projects

180,417

Linux kernel source tree

4,659

The seL4 microkernel

Xv6 for RISC-V

3,421

Rust version of THU uCore OS. Linux compatible.

2,851

Theseus is a modern OS written from scratch in Rust that explores 𝐢𝐧𝐭𝐫𝐚𝐥𝐢𝐧𝐠𝐮𝐚𝐥 𝐝𝐞𝐬𝐢𝐠𝐧: closing the semantic gap between compiler and hardware by maximally leveraging the power of language safety and affine types. Theseus aims to shift OS responsibilities like resource management into the compiler.

15,144

Mirror of https://gitlab.redox-os.org/redox-os/redox

Quick Overview

Kerla is an experimental operating system kernel written in Rust. It aims to explore the potential of Rust in systems programming, particularly in kernel development, focusing on safety and performance. Kerla is designed to be a monolithic kernel with a Unix-like interface.

Pros

  • Written in Rust, providing memory safety and thread safety guarantees
  • Implements a Unix-like interface, making it familiar for developers
  • Actively developed and maintained project
  • Serves as an educational resource for OS development in Rust

Cons

  • Experimental nature means it's not suitable for production use
  • Limited hardware support compared to mainstream kernels
  • Smaller community and ecosystem compared to established OS projects
  • May lack advanced features found in mature operating systems

Getting Started

To build and run Kerla, follow these steps:

1. Install Rust and required dependencies:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup target add x86_64-unknown-none


2. Clone the repository:

git clone https://github.com/nuta/kerla.git cd kerla


3. Build the kernel:

make


4. Run Kerla in QEMU:

make run


For more detailed instructions and options, refer to the project's README and documentation.

Competitor Comparisons

180,417

Linux kernel source tree

Pros of Linux

  • Mature, widely-used, and extensively tested operating system
  • Supports a vast array of hardware and architectures
  • Large community and extensive documentation

Cons of Linux

  • Complex codebase with a steep learning curve
  • Slower development cycle due to its size and complexity
  • Higher resource requirements for development and testing

Code Comparison

Linux (simplified example of process creation):

int do_fork(unsigned long clone_flags,
            unsigned long stack_start,
            unsigned long stack_size,
            int __user *parent_tidptr,
            int __user *child_tidptr)
{
    // Complex process creation logic
}

Kerla (simplified example of process creation):

pub fn create_process(
    name: &str,
    entry: VAddr,
    stack: Option<&[u8]>,
) -> Result<Arc<Process>> {
    // Simpler process creation logic
}

Summary

Linux is a mature, widely-used operating system with extensive hardware support and a large community. However, its complexity can make it challenging for newcomers. Kerla, being a microkernel written in Rust, offers a simpler codebase and potentially improved safety features, but lacks the maturity and extensive support of Linux. The code comparison illustrates the difference in complexity and language choice between the two projects.

4,659

The seL4 microkernel

Pros of seL4

  • Formally verified microkernel, providing high security and reliability
  • Extensive documentation and research backing
  • Larger community and industry adoption

Cons of seL4

  • Steeper learning curve due to complexity
  • More resource-intensive, potentially less suitable for lightweight systems
  • Slower development cycle due to formal verification process

Code Comparison

seL4:

static inline void *
PURE CONST get_frame_cap_device_address(cap_t cap)
{
    return (void *)(cap_frame_cap_get_capFBasePtr(cap));
}

Kerla:

pub fn alloc_pages(order: usize) -> Option<PhysAddr> {
    FRAME_ALLOCATOR.lock().alloc_pages(order)
}

Key Differences

  • seL4 is written in C, while Kerla is implemented in Rust
  • seL4 focuses on formal verification, Kerla prioritizes simplicity and modern language features
  • seL4 has a more extensive feature set, while Kerla aims for a minimalistic approach

Use Cases

  • seL4: High-security systems, critical infrastructure, aerospace
  • Kerla: Educational purposes, embedded systems, experimental OS development

Community and Support

  • seL4: Larger community, commercial support available
  • Kerla: Smaller, more focused community, primarily open-source contributions

Xv6 for RISC-V

Pros of xv6-riscv

  • Educational focus: Designed for teaching operating system concepts
  • RISC-V architecture support: Aligns with modern hardware trends
  • Simplicity: Easier to understand and modify for learning purposes

Cons of xv6-riscv

  • Limited features: Lacks advanced OS capabilities found in Kerla
  • Performance: Not optimized for real-world use cases
  • Portability: Primarily focused on RISC-V, less flexible than Kerla

Code Comparison

xv6-riscv (kernel/proc.c):

// Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up.
// Scheduler never returns.  It loops, doing:
//  - choose a process to run.
//  - swtch to start running that process.
//  - eventually that process transfers control

Kerla (kernel/process/scheduler.rs):

/// The process scheduler.
pub struct Scheduler {
    runqueue: VecDeque<Arc<Process>>,
    idle_thread: Option<Arc<Process>>,
}

impl Scheduler {
    pub fn new() -> Scheduler {
        Scheduler {

Summary

xv6-riscv is an educational OS focused on teaching RISC-V concepts, while Kerla is a more feature-rich, Rust-based microkernel. xv6-riscv excels in simplicity and educational value, but Kerla offers better performance and modern language features. The code comparison shows xv6-riscv using C with comments explaining the scheduler, while Kerla uses Rust with a more structured approach to scheduler implementation.

3,421

Rust version of THU uCore OS. Linux compatible.

Pros of rCore

  • Written in Rust, providing memory safety and concurrency benefits
  • More comprehensive educational resource with detailed documentation
  • Supports multiple architectures (x86_64, RISC-V, aarch64)

Cons of rCore

  • Larger codebase, potentially more complex for beginners
  • Less focused on modern features like async/await

Code Comparison

rCore (trap handling):

#[no_mangle]
pub fn trap_handler() -> ! {
    let scause = scause::read();
    let stval = stval::read();
    match scause.cause() {
        Trap::Exception(Exception::UserEnvCall) => {
            // Handle system call
        }
        Trap::Exception(Exception::StoreFault) |
        Trap::Exception(Exception::StorePageFault) => {
            // Handle page fault
        }
        // ...
    }
}

Kerla (interrupt handling):

#[no_mangle]
pub extern "C" fn x64_handle_interrupt(frame: &InterruptFrame) {
    match frame.vector {
        SYSCALL_VECTOR => {
            // Handle system call
        }
        PAGE_FAULT_VECTOR => {
            // Handle page fault
        }
        // ...
    }
}

Both projects implement similar functionality for handling traps/interrupts, but rCore uses Rust's pattern matching more extensively, while Kerla's approach is more C-like.

2,851

Theseus is a modern OS written from scratch in Rust that explores 𝐢𝐧𝐭𝐫𝐚𝐥𝐢𝐧𝐠𝐮𝐚𝐥 𝐝𝐞𝐬𝐢𝐠𝐧: closing the semantic gap between compiler and hardware by maximally leveraging the power of language safety and affine types. Theseus aims to shift OS responsibilities like resource management into the compiler.

Pros of Theseus

  • Written in Rust, offering memory safety and concurrency benefits
  • Implements a novel OS structure with fine-grained components
  • Extensive documentation and research papers available

Cons of Theseus

  • More complex architecture, potentially harder to understand and maintain
  • Less focus on POSIX compatibility, which may limit application support
  • Still in early development stages with fewer features implemented

Code Comparison

Theseus (Rust):

pub fn spawn<F, T>(f: F) -> Result<TaskRef, &'static str>
where
    F: FnOnce() -> T + Send + 'static,
    T: Send + 'static,
{
    // Task creation logic
}

Kerla (C):

int task_create(struct task **task, const char *name,
                void (*entry)(void *arg), void *arg) {
    // Task creation logic
}

Both projects aim to create modern, experimental operating systems, but with different approaches. Theseus focuses on a novel OS structure using Rust's safety features, while Kerla aims for a more traditional UNIX-like kernel written in C. Theseus offers potential benefits in terms of safety and modularity, but at the cost of increased complexity and potentially limited application compatibility. Kerla, on the other hand, provides a more familiar environment for developers accustomed to traditional UNIX-like systems.

15,144

Mirror of https://gitlab.redox-os.org/redox-os/redox

Pros of Redox

  • Written in Rust, providing memory safety and concurrency benefits
  • More mature project with a larger community and ecosystem
  • Includes a graphical user interface and desktop environment

Cons of Redox

  • Larger codebase and more complex system architecture
  • Slower development cycle due to its comprehensive nature
  • Higher resource requirements for running and testing

Code Comparison

Kerla (C++):

pub fn syscall_read(fd: i32, buf: *mut u8, count: usize) -> isize {
    let file = current_process().get_file_descriptor(fd)?;
    file.read(buf, count)
}

Redox (Rust):

pub fn sys_read(fd: FileHandle, buf: &mut [u8]) -> Result<usize> {
    let file = {
        let contexts = context::contexts();
        let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
        let context = context_lock.read();
        context.get_file(fd)?
    };
    file.read(buf)
}

Both projects implement system calls for reading files, but Redox's implementation showcases Rust's safety features and error handling, while Kerla's C++ code is more concise.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Kerla

CI Discord Chat

screenshot

Kerla is a monolithic operating system kernel written from scratch in Rust which aims to be compatible with the Linux ABI, that is, it runs Linux binaries without any modifications.

  • Implements *NIX process concepts: context switching, signals, fork(2), execve(2), wait4(2), etc.
  • Supports commonly used system calls like write(2), stat(2), mmap(2), pipe(2), poll(2), ...
  • No disk support for now: initramfs is mounted as the root file system.
  • Pseudo file systems: tmpfs and devfs.
  • smoltcp-based TCP/IP support.
  • Implements tty and pseudo terminal (pty).
  • Supports QEMU and Firecracker (with virtio-net device driver).
  • Supports x86_64.
  • Docker-based initramfs build system.

Check out my blog post for motivation and my thoughts on writing an OS kernel in Rust.

Demo: SSH into Kerla!

You can play with Kerla over ssh. Your login is not visible from others (except me): we automatically launch a dedicated microVM on Firecracker for each TCP connection.

$ ssh root@demo.kerla.dev

If you found bugs or missing features, let me know on GitHub issues :)

Running a Docker Image (experimental)

You can run a Docker image as a root file system (not as a container!) on Kerla Kernel instead of our initramfs built from initramfs directory.

For example, to run nuta/helloworld image (Dockerfile), try the following command:

$ make IMAGE=nuta/helloworld run
...
[   0.029] syscall: execve(439398, 4393b8, 4393c8, 8, 2f2f2f2f2f2f2f2f, 8080808080808080)
[   0.030] syscall: arch_prctl(1002, 4055d8, 0, 20000, 0, ff)
[   0.031] syscall: set_tid_address(4057f0, 4055d8, 0, 20000, 0, ff)
[   0.033] syscall: ioctl(1, 5413, 9ffffeed0, 1, 405040, 9ffffeef7)

 _          _ _                            _     _ _
| |__   ___| | | ___   __      _____  _ __| | __| | |
| '_ \ / _ \ | |/ _ \  \ \ /\ / / _ \| '__| |/ _` | |
| | | |  __/ | | (_) |  \ V  V / (_) | |  | | (_| |_|
|_| |_|\___|_|_|\___/    \_/\_/ \___/|_|  |_|\__,_(_)

This feature is in a very early stage and I guess almost all images out there won't work because:

  • They tend to be too large to be embedded into the kernel image.
  • They might use unimplemented features (e.g. position-independent executables used in Alpine Linux).

Building and Running the OS

See Quickstart for instructions on building from source, running on emulators, etc.

Current Roadmap

Roadmap - Run a Node.js Web Application on Kerla on Firecracker on AWS

Compatibility

See here for the current status.

Contributing

Send me bug reports, feature requests, and patches on GitHub for example:

  • Implementing missing features: majority of existing Linux applications won't work due to the lack of features.
  • Writing documentation: I think Kerla could be good material to learn how an operating system kernel works.
  • Trying to experiment with Rust-y ideas: for example currently I'm interested in GhostCell.

License

See LICENSE.md.

Related Work

Emulating Linux ABI is not a novel work. Some UNIX-like kernels like FreeBSD and NetBSD already have their own Linux emulation layers. Windows has a well-known feature called Windows Subsystem for Linux (WSL) which enables running Linux binaries seamlessly. WSL 1 implements the feature by ABI emulation. WSL 2 runs the real Linux kernel using the hardware-accelerated virtualization (Hyper-V).

Aside from general-purpose operating systems, there're some attractive projects related to the Linux ABI emualtion. OSv is a unikernel which runs unmodified Linux binaries. rCore is a teaching operating system which implements the Linux ABI in Rust. Noah suggests an intriguing approach to run unmodified Linux binaries on macOS.