Skip to content

Potential unsound casting from volatile_register::RW to the wrapped type #485

@shinmao

Description

@shinmao

Hi, I am wondering whether the casting here is unsound:

pub fn vect_active() -> VectActive {
let icsr =
unsafe { ptr::read_volatile(&(*SCB::PTR).icsr as *const _ as *const u32) } & 0x1FF;

Based on the definition, the wrapper struct volatile_register::RW (let me abbreviate it as vr here) didn't have stable layout, and rustc would preserve the right to insert padding or reorder the structure. vr<u32> should be declared as transparent; otherwise, casting it to u32 could lead to UB such as uninitialized memory exposure to ptr::read_volatile.

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