ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
jfsimon has quit [Remote host closed the connection]
jfsimon has joined #rust-embedded
cr1901_ has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
sroemer has joined #rust-embedded
majors has quit [Quit: ZNC 1.9.0+deb2build3 - https://znc.in]
majors has joined #rust-embedded
Noah[m] has quit [Quit: Idle timeout reached: 172800s]
emmanuelsearch[m has joined #rust-embedded
<emmanuelsearch[m> is there already a tentative date/location for the next f2f meeting of the embedded wg similar to what happened at RustWeek?
<emmanuelsearch[m> Context: we (Ariel OS folks) talk to ST folks later today and would like to suggest they show up next time ;)
<emmanuelsearch[m> maybe therealprof James Munns adamgreig you have info to share on this?
<emmanuelsearch[m> * is there already a tentative date/location for the next f2f meeting of the Rust Embedded wg similar to what happened at RustWeek?
<emmanuelsearch[m> * Context: we (Ariel OS folks) talk to ST folks later today and would like to invite them to show up next time ;)
<JamesMunns[m]> There's none planned
<JamesMunns[m]> Probably next rustweek?
<therealprof[m]> <emmanuelsearch[m> "is there already a tentative..." <- Yeah, sorry, nothing planned at this point.
<thejpster[m]> How about at Oxidize in Berlin in September?
<thejpster[m]> If that’s of interest I can ask the right people. Maybe concurrent with the workshops on day 1? Or the day after the conference?
cr1901 has quit [Read error: Connection reset by peer]
jfsimon has quit [Remote host closed the connection]
jfsimon has joined #rust-embedded
<thejpster[m]> I would point to `&str`, where creating a `&str` from random bytes without checking that they are valid UTF-8 is `unsafe`. But does making an invalid `&str` cause UB, or does it just cause the API to Not Work?
<dngrs[m]> hmmm, I think there was something written about std::fs and guarantees/checks that Rust cannot make. But where was that...
<dngrs[m]> "Note that, although read and write methods require a `&mut File`, because of the interfaces for [`Read`] and [`Write`], the holder of a `&File` can still modify the file, either through methods that take `&File` or by retrieving the underlying OS object and modifying the file that way. Additionally, many operating systems allow concurrent modification of files by different processes. Avoid assuming that holding a `&File` means that
<dngrs[m]> the file will not change." - https://doc.rust-lang.org/std/fs/struct.File.html#examples
<diondokter[m]> <thejpster[m]> "I would point to `&str`, where..." <- I think it can cause actual UB
<diondokter[m]> <thejpster[m]> "Well I got into an interesting..." <- > <@thejpster:matrix.org> Well I got into an interesting discussion today.... (full message at <https://catircservices.org/_irc/v1/media/download/AaZM2n9rDMcrPdDHwNNyHQ3fwqToNChE83NrcvQy8xcJN-MPxvNQLVjaWkYqrDVFLdTSaLKQb_EfgJDmLXkZPCi_8AAAAAAAAGNhdGlyY3NlcnZpY2VzLm9yZy9RaUdsenVzZW9WYWdZRnVYR253Zk5Ed1Y>)
<dngrs[m]> the [nomicon](https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html) might also be interesting here:
<dngrs[m]> > The Unsafe Rust code just can't trust the Safe Rust code to be written correctly. That said, BTreeMap will still behave completely erratically if you feed in values that don't have a total ordering. It just won't ever cause Undefined Behavior.
<dngrs[m]> (also what follows the paragraph I quoted)
<dngrs[m]> s/also/and/
<JamesMunns[m]> I agree w/ dion that calling unvalidated utf-8 can cause UB if the bytes are not valid
<JamesMunns[m]> IMO items like voltage regulator are not `unsafe`, because safety is a *language* construct, and the voltage regulator is part of the "system contract" with the language
<JamesMunns[m]> if you do something that makes your system invalid or to violate the systemic contract (e.g. unmapping the flash you are executing from), the program is invalid, not just unsafe
<dngrs[m]> #[deny(holding_it_wrong)]
<JamesMunns[m]> Violating the unsafe preconditions (in this case: from_utf8_unchecked) IS UB, even if it does not immediately cause a crash, or happens towork
<thejpster[m]> but why is it UB?
<thejpster[m]> actually, scratch that. I can dig into it myself.
<thejpster[m]> <dngrs[m]> "the [nomicon](https://doc.rust-..." <- This is excellent. Thanks!
<thejpster[m]> ok, so to ask a more pointed question ... why is it unsafe to steal an svd2rust handle to a Peripheral? What UB can you cause by racing on MMIO registers? They are all accessed using volatile loads and stores of CPU register size, which is equivalent to what AtomicU32 does.
Kaspar[m] has joined #rust-embedded
<Kaspar[m]> <thejpster[m]> "ok, so to ask a more pointed..." <- There could be something inside the implementation that assumes unique access, e.g., rmw. So code depends on nothing else modifying e.g., the registers. The type system *can* enforce this, unless bypassed. It might be that bypassing this causes memory safety issues (e.g., concurrent access to DMA peripheral), so it must be prohibited. So bypassing that contract is 'unsafe'.
<JamesMunns[m]> <thejpster[m]> "ok, so to ask a more pointed..." <- Disagree it is the same as atomic because volatile read/writes don't use ldrex/strex
<JamesMunns[m]> <thejpster[m]> "ok, so to ask a more pointed..." <- But as for why it is unsafe is mostly "vibes" and because it seemed reasonable at the time
<JamesMunns[m]> <thejpster[m]> "ok, so to ask a more pointed..." <- (Ah you mean just atomic load/stores, not atomic updates, separate load stores are memory safe but may not be correct)
<Kaspar[m]> JamesMunns[m]: My understanding was that this is about soundness.
<JamesMunns[m]> iirc chiptool doesn't make stealing unsafe, but you might get a ptr or something you have to deref? I forget
<JamesMunns[m]> If you have a moral "&mut" of the peripheral, that can't alias. But if you are clear you only have/need a shared ref to mutate, like atomics, it is morally fine
* thejpster[m] writes down “moral &mut”
<JamesMunns[m]> Yeah, if you accept an arbitrary ptr, definitely unsafe. If a known good pointer for a good location, that's kinda up to you to set the api as safe or not
<thejpster[m]> > “up to you”
<thejpster[m]> oh no
<JamesMunns[m]> By "moral &mut" I specifically mean:
<JamesMunns[m]> * If you ever make an &mut of struct you are pointing to, or
<JamesMunns[m]> * you allude to users that they can ASSUME they have exclusive access to the item while they hold an &mut
<JamesMunns[m]> if you ONLY use ptr methods (not mapped struct references), and ALWAYS tell users that anyone can alias at any time and they might observe tearing/lost writes/etc. and its up to them to CS that, then it's fine
<JamesMunns[m]> because you are not morally promising exclusivity in your API
<thejpster[m]> The compromise answer is probably a BSP that uses an atomicbool to let you safely create everything exactly once.
<JamesMunns[m]> (which I think svd used to do both, may only do the latter now)
<JamesMunns[m]> I mean that's what svd2rust does?
<JamesMunns[m]> its a CS bool, but yeah
<JamesMunns[m]> JamesMunns[m]: re: this: I'm noting the *exclusive* part of &mut is more important here than the *mutable* part.
<thejpster[m]> This was useful, thanks.
<JamesMunns[m]> because &mut pointers are both exclusive and mutable, vs & pointers
<thejpster[m]> A chapter for the embedonomicon perhaps
<dngrs[m]> mut stands for mutex 🤓
<thejpster[m]> And Handle(*mut T) should be clear about which of the above it is emulating
<JamesMunns[m]> Yep, just because it's ACTUALLY a ptr in the struct, doesn't mean that MORALLY it isn't, that's why `PhantomData` exists
<JamesMunns[m]> * it isn't something else, that's
<thejpster[m]> I wonder if it’s UB to create a PhantomData<&mut RegisterBlock>
<JamesMunns[m]> (Box is a good example of this: it's Just a pointer under the hood, but it plays nice with all the kinds of variance)
<JamesMunns[m]> to create it, afaik, no
<JamesMunns[m]> to use it as a bounds/guarantee of something, maybe
wassasin[m] has joined #rust-embedded
<wassasin[m]> thejpster[m]: That is how Embassy manages ownership https://github.com/embassy-rs/embassy/blob/main/embassy-hal-internal/src/peripheral.rs#L21
jfsimon has quit [Remote host closed the connection]
<jason-kairos[m]> suppose the map file for your binary shows a bunch of formatting operations related to a panic handler in some third party library
<jason-kairos[m]> is there some way to reduce the size of those sorts of error handlers?
jfsimon has joined #rust-embedded
<jannic[m]> IMHO unsafe should be used in a way that provides the most value. And therefore there is a large grey area where some judgement is required.... (full message at <https://catircservices.org/_irc/v1/media/download/AQpXaQqQzcYFIDsHa5TekRN4y_fh6bMhA-p2BXyhrAAzI16nvOHfSU0FtFPQ7VLOAkvwyEyQOzZQutVd6wma_kq_8AAAAAAAAGNhdGlyY3NlcnZpY2VzLm9yZy91VFRWS3ZNdnZXRmZJeXFBTnl6RnRvT1Q>)
<jason-kairos[m]> s/handler//
<thejpster[m]> I like that! Thanks jannic
ouilemur has quit [Quit: WeeChat 4.6.3]
sroemer has quit [Quit: WeeChat 4.5.2]
jfsimon has quit [Remote host closed the connection]
jfsimon has joined #rust-embedded
rainingmessages5 has joined #rust-embedded
rainingmessages has quit [Read error: Connection reset by peer]
rainingmessages5 is now known as rainingmessages
WSalmon_ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
WSalmon has joined #rust-embedded
WSalmon has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
WSalmon has joined #rust-embedded
ouilemur has joined #rust-embedded
Hallo124 has quit [Remote host closed the connection]
Hallo124 has joined #rust-embedded
WSalmon has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
WSalmon has joined #rust-embedded
WSalmon has quit [Remote host closed the connection]
WSalmon_ has joined #rust-embedded
RockBoynton[m] has quit [Quit: Idle timeout reached: 172800s]
Hallo124 has quit [Remote host closed the connection]
Hallo124 has joined #rust-embedded
DominicFischer[m has quit [Quit: Idle timeout reached: 172800s]
jfsimon has quit [Remote host closed the connection]
jfsimon has joined #rust-embedded
jfsimon has quit [Max SendQ exceeded]
jfsimon has joined #rust-embedded
jfsimon has quit [Remote host closed the connection]
jfsimon has joined #rust-embedded
jfsimon has quit [Remote host closed the connection]
jfsimon has joined #rust-embedded