Rust: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(→‎Operating System Development: Added a description of the alloc crate)
(fuck off bzt)
Line 74: Line 74:
* [http://os.phil-opp.com/ Blog Series: Writing an OS in Rust]
* [http://os.phil-opp.com/ Blog Series: Writing an OS in Rust]
* [http://www.randomhacks.net/2015/11/11/bare-metal-rust-custom-target-kernel-space/ Retarget your compiler so interrupts are not evil]
* [http://www.randomhacks.net/2015/11/11/bare-metal-rust-custom-target-kernel-space/ Retarget your compiler so interrupts are not evil]
* [https://github.com/rust-osdev rust-osdev on GitHub]
* [[BOOTBOOT]] loader has an example 64 bit higher half kernel in Rust


[[Category:Languages]]
[[Category:Languages]]

Revision as of 09:20, 3 June 2022

Rust is a systems language sponsored by Mozilla, focused on three things: safety, speed, and concurrency. It accomplishes many of these goals through strong compile-time checks, allowing for very little overhead at runtime. Performance is comparable to C or C++, while being free of many of the problems caused by things like dangling pointers, buffer overflows, and iterator invalidation.

While Rust is very much a "curly-brace" language, it also takes many cues from ML. Almost everything is an expression, and there is a very strong type system including sum types and powerful generics.

Rust provides a mechanism to subvert its safety checks when necessary, by adding an 'unsafe' annotation to portions of your code. This allows you full access to raw pointers, while controlling exactly how they are used. Often, Rust code that uses unsafe will do so as an implementation detail, allowing for them to expose a safe interface.

Operating System Development

Rust has a comparable amount of runtime to C and C++, and has set up its standard library to be amenable towards OS development. Specifically, the standard library (std) consists of two smaller parts: core and alloc. Core consists of the primitive, platform-independent components of the standard library. It doesn't include things like allocation, threading, and other higher-level features. Alloc is used for managing heap allocations, smart pointers, and simple data collections. Std builds on top of core and alloc to add other OS dependent features, such as files and processes. Using only core and alloc instead of std is as easy as adding the no_std annotation to your main source file.

Every Rust compiler is a cross-compiler, which makes setup easier.

There are still some rough edges when doing OSDev, and they require using nightly-only features. These are currently being worked on.

Active Projects

  • "Writing an OS in Rust"
  • Meaty Bare-Bones
  • core-os-riscv
    • An xv6-like operating system
    • RISC-V based with multi-core support
  • Tifflin
    • Multiboot image for x86_64
    • has VFS and userland
  • Redox
    • One of the largest and most active Rust OS projects
  • Tock
    • optimized for embedded devices
    • isolates drivers and applications
  • intermezzOS
    • Small kernel + book, specifically for learning OSDev through Rust
    • on hiatus indefinitely
  • Ryanra's RustOS
    • Uses libcore/collections/alloc
  • QuiltOS
    • Forked from Ryanra's RustOS
    • Main goal is demoing OS Dev libraries written in Rust.
  • Rux
  • Nebulet
    • Has an end goal of running WebAssembly in the kernel for a performance increase
  • Theseus
    • An experimental OS written in Rust

Past Projects

Rust went through a long and public development process, and used to have a significantly larger runtime. There were lots of experiments pre-1.0, and so these projects are of historical interest but may not build.


Libraries

  • libx86: Library to program x86 hardware.
  • libcpu: Library to program CPUs. Now absorbed into libx86.
  • slabmalloc: Low-level memory allocator for liballoc.
  • multiboot: Library to read multiboot layout.
  • spin: Various synchronization primitives implemented with spinning. Closely mimics `std::sync`'s interface.
  • fringe: Context switching agnostic to how stacks are allocated.

See Also