Struct vm_memory::volatile_memory::VolatileRef
source · pub struct VolatileRef<'a, T, B = ()> { /* private fields */ }
Expand description
A memory location that supports volatile access to an instance of T
.
§Examples
let mut v = 5u32;
let v_ref = unsafe { VolatileRef::new(&mut v as *mut u32 as *mut u8) };
assert_eq!(v, 5);
assert_eq!(v_ref.load(), 5);
v_ref.store(500);
assert_eq!(v, 500);
Implementations§
source§impl<'a, T> VolatileRef<'a, T, ()>where
T: ByteValued,
impl<'a, T> VolatileRef<'a, T, ()>where
T: ByteValued,
sourcepub unsafe fn new(addr: *mut u8) -> Self
pub unsafe fn new(addr: *mut u8) -> Self
Creates a VolatileRef
to an instance of T
.
§Safety
To use this safely, the caller must guarantee that the memory at addr
is big enough for a
T
and is available for the duration of the lifetime of the new VolatileRef
. The caller
must also guarantee that all other users of the given chunk of memory are using volatile
accesses.
source§impl<'a, T, B> VolatileRef<'a, T, B>where
T: ByteValued,
B: BitmapSlice,
impl<'a, T, B> VolatileRef<'a, T, B>where
T: ByteValued,
B: BitmapSlice,
sourcepub unsafe fn with_bitmap(addr: *mut u8, bitmap: B) -> Self
pub unsafe fn with_bitmap(addr: *mut u8, bitmap: B) -> Self
Creates a VolatileRef
to an instance of T
, using the
provided bitmap
object for dirty page tracking.
§Safety
To use this safely, the caller must guarantee that the memory at addr
is big enough for a
T
and is available for the duration of the lifetime of the new VolatileRef
. The caller
must also guarantee that all other users of the given chunk of memory are using volatile
accesses.
sourcepub fn as_ptr(&self) -> *mut u8
pub fn as_ptr(&self) -> *mut u8
Returns a pointer to the underlying memory. Mutable accesses performed using the resulting pointer are not automatically accounted for by the dirty bitmap tracking functionality.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Gets the size of the referenced type T
.
§Examples
let v_ref = unsafe { VolatileRef::<u32>::new(0 as *mut _) };
assert_eq!(v_ref.len(), size_of::<u32>() as usize);
sourcepub fn to_slice(&self) -> VolatileSlice<'a, B>
pub fn to_slice(&self) -> VolatileSlice<'a, B>
Converts this to a VolatileSlice
with the same size and
address.
Trait Implementations§
source§impl<'a, T: Clone, B: Clone> Clone for VolatileRef<'a, T, B>
impl<'a, T: Clone, B: Clone> Clone for VolatileRef<'a, T, B>
source§fn clone(&self) -> VolatileRef<'a, T, B>
fn clone(&self) -> VolatileRef<'a, T, B>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreimpl<'a, T: Copy, B: Copy> Copy for VolatileRef<'a, T, B>
Auto Trait Implementations§
impl<'a, T, B> Freeze for VolatileRef<'a, T, B>where
B: Freeze,
impl<'a, T, B> RefUnwindSafe for VolatileRef<'a, T, B>where
B: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, B = ()> !Send for VolatileRef<'a, T, B>
impl<'a, T, B = ()> !Sync for VolatileRef<'a, T, B>
impl<'a, T, B> Unpin for VolatileRef<'a, T, B>where
B: Unpin,
impl<'a, T, B> UnwindSafe for VolatileRef<'a, T, B>where
B: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)