News for hackers. Stuff that matters.
Re:Is Rust Used Safely by Software Developers? by tialaramex on Friday July 16, 2021 @06:39PM (#27861999)
Looking at your "blink an LED" example this appears to end up in some code from svd2rust and in that code what's going on here is the write takes a closure which modifies the bits to be written (starting from the hardware default).

The unsafe thing being done here is calling w.bits() which is a method on w (the bits we're going to write to this register in the hardware) that allows the caller to set it to any value of their choosing, even values that nobody said are OK for this hardware.

There are two reasons why you might do this. Maybe your hardware was too lazy to provide safe ways to set every value that could be OK. This seems entirely plausible for the Raspberry Pi. Or, maybe you are crazy and you're writing values the hardware maker said never to use. Either way, Rust doesn't know anything about how the Raspberry Pi GPIO unit works and what bit values are OK.

This unsafe code does not write bits to registers. This isn't bypassing some imaginary safeguard that prevents touching stuff simultaneous to an ISR. It's critical to understand that.

The surrounding safe code performs the register write, as an atomic operation (AIUI a single hardware instruction on the Raspberry Pi) using the result of the closure.

> I'm not a Rust programmer, so be gentle with me.

> So at the end of the day it's just C with different syntax, and a lot more hoopla.

So what seems to have happened here is that you're completely ignorant of the topic and you've mistaken that for expertise. That's a bad habit to have developed, and it's important to break it.

There are no comments on this comment yet.