Why is rust suitable for write os

hi experts, is rust better than c to write os kernel?

Hi zgxgoo, I don't think we have enough data yet to support such a conclusion.

There is the Redox OS project which attempts to build a full OS in Rust, and some embedded kernel projects in various states of completion (or deterioration).

I doubt that work has progressed to a state where we can meaningfully compare the work to things like a Linux kernel, which has seen some man-centuries of development time and gets funded by heavyweight companies.

That said, Rust has a few things going for it that make it suitable for at least some of the tasks that arise when writing a kernel. If you are interested in that sort of development, why don't you try it and tell us how you fared?

Disclaimer: Apart from building a small kernel during an OS course as a CS student, and getting a kernel driver patch into Ubuntu once, I have little experience with actual kernel work.


I've attempted some kernel prototyping in Rust. See: GitHub - dpc/titanos: Titanos an exercise in writing OS kernel in Rust programming language.

Generally Rust is very promising for the field and I it's definitely possible to write baremetal software including kernels in Rust. There were some annoyances though. First, a lot of the stuff needs to be unsafe, deal with raw pointers, etc. and Rust syntax is very clumsy in this area. It's not a deal breaker, and it might have a lot to do with me being used to C, and not being Rust expert and trying C-tricks where they don't belong.

Second, I've encountered some stuff missing from the language, like: Rust version of `__attribute(used)__` (GCC) or `llvm.used` (LLVM). · Issue #23577 · rust-lang/rust · GitHub which I just couldn't get core developers attention to consider fixing as I was dismissed with some workarounds like "just wrap it in the crate and make pub".

I really need to find some time to look into Redox and how they have dealt with this issues.

1 Like

Thanks for your suggestion!

Thanks for your suggestion,