News for hackers. Stuff that matters.
Re:Writing an x86 bootloader in Rust that can launch vmlinux by grayhatter on Friday September 18, 2020 @09:30AM (#24516506)
So all all of rust's issues, and none of it's safety?
Re:Writing an x86 bootloader in Rust that can launch vmlinux by uxp100 on Friday September 18, 2020 @11:58AM (#24518404)
Honestly, many of rust’s safety promises don’t help the type of low level code I write, so I’m skeptical of the “embedded rust” push. But embedded is a huge field so some people will definitely benefit from what rust makes available.

But yeah, I think for some projects rust brings you a great type system, a gross syntax, and very little additional safety. But OTOH, on those projects writing rust will be not that different than writing C. Either language will still let you forget to sanitize a length value from an external struct that is put into a DMA engine. And either language will let you create a dangerous_u32 type that needs to be sanitized before your routines write it into a peripheral. But rust’s probably would be a little more ergonomic for the programmers, a little harder to use improperly, and involve pressing every punctuation mark on your keyboard.

Re:Writing an x86 bootloader in Rust that can launch vmlinux by mlindner on Friday September 18, 2020 @08:48PM (#24523627)
> Honestly, many of rust’s safety promises don’t help the type of low level code I write, so I’m skeptical of the “embedded rust” push. But embedded is a huge field so some people will definitely benefit from what rust makes available.

Why exactly? Once you write an abstraction on top of the raw addresses for configuring the hardware (usually already provided by a library) you don't need to use unsafe at all. One of the first things you do in C is write macros for all the addresses you use, writing safe wrappers isn't that much more complex than that.

Re:Writing an x86 bootloader in Rust that can launch vmlinux by uxp100 on Saturday September 19, 2020 @03:59PM (#24529987)
Because nothing the C code is doing would be "unsafe" in rust terms. What is the advantage rust has for following an SDMMC controller init sequence?
Re:Writing an x86 bootloader in Rust that can launch vmlinux by zaarn on Monday September 21, 2020 @10:50AM (#24544121)
Once you define a safe interface, you only have to audit the implementation of that interface for errors that aren't guarded for in unsafe code.

The safe interface you can then use without fearing memory corruption or having to audit that code for unsafety. Any safe code is pretty much only logic errors.

Re:Writing an x86 bootloader in Rust that can launch vmlinux by zaarn on Friday September 18, 2020 @09:53AM (#24516772)
You still get safety, if you write normal rust code then rust will largely behave the same.

But it allows you to for example to dereference raw pointers (and by proxy, allows pointer math).

A lot of unsafe functions become available, like unguarded array access (ie, you can go out of bounds of an array) but you have to explicitly do that.

Re:Writing an x86 bootloader in Rust that can launch vmlinux by Aengeuad on Friday September 18, 2020 @12:13PM (#24518608)
Using unsafe doesn't disable the safety features that Rust has like ownership rules or type safety, it's an acknowledgement that undefined behaviour can exist and that it's the programmers responsibility to ensure that undefined behaviour isn't introduced into safe Rust. There's no real way around this, if you want to write to arbitrary memory addresses Rust can't magically prove that you're doing so safely but if you can prove you're doing so safely then Rust will take care of the rest and make sure you're not introducing data races, use after free, buffer overflows, etc.
Re:Writing an x86 bootloader in Rust that can launch vmlinux by fortran77 on Friday September 18, 2020 @05:16PM (#24521953)
None of it is safety?

I would think some of it safety, like strong type checking. But, you're right in that this isn't the primary use case of Rust.

Re:Writing an x86 bootloader in Rust that can launch vmlinux by Ar-Curunir on Friday September 18, 2020 @11:39AM (#24518161)
No, you only face this in the unsafe code; the rest of your code is still safe.
Re:Writing an x86 bootloader in Rust that can launch vmlinux by johnisgood on Friday September 18, 2020 @09:44PM (#24524096)
No, unsafe code may affect the rest of your code (safe code).
Re:Writing an x86 bootloader in Rust that can launch vmlinux by zaarn on Monday September 21, 2020 @10:50AM (#24544129)
You only have to audit the unsafe code for unsoundness though.