Skip to content

References to MMIO space are (probably?) UB #4

@thejpster

Description

@thejpster

I was looking at tock-registers in detail for the first time today, and I think you have the same soundness issue that we fell over in the svd2rust generated output.

As far as we (me, and others in the Embedded Devices WG) can tell, it is UB to have a reference which points to MMIO address space. I believe tock-registers generates such MMIO references.

The UB comes about because references in Rust are marked as dereferencable when handed to LLVM, and that means LLVM is allowed to read from them whenever it likes. This would be incorrect for a reference to MMIO space, because the read may have side-effects. I think currently LLVM does not actually do any unexpected dereferencing, but it remains allowable.

I believe the only correct approach is to only ever construct pointers to MMIO space, and not references, and be very careful to never accidentally conjure up a reference. This is the approach taken by safe-mmio and derive-mmio, and is what svd2rust is working towards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions