|
| 1 | ++++ |
| 2 | +title = "This Month in Rust OSDev: December 2022" |
| 3 | +date = 2023-01-09 |
| 4 | + |
| 5 | +[extra] |
| 6 | +month = "December 2022" |
| 7 | +editors = ["phil-opp"] |
| 8 | ++++ |
| 9 | + |
| 10 | +Welcome to a new issue of _"This Month in Rust OSDev"_. In these posts, we give a regular overview of notable changes in the Rust operating system development ecosystem. |
| 11 | + |
| 12 | +<!-- more --> |
| 13 | + |
| 14 | +This series is openly developed [on GitHub](https://github.com/rust-osdev/homepage/). Feel free to open pull requests there with content you would like to see in the next issue. If you find some issues on this page, please report them by [creating an issue](https://github.com/rust-osdev/homepage/issues/new) or using our <a href="#comment-form">_comment form_</a> at the bottom of this page. |
| 15 | + |
| 16 | +<!-- |
| 17 | + This is a draft for the upcoming "This Month in Rust OSDev (December 2022)" post. |
| 18 | + Feel free to create pull requests against the `next` branch to add your |
| 19 | + content here. |
| 20 | + Please take a look at the past posts on https://rust-osdev.com/ to see the |
| 21 | + general structure of these posts. |
| 22 | +--> |
| 23 | + |
| 24 | +## Infrastructure and Tooling |
| 25 | + |
| 26 | +In this section, we collect recent updates to `rustc`, `cargo`, and other tooling that are relevant to Rust OS development. |
| 27 | + |
| 28 | +<!-- |
| 29 | + Please use the following template: |
| 30 | +
|
| 31 | + ### Summary |
| 32 | + <span class="maintainers">(Section written by [@author](https://github.com/author))</span> |
| 33 | +
|
| 34 | + <text> |
| 35 | +--> |
| 36 | + |
| 37 | +### [Experimental feature gate proposal `interoperable_abi`](https://github.com/rust-lang/rust/pull/105586) |
| 38 | + |
| 39 | +This Rust language proposal suggests to create a new `extern "interop"` ABI as a strict superset of the C ABI. |
| 40 | +The goal of this new ABI is to "define a standard way to make calls across high-level languages, passing high-level data types, without dropping to the lowest common denominator of C". |
| 41 | +For example, it will define a specific memory representation for strings, tuples, and common standard library types such as `Option` and `Result`. |
| 42 | + |
| 43 | +This new ABI would be very useful for operating system development because there are often multiple executables that need to communicate with each other using a stable ABI. |
| 44 | +For example, user-space programs communicate with the kernel using [system calls](https://en.wikipedia.org/wiki/System_call), and with each other porgrams using different forms of [inter-process communication](https://en.wikipedia.org/wiki/Inter-process_communication). |
| 45 | +With new `extern "interop"` ABI, these communication boundaries could use safe, higher-level types when both sides are written in Rust. |
| 46 | + |
| 47 | +### [`default_alloc_error_handler` has been stabilized](https://github.com/rust-lang/rust/pull/102318) |
| 48 | + |
| 49 | +On `no_std` targets, enabling `alloc` requires providing an OOM (out-of-memory) handler. The usual implementation of this handler just panics, but implementing the handler requires an unstable feature: [`alloc_error_handler`]. The newly-stabilized `default_alloc_error_handler` automatically provides an OOM handler that panics if no custom handler is implemented. This is an [important step towards using some targets on the stable channel][towards-stable]. |
| 50 | + |
| 51 | +[`alloc_error_handler`]: https://doc.rust-lang.org/unstable-book/language-features/alloc-error-handler.html#alloc_error_handler |
| 52 | +[towards-stable]: https://github.com/rust-lang/rust/pull/102318#issuecomment-1331865137 |
| 53 | + |
| 54 | +## Announcements, News, and Blog Posts |
| 55 | + |
| 56 | +<!-- |
| 57 | +Here we collect news, blog posts, etc. related to OS development in Rust. |
| 58 | +Please follow this template: |
| 59 | +
|
| 60 | +- [Title](https://example.com) |
| 61 | + - (optional) Some additional context |
| 62 | +--> |
| 63 | + |
| 64 | +- [Linux 6.1 Released With MGLRU, Initial Rust Code](https://www.phoronix.com/news/Linux-6.1-Released) |
| 65 | +- [Kernel/Boot: Cope with a Relocation by a Bootloader in 32-bit x86 Assembly Code](https://phip1611.de/blog/kernel-boot-cope-with-a-relocation-by-a-bootloader-in-32-bit-x86-assembly-code/) \ |
| 66 | + In this blogpost, [@phip1611](https://github.com/phip1611) shows you how you can cope with a |
| 67 | + relocation by a bootloader in x86 32-bit assembly code. |
| 68 | +- [How Does the “File Size is Smaller Than Mem Size” Optimization Work in GNU ld for the .bss Section?](https://phip1611.de/blog/how-does-the-file-size-is-smaller-than-mem-size-optimization-work-in-gnu-ld/) \ |
| 69 | + In this blogpost, [@phip1611](https://github.com/phip1611) explains what properties bring the GNU |
| 70 | + linker ld to save disk space, as symbols in the `.bss` section do not need to be statically |
| 71 | + allocated inside the ELF. Symbols in the `.bss` segment are expected to be initialized to all |
| 72 | + zeroes. |
| 73 | +- [GNU ld: Linking .bss into .data to Ensure that Mem Size Equals File Size For Each LOAD Segment (.bss in a PROGBITS Section)](https://phip1611.de/blog/linking-bss-into-data-to-ensure-the-mem-size-equals-file-size-for-each-load-segment-bss-in-a-progbits-section/) \ |
| 74 | + In this blogpost, [@phip1611](https://github.com/phip1611) explains what steps you have to do |
| 75 | + that the GNU linker put's all symbols of the `.bss` section "as they are" into the binary |
| 76 | + so that they occupy zeroed memory in the ELF. This is relevant for some very rudimentary |
| 77 | + ELF loaders that are found in some microkernels to bootstrap their initial process. |
| 78 | +- [The Probably Simplest x86 Driver Written in Assembly – Printing to QEMU’s debugcon-Device)](https://phip1611.de/blog/the-probably-simplest-x86-driver-written-in-assembly-printing-to-qemus-debugcon-device/) \ |
| 79 | + In this blogpost, [@phip1611](https://github.com/phip1611) codes with you probably the simplest |
| 80 | + driver that one can write in assembly. *This blogpost is from September but wasn't mentioned here |
| 81 | + earlier.* |
| 82 | + |
| 83 | +## `rust-osdev` Projects |
| 84 | + |
| 85 | +In this section, we give an overview of notable changes to the projects hosted under the [`rust-osdev`] organization. |
| 86 | + |
| 87 | +[`rust-osdev`]: https://github.com/rust-osdev/about |
| 88 | + |
| 89 | +<!-- |
| 90 | + Please use the following template: |
| 91 | +
|
| 92 | + ### [`repo_name`](https://github.com/rust-osdev/repo_name) |
| 93 | + <span class="maintainers">Maintained by [@maintainer_1](https://github.com/maintainer_1)</span> |
| 94 | +
|
| 95 | + The `repo_name` crate ...<<short introduction>>... |
| 96 | +
|
| 97 | + We merged the following changes this month: |
| 98 | + <<changelog, either in list or text form>> |
| 99 | +--> |
| 100 | + |
| 101 | +### [`uefi-rs`](https://github.com/rust-osdev/uefi-rs) |
| 102 | + |
| 103 | +<span class="maintainers">Maintained by [@GabrielMajeri](https://github.com/GabrielMajeri), [@nicholasbishop](https://github.com/nicholasbishop), and [@phip1611](https://github.com/phip1611)</span> |
| 104 | + |
| 105 | +The `uefi` crate provides safe and performant wrappers for [UEFI](https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface), the successor to the BIOS. |
| 106 | + |
| 107 | +We merged the following changes last month: |
| 108 | + |
| 109 | +#### Features |
| 110 | + |
| 111 | +- [Implement `SIMPLE_NETWORK_PROTOCOL`](https://github.com/rust-osdev/uefi-rs/pull/606) |
| 112 | +- [Initial support for TCG TPM protocols](https://github.com/rust-osdev/uefi-rs/pull/605) |
| 113 | +- [Add `unsafe_protocol` macro and drop use of the unstable `negative_impls` feature](https://github.com/rust-osdev/uefi-rs/pull/607) |
| 114 | +- [`UnalignedSlice`: impl `Clone` and improve `Debug`](https://github.com/rust-osdev/uefi-rs/pull/603) |
| 115 | +- [Implement `Error` and `Display` traits for `FromStrError`](https://github.com/rust-osdev/uefi-rs/pull/610) |
| 116 | +- [Simplification: No longer return "impl Iterator"](https://github.com/rust-osdev/uefi-rs/pull/619) |
| 117 | +- [uefi: Add `ptr_meta` dependency](https://github.com/rust-osdev/uefi-rs/pull/621) |
| 118 | +- [Drop unstable `maybe_uninit_slice` and `vec_into_raw_parts` features](https://github.com/rust-osdev/uefi-rs/pull/622) |
| 119 | + |
| 120 | +#### Fixes |
| 121 | + |
| 122 | +- [uefi: bug fix found by clippy](https://github.com/rust-osdev/uefi-rs/pull/620) |
| 123 | + |
| 124 | +#### Docs |
| 125 | + |
| 126 | +- [Add list of possible errors to `BootServices::open_protocol` docs](https://github.com/rust-osdev/uefi-rs/pull/600) |
| 127 | +- [Add list of possible errors to some `BootServices` function docs](https://github.com/rust-osdev/uefi-rs/pull/602) |
| 128 | +- [Add docs to `BootServices` functions describing error cases](https://github.com/rust-osdev/uefi-rs/pull/604) |
| 129 | +- [Shortened error documentation for all methods in `BootServices`](https://github.com/rust-osdev/uefi-rs/pull/608) |
| 130 | +- [Replaced UEFI chapter numbers with function identifiers in the docs](https://github.com/rust-osdev/uefi-rs/pull/611) |
| 131 | +- [Add some documentation for media protocols](https://github.com/rust-osdev/uefi-rs/pull/614) |
| 132 | + |
| 133 | +#### Tooling |
| 134 | + |
| 135 | +- [xtask: Update to mbrman 0.5.1](https://github.com/rust-osdev/uefi-rs/pull/601) |
| 136 | +- [Editorconfig: switch to max line width of 80](https://github.com/rust-osdev/uefi-rs/pull/615) |
| 137 | + |
| 138 | + |
| 139 | +Thanks to [@veluca93](https://github.com/veluca93), [@phip1611](https://github.com/phip1611), and [@raccog](https://github.com/raccog) for their contributions! |
| 140 | + |
| 141 | + |
| 142 | +### [`x86_64`](https://github.com/rust-osdev/x86_64) |
| 143 | + |
| 144 | +<span class="maintainers">Maintained by [@phil-opp](https://github.com/phil-opp), [@josephlr](https://github.com/orgs/rust-osdev/people/josephlr), [@Freax13](https://github.com/orgs/rust-osdev/people/Freax13), and [@rybot666](https://github.com/orgs/rust-osdev/people/rybot666)</span> |
| 145 | + |
| 146 | +The `x86_64` crate provides various abstractions for `x86_64` systems, including wrappers for CPU instructions, access to processor-specific registers, and abstraction types for architecture-specific structures such as page tables and descriptor tables. |
| 147 | + |
| 148 | +We merged the following changes in December: |
| 149 | + |
| 150 | +- [Adding `next_higher_level` to `PageLevelIndex`](https://github.com/rust-osdev/x86_64/pull/400) |
| 151 | +- [Adding `is_empty` to `PageTable`](https://github.com/rust-osdev/x86_64/pull/399) |
| 152 | +- [fix `Page::from_page_table_indices`](https://github.com/rust-osdev/x86_64/pull/398) <span class="gray">(for upcoming `v0.15` release)</span> |
| 153 | + |
| 154 | +Thanks to [@TornaxO7](https://github.com/TornaxO7) for their contribution! |
| 155 | + |
| 156 | + |
| 157 | +## Call for Participation |
| 158 | + |
| 159 | +Want to contribute to a Rust OSDev project, but don't know where to start? Help with one of these outstanding issues! |
| 160 | + |
| 161 | +<!-- |
| 162 | + Please use the following template for adding items: |
| 163 | + - [(`repo_name`) Issue Description](https://example.com/link-to-issue) |
| 164 | +--> |
| 165 | + |
| 166 | +<span class="gray"> |
| 167 | + |
| 168 | +_No tasks were proposed for this section this month._ |
| 169 | + |
| 170 | +</span> |
| 171 | + |
| 172 | +If you maintain a Rust project related to operating system development and are looking for contributors, especially for tasks suited to people getting started in this space, please [create a PR](https://github.com/rust-osdev/homepage/pulls) against the `next` branch with the tasks you want to include in the next issue. |
| 173 | + |
| 174 | +## Other Projects |
| 175 | + |
| 176 | +In this section, we describe updates to Rust OS projects that are not directly related to the `rust-osdev` organization. Feel free to [create a pull request](https://github.com/rust-osdev/homepage/pulls) with the updates of your OS project for the next post. |
| 177 | + |
| 178 | +### [Theseus OS](https://github.com/theseus-os/Theseus) |
| 179 | + |
| 180 | +<span class="maintainers">(Section written by [Kevin Boos](https://www.theseus-os.com/kevinaboos/) ([@kevinaboos](https://github.com/kevinaboos)))</span> |
| 181 | + |
| 182 | +Theseus is a safe-language OS written from scratch in Rust that is in the midst of a shift from academic research to usability and legacy compatibility. |
| 183 | +Theseus loads and links all components at runtime, and executes everything at a single privilege level in a single address space, relying on Rust safety for isolation and correctness. |
| 184 | + |
| 185 | +As a fully open-source project, we welcome and encourage contributions from everyone! |
| 186 | + |
| 187 | +Since our [last update](https://rust-osdev.com/this-month/2022-09/index.html#theseus-os) here a few months ago, we have worked on the following things: |
| 188 | +* Introduced `dreadnought`, a basic async executor that brings Rust's `async`/`await` syntax to Theseus |
| 189 | + * Usable by both applications and low-level kernel components |
| 190 | + * Integrated the concept of wakers with Theseus's native task subsystem |
| 191 | + * Currently, there is a 1-to-1 relationship between async `dreadnought` tasks and native Theseus tasks |
| 192 | +* Rewrote our networking interface to offer better, simpler, and cleaner abstractions |
| 193 | + * It now supports the latest `smoltcp` version, `0.8` |
| 194 | +* Added support for booting Theseus on UEFI |
| 195 | + * Previously, Theseus could boot from only multiboot2-compliant bootloaders using legacy BIOS |
| 196 | + * UEFI on x86_64 now successfully boots after significant redesign of early bootstrap routines |
| 197 | + * New custom `uefi_loader` tool, loosely based on the rust-osdev org's `bootloader` project |
| 198 | + * Early graphical display for basic text printing is a work-in-progress |
| 199 | + * UEFI is required to boot Theseus on aarch64; this is also a work-in-progress |
| 200 | +* Almost completed porting core subsystems to aarch64 |
| 201 | + * Bootstrap and logging over UART |
| 202 | + * Memory management: page table modification, arch-agnostic PTE flags and basic memory types, etc |
| 203 | + * Basic context switching and task bootstrap |
| 204 | + * SMP multicore, plus identification of CPU cores |
| 205 | + * Interrupt handling via GIC |
| 206 | +* Redesigned the drivers for PS/2 controller, keyboard, and mouse in an intralingual manner that fully leverages Rust's strong type system. |
| 207 | +* Started implementing a brand new graphics stack and window manager, `Porthole`, from scratch |
| 208 | + * Added support for x86's Page Attribute Table, which allows Theseus to control the caching properties of individual memory pages |
| 209 | + * We now map graphics video memory as *write-combining* instead of cache-disabled, which significantly improves performance |
| 210 | +* Redesigned task management to give arbitrary tasks fewer privileges |
| 211 | + * Two new types: `JoinableTaskRef` and `ExitableTaskRef` |
| 212 | + * `JoinableTaskRef` is similar to `std::task::JoinHandle`, but is fully safe |
| 213 | + * Ensures that a task can only be `join`ed by the "parent" task that spawned it |
| 214 | + * Remove distinction between `join`ing a task and obtaining its `ExitValue` |
| 215 | + * Automatically reaps "orphan" tasks that are no longer joinable |
| 216 | + * `ExitableTaskRef` statically ensures that only a task itself can mark itself as exited |
| 217 | + * Now, a given task can no longer invalidly mark another arbitrary task as exited |
| 218 | + * Refactored scheduler and task switching to not hold any `TaskRef`s during a context switch |
| 219 | + * Ensures that exited tasks are dropped and cleaned up expediently |
| 220 | + * Native ELF Thread-Local Storage (TLS) variables are used to store the current task |
| 221 | + * Accessing the current task is much faster, albeit slightly more complicated to initialize |
| 222 | +* Implemented a new shell called `hull`, plus new terminal, console, and TTY components |
| 223 | + * Theseus can now run headlessly, e.g., interactively over a serial port instead of via a graphical display. |
| 224 | +* Removed usage of `owning_ref`, a crate with unsoundness, in favor of our own types: |
| 225 | + * `BorrowedMappedPages<T>`: a pseudo-self-referential type that allows persistent, efficient borrowing of a `MappedPages` memory region as a specific type `T` |
| 226 | + * Accepts a `Mutability` type parameter for either immutable (`&T`) or mutable (`&mut T`) borrowing |
| 227 | + * Sister type `BorrowedSliceMappedPages` also supports dynamically-sized slices, i.e., `&[T]` and `&mut [T]` |
| 228 | + * Much more efficient than `owning_ref` because `MappedPages` is always pinned in memory, avoiding the need for `Box` allocation |
| 229 | + * `dereffer`: a new library crate that provides `DerefsTo<T>`, a generic wrapper type that allows the enclosed object `T` to be arbitrarily dereferenced to *any* inner type reachable from that object `T` |
| 230 | + * Supports much more arbitrary and complex deref functions than `std::ops::Deref` |
| 231 | +* Canonicalized the content of Theseus's `x86_64-unknown-theseus` target spec |
| 232 | + * Codegen flags are now moved into the target spec, making out-of-tree builds easier and more repeatable |
| 233 | + * Target specs are now ready to be upstreamed into `rustc` as built-in targets |
| 234 | +* `owned_borrowed_trait`: a new library crate that abstracts over Owned values vs. Borrowed refs |
| 235 | + * Uses traits and marker types instead of the existing enum-based designs (like `Cow`) |
| 236 | + * Doesn't require `Clone` or care about any characteristics of the inner type `T` |
| 237 | + * Allows you to use generics and associated `const`s to conditionally branch based on whether an owned value or borrowed reference was passed into a function |
| 238 | + * Allows you to return a different (generic) type from a function based on whether an owned value or borrowed reference was passed in |
| 239 | + |
| 240 | +Check out the [Theseus OS blog](https://www.theseus-os.com/) for more. |
| 241 | + |
| 242 | +### [`Andy-Python-Programmer/Aero`](https://github.com/Andy-Python-Programmer/aero) |
| 243 | + |
| 244 | +<span class="maintainers">(Section written by [@Andy-Python-Programmer](https://github.com/Andy-Python-Programmer))</span> |
| 245 | + |
| 246 | +Aero is a new modern, experimental, unix-like operating system following the monolithic kernel design. Supporting modern PC features such as long mode, 5-level paging, and SMP (multicore), to name a few. |
| 247 | + |
| 248 | +This month, Aero successfully managed to get [`mesa-demos`](https://github.com/freedesktop/mesa-demos) and [`alacritty`](https://github.com/alacritty/alacritty) running. |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | +In addition, `deps.sh` script was added to automate the process of installing the required dependencies on the host to build the sysroot. |
| 253 | + |
| 254 | +### [`phil-opp/blog_os`](https://github.com/phil-opp/blog_os) |
| 255 | +<span class="maintainers">(Section written by [@phil-opp](https://github.com/phil-opp))</span> |
| 256 | + |
| 257 | +We merged the following changes to the [_Writing an OS in Rust_](https://os.phil-opp.com/) blog in the past two months: |
| 258 | + |
| 259 | +- [[Chinese] Translate posts 5-8 and improve translation of posts 1-4](https://github.com/phil-opp/blog_os/pull/1131) |
| 260 | + - Thanks to [@liuyuran](https://github.com/liuyuran) for creating this translation. |
| 261 | + - Thanks to [@JiangengDong](https://github.com/JiangengDong) and [@Byacrya](https://github.com/Byacrya) for reviewing. |
| 262 | +- [[Translation][Korean] post-06](https://github.com/phil-opp/blog_os/pull/1175) and [[Translation][Korean] post-07](https://github.com/phil-opp/blog_os/pull/1177) |
| 263 | + - Thanks to [@JOE1994](https://github.com/JOE1994) for creating these translations. |
| 264 | + - Thanks to [@dalinaum](https://github.com/dalinaum) for reviewing. |
| 265 | +- [French translation's links fixes](https://github.com/phil-opp/blog_os/pull/1166) <span class="gray">(thanks to [@alaincao](https://github.com/alaincao)) |
| 266 | +- [Specify latest 0.9 patch version of `bootloader`](https://github.com/phil-opp/blog_os/pull/1176) <span class="gray">(thanks to [@seewishnew](https://github.com/seewishnew)) |
| 267 | + |
| 268 | +<!-- |
| 269 | + Please use the following template: |
| 270 | +
|
| 271 | + ### [`owner_name/repo_name`](https://github.com/rust-osdev/owner_name/repo_name) |
| 272 | + <span class="maintainers">(Section written by [@your_github_name](https://github.com/your_github_name))</span> |
| 273 | +
|
| 274 | + ...<<your project updates>>... |
| 275 | +--> |
| 276 | + |
| 277 | +## Join Us? |
| 278 | + |
| 279 | +Are you interested in Rust-based operating system development? Our `rust-osdev` organization is always open to new members and new projects. Just let us know if you want to join! A good way for getting in touch is our [gitter channel](https://gitter.im/rust-osdev/Lobby). |
0 commit comments