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,

source

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,

source

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.

source

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.

source

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);
source

pub fn bitmap(&self) -> &B

Borrows the inner BitmapSlice.

source

pub fn store(&self, v: T)

Does a volatile write of the value v to the address of this ref.

source

pub fn load(&self) -> T

Does a volatile read of the value at the address of this ref.

source

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>

source§

fn clone(&self) -> VolatileRef<'a, T, B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, T: Debug, B: Debug> Debug for VolatileRef<'a, T, B>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'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>

§

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>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.