Skip to content

This crate is currently unsound due to spurious reads  #39

@matthunz

Description

@matthunz

As pointed out in japaric/vcell#10, crates like this that use references to mmio are unsound.

I propose a new design that only stores raw pointers to prevent this behavior.
We could then initialize the cell using addr_of_mut to avoid any creation of references before that data is initialized.

pub struct VolatileCell<T> {
    ptr: *mut T,
}

impl<T> VolatileCell<T> {
    pub fn new(ptr: *mut T) -> Self {
        Self { ptr }
    }

    pub fn get(&self) -> T
    where
        T: Copy,
    {
        unsafe { self.ptr.read_volatile() }
    }

    pub fn get_mut(&self) -> T
    where
        T: Copy,
    {
        unsafe { self.ptr.read_volatile() }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions