RISC-V OS using Rust: Graphics
blog.stephenmarz.com
blog.stephenmarz.com
https://lore.kernel.org/lkml/Pine.LNX.4.58.0401192241080.231...
" any compiler or language that likes to hide things like memory allocations behind your back just isn't a good choice for a kernel "
This was about C++ . So,given that Rust is similar to C++ , How does this quote applies to Rust?
Edit: I am getting downvoted for this post. Downvoters,any reasons?
I think this is the right approach for a performant language and a good compromise in usability. The only thing missing would be to have lints letting you know when using other constructs would be a better trade-off, like switching from dynamic dispatch to static dispatch when there's only one possible caller.
gotta explain what's the difference between
let mut vec = Vec::new();
vec.push(1);
vec.push(2);
vec.push(3);
// likely allocates one, two, or three times
and auto vec = std::vector<int>{};
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
// same struct vec_int vec = VEC_INT_EMPTY;
vec_int_push(&vec,1);
vec_int_push(&vec,2);
vec_int_push(&vec,3);
even in C. They're talking about things like: Foo foo; // Foo::Foo allocates
z = x + y; // operator+ allocates
w = x; // operator= allocates
foo += *bar; // operator* allocates
Rust can do most of those things, but it's not encouraged and significantly less pervasive, especially in the kind of code you'd want to use in a kernel in the first place.Sure in theory. But in practice most consider such a behavior a code small or straight bug an d fix it.
So there is a difference in practice.
You can also use asm blocks (or string literals casted to function pointers) to wreak all kinds of havok. Oddly, noone seems particularly concerned about that.
The only way to have explicit allocations in Rust is to not use libstd (but this isn't special in the context of writing OSes anyway) and disallow using the GlobalAlloc trait, as well as any third-party libraries that rely on it. Unfortunately both the explicit allocator LocalAlloc and the global allocator GlobalAlloc, as well as all the types that rely on GlobalAlloc, are defined in the same library liballoc, so keeping one and removing the others requires patching liballoc.
As far as other non-C languages go, Zig has an explicit allocator that neeeds to be threaded through any function that wants to allocate, which would likely satisfy Linus's requirement.
Then again, I don't commonly use any of the languages in question, so maybe I'm missing the point entirely.
Symbian, Windows, macOS, Android, ChromeOS, Arduino, ARM mbed are all examples of OSes that have C++ at the kernel, or very least at the drivers layer.
Android and ChromeOS use a fork of Linux kernel, with legacy drivers written in C. What GNU/Linux users would call regular drivers.
Project Treble drivers are written in a mix of C++ and Java.
ChromeOS uses a mix of C++ and Rust for its drivers.
Linux fans have to come to grips that its place on Android and ChromeOS is only a convenience for a POSIX like kernel.
Edit: or even something like "a = b"
The problem gets magnified when you pass around these objects by value, thereby invoking copy constructors that also do those allocations, and doing value assignment, where you could have all those allocations happen again.
His comments predate r-value references, and a lot of stuff that r-value references have improved would be exactly the kinds of things where he saw a problem (though he'd hate the r-value solution).
Rust allocations are I believe closer to C then C++ and Linus has already supported Rust: https://www.theregister.com/2020/07/13/rust_code_in_linux_ke...
So basically the question as it's asked doesn't make sense as I understand Rust and if someone took that to be intentional could be interpreted as language FUD (which could then deserve a down vote). An update to prevent the spread of misinformation about the language would be cool.
PS. I've only been using Rust on the daily for the last 8 months so I am by no means an expert. If there is a reason for your assertions that I'm missing I'd like to know. Thnx!
Hence why Linus is allowing Rust for certain Kernel aspects whereas he has previously rejected C++: https://www.theregister.com/2020/07/13/rust_code_in_linux_ke...
Anxiously waiting for the day I can purchase a riscV raspberry pi like SoC with fully oss hardware and Ready for Linux.
RPi is another story: it's a single board computer with exposed GPIO and used to be shipped with ancient GPU.
Hifive1 is more of a competitor to Arduino if you can call it that. They even have the same pinout for expansion.
They are quite pricy, like you said, due to early adopter fee. However, you gotta understand that SiFive develop their cores and unlike Arduino RPi can't just slap something that is already produced and ready to be mounted on a board.