Closed
Description
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
Labels
No labels