Rust: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Add a list of projects written in rust (from a quick google))
m (Reverted edits by Melina148 (talk) to last revision by Adavis07)
 
(36 intermediate revisions by 25 users not shown)
Line 1: Line 1:
'''Rust''' is a new systems language under development by Mozilla, designed to offer better safety and concurrency than other, more traditional systems programming languages. The syntax is a C dialect with the familiar braces and semi-colons. It features constructs from imperative programming (such as <tt>if</tt> and <tt>while</tt>), functional programming (such as lambda's, multi-directional pattern matching and immutable variables) and object oriented languages (traits and objects).
'''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 has a strong focus on memory safety and control. Object allocation happens on the stack by default, but they can explicitly be stored on the heap. Objects are automatically deallocated as soon as they are no longer needed. Rust's references prevent dangling pointers, null references, and out of bounds memory access.

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 ==
== Operating System Development ==
While Rust has its own runtime (that uses libc), Rust can easily be configured to compile programs without it. This gives developers the freedom to implement their own memory allocation and other low-level services. This makes Rust ideal for 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.
== Projects ==

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

== Active Projects ==

* [https://github.com/Andy-Python-Programmer/aero A mature POSIX OS]
* [https://os.phil-opp.com/ "Writing an OS in Rust"]
* [https://osblog.stephenmarz.com/ Tutorial: RISC-V OS using Rust]
* [https://github.com/thepowersgang/rust-barebones-kernel Meaty Bare-Bones]
* [https://github.com/thepowersgang/rust-barebones-kernel Meaty Bare-Bones]
* [https://github.com/thepowersgang/rust_os "Tifflin"]
* [https://github.com/skyzh/core-os-riscv core-os-riscv]
** An xv6-like operating system
** RISC-V based with multi-core support
* [https://github.com/thepowersgang/rust_os Tifflin]
** Multiboot image for x86_64
** Multiboot image for x86_64
** Actively developed, has VFS and userland
** has VFS and userland
* [http://www.redox-os.org Redox]
* [https://github.com/charliesome/rustboot RustBoot]
** One of the largest and most active Rust OS projects
** x86 bootsector, doesn't use libcore
* [https://www.tockos.org Tock]
** Out-of-date, written in pre 1.0 code
** optimized for embedded devices
** isolates drivers and applications
* [http://intermezzos.github.io/ intermezzOS]
** Small kernel + book, specifically for learning OSDev through Rust
** on hiatus indefinitely
* [https://github.com/ryanra/RustOS Ryanra's RustOS]
* [https://github.com/ryanra/RustOS Ryanra's RustOS]
** Uses libcore/collections/alloc
** Uses libcore/collections/alloc
* [https://github.com/QuiltOS/QuiltOS QuiltOS]
** Actively develped
** Forked from Ryanra's RustOS
** Main goal is demoing OS Dev libraries written in Rust.
* [https://source.that.world/source/rux Rux]
* [https://github.com/nebulet/nebulet Nebulet]
** Has an end goal of running [[WebAssembly]] in the kernel for a performance increase
* [https://github.com/theseus-os/Theseus Theseus]
** An experimental OS written in Rust
* [https://github.com/vinc/moros MOROS]
** A simple hobby OS with a text-based user interface


== 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, thus these projects are of historical interest, but aren't guaranteed to run or even build.

* [https://github.com/charliesome/rustboot RustBoot]
* [https://github.com/LeoTestard/Quasar Quasar]
* [https://github.com/miselin/rustic Rustic]
* [https://github.com/wbthomason/ironkernel IronKernel]
* [https://github.com/thiagopnts/rustico Rustico]
* [https://github.com/Arcterus/kRnel kRnl]
* [https://github.com/mahrz/rv6 rv6]
* [https://github.com/hackndev/zinc Zinc]


== Libraries ==

* [https://github.com/gz/rust-x86 libx86]: Library to program x86 hardware.
* [https://github.com/rust-osdev/x86_64 x86_64]: Library to program x86_64 hardware.
* [https://github.com/rust-osdev/bootloader bootloader]: A rust bootloader.
* <strike>[https://github.com/Tobba/libcpu libcpu]: Library to program CPUs.</strike> Now absorbed into libx86.
* [https://github.com/gz/rust-slabmalloc slabmalloc]: Low-level memory allocator for liballoc.
* [https://github.com/gz/rust-multiboot multiboot]: Library to read multiboot layout.
* [https://github.com/mvdnes/spin-rs spin]: Various synchronization primitives implemented with spinning. Closely mimics `std::sync`'s interface.
* [https://github.com/nathan7/libfringe fringe]: Context switching agnostic to how stacks are allocated.


== See Also ==
== See Also ==

* [http://www.rust-lang.org/ Rust Website]
* [http://www.rust-lang.org/ Rust Website]
* [https://web.archive.org/web/https://github.com/rust-lang/rust/wiki/Operating-system-development Operating Systems Development in Rust]
* [https://github.com/rust-lang/rust-wiki-backup/blob/master/Operating-system-development.md Operating Systems Development in Rust]
* [http://scialex.github.io/reenix.pdf Reenix: Implementing a Unix-like OS in Rust]
* [http://scialex.github.io/reenix.pdf Reenix: Implementing a Unix-like OS in Rust]
* [http://jvns.ca/blog/2014/03/12/the-rust-os-story/ Writing an OS in Rust in tiny steps (Steps 1-5)]
* [http://jvns.ca/blog/2014/03/12/the-rust-os-story/ Writing an OS in Rust in tiny steps (Steps 1-5)]
* [[Rust Bare Bones]]
* [[Rust Bare Bones]]
* [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]
* [[BOOTBOOT]] loader has an example 64 bit higher half kernel in Rust
* [https://github.com/rust-osdev rust-osdev on GitHub]


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

Latest revision as of 13:37, 7 June 2024

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.

Active Projects

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, thus these projects are of historical interest, but aren't guaranteed to run or even build.


Libraries

  • libx86: Library to program x86 hardware.
  • x86_64: Library to program x86_64 hardware.
  • bootloader: A rust bootloader.
  • 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