Struct vm_memory::guest_memory::MemoryRegionAddress
source · pub struct MemoryRegionAddress(pub u64);
Expand description
Represents an offset inside a region.
Tuple Fields§
§0: u64
Trait Implementations§
source§impl Address for MemoryRegionAddress
impl Address for MemoryRegionAddress
source§fn new(value: u64) -> MemoryRegionAddress
fn new(value: u64) -> MemoryRegionAddress
Creates an address from a raw address value.
source§fn checked_offset_from(&self, base: MemoryRegionAddress) -> Option<u64>
fn checked_offset_from(&self, base: MemoryRegionAddress) -> Option<u64>
Computes the offset from this address to the given base address. Read more
source§fn checked_add(&self, other: u64) -> Option<MemoryRegionAddress>
fn checked_add(&self, other: u64) -> Option<MemoryRegionAddress>
Computes
self + other
, returning None
if overflow occurred.source§fn overflowing_add(&self, other: u64) -> (MemoryRegionAddress, bool)
fn overflowing_add(&self, other: u64) -> (MemoryRegionAddress, bool)
Computes
self + other
. Read moresource§fn unchecked_add(&self, offset: u64) -> MemoryRegionAddress
fn unchecked_add(&self, offset: u64) -> MemoryRegionAddress
Computes
self + offset
. Read moresource§fn checked_sub(&self, other: u64) -> Option<MemoryRegionAddress>
fn checked_sub(&self, other: u64) -> Option<MemoryRegionAddress>
Subtracts two addresses, checking for underflow. If underflow happens,
None
is returned.source§fn overflowing_sub(&self, other: u64) -> (MemoryRegionAddress, bool)
fn overflowing_sub(&self, other: u64) -> (MemoryRegionAddress, bool)
Computes
self - other
. Read moresource§fn unchecked_sub(&self, other: u64) -> MemoryRegionAddress
fn unchecked_sub(&self, other: u64) -> MemoryRegionAddress
Computes
self - other
. Read moresource§fn mask(&self, mask: Self::V) -> Self::V
fn mask(&self, mask: Self::V) -> Self::V
Returns the bitwise and of the address with the given mask.
source§fn unchecked_offset_from(&self, base: Self) -> Self::V
fn unchecked_offset_from(&self, base: Self) -> Self::V
Computes the offset from this address to the given base address. Read more
source§fn checked_align_up(&self, power_of_two: Self::V) -> Option<Self>
fn checked_align_up(&self, power_of_two: Self::V) -> Option<Self>
Returns self, aligned to the given power of two.
source§fn unchecked_align_up(&self, power_of_two: Self::V) -> Self
fn unchecked_align_up(&self, power_of_two: Self::V) -> Self
Returns self, aligned to the given power of two.
Only use this when the result is guaranteed not to overflow.
source§impl AddressValue for MemoryRegionAddress
impl AddressValue for MemoryRegionAddress
source§impl BitAnd<u64> for MemoryRegionAddress
impl BitAnd<u64> for MemoryRegionAddress
§type Output = MemoryRegionAddress
type Output = MemoryRegionAddress
The resulting type after applying the
&
operator.source§impl BitOr<u64> for MemoryRegionAddress
impl BitOr<u64> for MemoryRegionAddress
§type Output = MemoryRegionAddress
type Output = MemoryRegionAddress
The resulting type after applying the
|
operator.source§impl<B: Bitmap> Bytes<MemoryRegionAddress> for GuestRegionMmap<B>
impl<B: Bitmap> Bytes<MemoryRegionAddress> for GuestRegionMmap<B>
source§fn write(&self, buf: &[u8], addr: MemoryRegionAddress) -> Result<usize>
fn write(&self, buf: &[u8], addr: MemoryRegionAddress) -> Result<usize>
§Examples
- Write a slice at guest address 0x1200.
let res = gm
.write(&[1, 2, 3, 4, 5], GuestAddress(0x1200))
.expect("Could not write to guest memory");
assert_eq!(5, res);
source§fn read(&self, buf: &mut [u8], addr: MemoryRegionAddress) -> Result<usize>
fn read(&self, buf: &mut [u8], addr: MemoryRegionAddress) -> Result<usize>
§Examples
- Read a slice of length 16 at guestaddress 0x1200.
let buf = &mut [0u8; 16];
let res = gm
.read(buf, GuestAddress(0x1200))
.expect("Could not read from guest memory");
assert_eq!(16, res);
source§fn read_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<usize>where
F: Read,
fn read_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<usize>where
F: Read,
§Examples
- Read bytes from /dev/urandom
let mut file = File::open(Path::new("/dev/urandom")).expect("Could not open /dev/urandom");
gm.read_from(addr, &mut file, 128)
.expect("Could not read from /dev/urandom into guest memory");
let read_addr = addr.checked_add(8).expect("Could not compute read address");
let rand_val: u32 = gm
.read_obj(read_addr)
.expect("Could not read u32 val from /dev/urandom");
source§fn read_exact_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<()>where
F: Read,
fn read_exact_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<()>where
F: Read,
§Examples
- Read bytes from /dev/urandom
let mut file = File::open(Path::new("/dev/urandom")).expect("Could not open /dev/urandom");
gm.read_exact_from(addr, &mut file, 128)
.expect("Could not read from /dev/urandom into guest memory");
let read_addr = addr.checked_add(8).expect("Could not compute read address");
let rand_val: u32 = gm
.read_obj(read_addr)
.expect("Could not read u32 val from /dev/urandom");
source§fn write_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<usize>where
F: Write,
fn write_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<usize>where
F: Write,
Writes data from the region to a writable object.
§Examples
- Write 128 bytes to a /dev/null file
let mut file = OpenOptions::new()
.write(true)
.open("/dev/null")
.expect("Could not open /dev/null");
gm.write_to(start_addr, &mut file, 128)
.expect("Could not write to file from guest memory");
source§fn write_all_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<()>where
F: Write,
fn write_all_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<()>where
F: Write,
Writes data from the region to a writable object.
§Examples
- Write 128 bytes to a /dev/null file
let mut file = OpenOptions::new()
.write(true)
.open("/dev/null")
.expect("Could not open /dev/null");
gm.write_all_to(start_addr, &mut file, 128)
.expect("Could not write to file from guest memory");
source§fn write_slice(&self, buf: &[u8], addr: MemoryRegionAddress) -> Result<()>
fn write_slice(&self, buf: &[u8], addr: MemoryRegionAddress) -> Result<()>
Writes the entire content of a slice into the container at
addr
. Read moresource§fn read_slice(&self, buf: &mut [u8], addr: MemoryRegionAddress) -> Result<()>
fn read_slice(&self, buf: &mut [u8], addr: MemoryRegionAddress) -> Result<()>
Reads data from the container at
addr
to fill an entire slice. Read moresource§fn store<T: AtomicAccess>(
&self,
val: T,
addr: MemoryRegionAddress,
order: Ordering,
) -> Result<()>
fn store<T: AtomicAccess>( &self, val: T, addr: MemoryRegionAddress, order: Ordering, ) -> Result<()>
Atomically store a value at the specified address.
source§fn load<T: AtomicAccess>(
&self,
addr: MemoryRegionAddress,
order: Ordering,
) -> Result<T>
fn load<T: AtomicAccess>( &self, addr: MemoryRegionAddress, order: Ordering, ) -> Result<T>
Atomically load a value from the specified address.
source§impl Clone for MemoryRegionAddress
impl Clone for MemoryRegionAddress
source§fn clone(&self) -> MemoryRegionAddress
fn clone(&self) -> MemoryRegionAddress
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for MemoryRegionAddress
impl Debug for MemoryRegionAddress
source§impl Default for MemoryRegionAddress
impl Default for MemoryRegionAddress
source§fn default() -> MemoryRegionAddress
fn default() -> MemoryRegionAddress
Returns the “default value” for a type. Read more
source§impl Ord for MemoryRegionAddress
impl Ord for MemoryRegionAddress
source§fn cmp(&self, other: &MemoryRegionAddress) -> Ordering
fn cmp(&self, other: &MemoryRegionAddress) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for MemoryRegionAddress
impl PartialEq for MemoryRegionAddress
source§fn eq(&self, other: &MemoryRegionAddress) -> bool
fn eq(&self, other: &MemoryRegionAddress) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for MemoryRegionAddress
impl PartialOrd for MemoryRegionAddress
source§fn partial_cmp(&self, other: &MemoryRegionAddress) -> Option<Ordering>
fn partial_cmp(&self, other: &MemoryRegionAddress) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for MemoryRegionAddress
impl Eq for MemoryRegionAddress
impl StructuralPartialEq for MemoryRegionAddress
Auto Trait Implementations§
impl Freeze for MemoryRegionAddress
impl RefUnwindSafe for MemoryRegionAddress
impl Send for MemoryRegionAddress
impl Sync for MemoryRegionAddress
impl Unpin for MemoryRegionAddress
impl UnwindSafe for MemoryRegionAddress
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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)