Skip to content

This crate is currently unsound due to spurious reads  #39

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() }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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