Top Related Projects
Xv6 for RISC-V
:books: Learn to write an embedded OS in Rust :crab:
Writing an OS in Rust
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.
A new operating system kernel with Linux binary compatibility written in Rust.
Mirror of https://gitlab.redox-os.org/redox-os/redox
Quick Overview
rCore-OS is an educational operating system kernel written in Rust. It aims to provide a comprehensive learning experience for operating system development using a modern, safe programming language. The project serves as a practical resource for students and developers interested in OS internals and Rust systems programming.
Pros
- Written in Rust, providing memory safety and concurrency benefits
- Comprehensive educational resource for OS development
- Actively maintained with regular updates and improvements
- Supports multiple architectures (x86_64, RISC-V)
Cons
- Not intended for production use, primarily an educational project
- May lack some advanced features found in mature operating systems
- Learning curve can be steep for those new to Rust or OS development
- Documentation may not be as extensive as some commercial operating systems
Getting Started
To get started with rCore-OS:
-
Clone the repository:
git clone https://github.com/rcore-os/rCore.git cd rCore
-
Install Rust and required tools:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup default nightly rustup target add riscv64gc-unknown-none-elf
-
Build and run rCore:
cd os make run
For more detailed instructions and documentation, refer to the project's README and wiki on GitHub.
Competitor Comparisons
Xv6 for RISC-V
Pros of xv6-riscv
- Simpler codebase, making it easier to understand and modify for educational purposes
- More closely follows traditional Unix design principles
- Better documentation and educational resources available
Cons of xv6-riscv
- Limited feature set compared to rCore
- Less focus on modern operating system concepts and techniques
- Primarily designed for x86 architecture, with RISC-V support added later
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
// via swtch back to the scheduler.
void
scheduler(void)
{
struct proc *p;
struct cpu *c = mycpu();
c->proc = 0;
for(;;){
// Avoid deadlock by ensuring that devices can interrupt.
intr_on();
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == RUNNABLE) {
// Switch to chosen process. It is the process's job
// to release its lock and then reacquire it
// before jumping back to us.
p->state = RUNNING;
c->proc = p;
swtch(&c->context, &p->context);
// Process is done running for now.
// It should have changed its p->state before coming back.
c->proc = 0;
}
release(&p->lock);
}
}
}
rCore (os/src/task/processor.rs):
impl Processor {
pub fn run(&self) -> ! {
loop {
if let Some(task) = fetch_task() {
// get context from task
let mut task_cx_ptr = task.acquire_inner_lock().get_task_cx_ptr();
// release TaskControlBlock manually
drop(task);
unsafe {
__switch(&mut self.idle_task_cx_ptr, &task_cx_ptr);
}
} else {
println!("no task available, yield");
yield_now();
}
}
}
}
:books: Learn to write an embedded OS in Rust :crab:
Pros of rust-raspberrypi-OS-tutorials
- More beginner-friendly with step-by-step tutorials
- Focuses specifically on Raspberry Pi, making it ideal for hobbyists
- Includes detailed explanations and comments in the code
Cons of rust-raspberrypi-OS-tutorials
- Limited to Raspberry Pi hardware, less versatile than rCore
- Simpler implementation, may not cover advanced OS concepts
- Slower development pace compared to rCore
Code Comparison
rCore:
pub fn sys_yield() -> isize {
suspend_current_and_run_next();
0
}
rust-raspberrypi-OS-tutorials:
pub fn yield_now() {
unsafe {
llvm_asm!("svc 0" :::: "volatile");
}
}
Both examples show a yield function, but rCore's implementation is more complex, directly interacting with the scheduler, while the Raspberry Pi tutorial uses a simpler system call approach.
rCore is a more comprehensive OS project aimed at educational purposes, covering various architectures and advanced concepts. It's suitable for in-depth OS study and research.
rust-raspberrypi-OS-tutorials is tailored for Raspberry Pi enthusiasts, offering a gentler learning curve with its focused approach and detailed explanations. It's ideal for those looking to understand OS basics on a specific platform.
Writing an OS in Rust
Pros of blog_os
- Detailed, step-by-step tutorial format, making it easier for beginners to follow
- Written in Rust, which offers memory safety and modern language features
- Focuses on x86_64 architecture, providing in-depth explanations of hardware-specific concepts
Cons of blog_os
- Limited to a single architecture (x86_64), whereas rCore supports multiple architectures
- Primarily educational, not intended for production use like rCore
- Less comprehensive in terms of features and OS capabilities compared to rCore
Code Comparison
blog_os:
#[no_mangle]
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
loop {}
}
rCore:
#[no_mangle]
pub extern "C" fn rust_main() -> ! {
println!("Hello rCore-Tutorial!");
panic!("end of rust_main")
}
Both projects use Rust and implement a simple entry point function. However, rCore's implementation includes a panic call, while blog_os uses an infinite loop. This reflects the different goals of the projects: blog_os aims to teach OS development concepts, while rCore focuses on building a functional OS.
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
- Supports runtime flexibility and dynamic loading of OS components
Cons of Theseus
- Less mature and less widely used compared to rCore
- May have a steeper learning curve due to its unique architecture
- Limited documentation and community support
Code Comparison
rCore (Rust):
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {
let task = current_task().unwrap();
let inner = task.inner_exclusive_access();
if fd >= inner.fd_table.len() {
return -1;
}
if let Some(file) = &inner.fd_table[fd] {
let file = file.clone();
// Release current task TCB manually to avoid multi-borrow
drop(inner);
file.write(UserBuffer::new(unsafe {
core::slice::from_raw_parts(buf, len)
})) as isize
} else {
-1
}
}
Theseus (Rust):
pub fn write(fd: FileDescriptor, buf: &[u8]) -> Result<usize, Error> {
let task = scheduler::get_my_current_task()?;
let file = task.get_file(fd)?;
file.write(buf)
}
The code snippets show that both projects use Rust, but Theseus appears to have a more concise implementation of the write system call. rCore's implementation includes more explicit error handling and memory management, while Theseus relies on Rust's built-in error handling mechanisms.
A new operating system kernel with Linux binary compatibility written in Rust.
Pros of Kerla
- Written in Rust, providing memory safety and concurrency benefits
- Designed as a monolithic kernel, potentially offering better performance
- Supports x86_64 architecture
Cons of Kerla
- Less comprehensive documentation compared to rCore
- Smaller community and fewer contributors
- Limited cross-platform support
Code Comparison
rCore (Rust):
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> SysResult {
let task = current_task().unwrap();
let inner = task.inner_exclusive_access();
if fd >= inner.fd_table.len() {
return Err(SysError::EBADF);
}
// ... (implementation continues)
}
Kerla (Rust):
pub fn sys_write(fd: c_int, buf: UserVAddr, len: usize) -> Result<isize> {
let file = current_process().get_file(fd)?;
let data = current_process().read_mem(buf, len)?;
file.write(&data).map(|written| written as isize)
}
Both projects use Rust for system calls, but Kerla's implementation appears more concise. rCore's code includes more explicit error handling and task management, while Kerla's version relies on helper functions for process and memory operations.
Mirror of https://gitlab.redox-os.org/redox-os/redox
Pros of Redox
- Written in Rust, providing memory safety and preventing common vulnerabilities
- Microkernel architecture for improved modularity and security
- Active community and regular development updates
Cons of Redox
- Less mature and stable compared to rCore
- Smaller ecosystem and fewer available applications
- Steeper learning curve for developers unfamiliar with Rust
Code Comparison
Redox (system call example):
pub fn sys_open(path: &str, flags: usize) -> Result<usize> {
let fd = syscall::open(path, flags)?;
Ok(fd)
}
rCore (system call example):
pub fn sys_open(path: *const u8, flags: u32) -> isize {
let task = current_task().unwrap();
let token = current_user_token();
let path = translated_str(token, path);
if let Some(inode) = open_file(path.as_str(), flags as u32) {
let fd = task.alloc_fd();
task.files[fd] = Some(inode);
fd as isize
} else {
-1
}
}
Both projects aim to create operating systems using Rust, but they differ in their approaches. Redox focuses on a microkernel architecture and leverages Rust's safety features extensively. rCore, on the other hand, is designed as an educational project to teach operating system concepts using Rust. While Redox has a more complete ecosystem, rCore offers a simpler learning path for those interested in OS development with Rust.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
rCore
NO LONGER MAINTAINED. You can see recent developments in:
- https://github.com/rcore-os/zCore
- https://github.com/rcore-os/arceos
- https://github.com/rcore-os/rCore-Tutorial-Book-v3
- https://github.com/rcore-os/arceos-tutorial-book
Rust version of THU uCore OS Plus.
Going to be the next generation teaching operating system.
Supported architectures and boards:
- x86_64(Tier 1): QEMU, PC (i5/i7)
- RISCV32/64(Tier 2): QEMU, HiFive Unleashed
- AArch64(Tier 2): QEMU, Raspberry Pi 3B+
- MIPS32(Tier 3): QEMU, TrivialMIPS
What's included
rCore has the following features:
- Linux compatible syscall interface: run Linux userspace programs
- Network stack
- Simple file system
- Signal system
- Async IO
- Kernel module
Building
Environment
- Rust toolchain
- QEMU >= 4.1.0
- musl-based GCC toolchains (only for building user programs)
Setup on Linux or macOS:
$ rustup component add rust-src llvm-tools-preview
Or use Docker container:
$ docker run -it -v $PWD:$PWD -w $PWD wangrunji0408/rcore
How to run
$ git clone https://github.com/rcore-os/rCore.git --recursive
$ cd rCore/user
$ make sfsimg PREBUILT=1 ARCH=x86_64
$ cd ../kernel
$ make run ARCH=x86_64 LOG=info
See Makefile for more usages.
Maintainers
Module | Maintainer |
---|---|
x86_64 | @wangrunji0408 |
RISC-V | @jiegec |
AArch64 (Raspi3) | @equation314 |
MIPS | @Harry_Chen @miskcoo |
Memory, Process, File System | @wangrunji0408 |
Network with drivers | @jiegec |
GUI | @equation314 |
History
This is a project of THU courses:
- Operating System (2018 Spring)
- Comprehensive Experiment of Computer System (2018 Summer)
- Operating System Train (2018 Autumn)
- Operating System (2019 Spring)
- Operating System Train (2019 Autumn)
- Operating System (2020 Spring)
Reports and Dev docs (in Chinese)
It's based on BlogOS , a demo project in the excellent tutorial Writing an OS in Rust (First Edition).
License
The source code is dual-licensed under MIT or the Apache License (Version 2.0).
Top Related Projects
Xv6 for RISC-V
:books: Learn to write an embedded OS in Rust :crab:
Writing an OS in Rust
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.
A new operating system kernel with Linux binary compatibility written in Rust.
Mirror of https://gitlab.redox-os.org/redox-os/redox
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot