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
sourceimpl<'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.
sourceimpl<'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
sourceimpl<'a, T: Clone, B: Clone> Clone for VolatileRef<'a, T, B>
impl<'a, T: Clone, B: Clone> Clone for VolatileRef<'a, T, B>
sourcefn clone(&self) -> VolatileRef<'a, T, B>
fn clone(&self) -> VolatileRef<'a, T, B>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<'a, T: Debug, B: Debug> Debug for VolatileRef<'a, T, B>
impl<'a, T: Debug, B: Debug> Debug for VolatileRef<'a, T, B>
impl<'a, T: Copy, B: Copy> Copy for VolatileRef<'a, T, B>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more