Struct vm_memory::guest_memory::MemoryRegionAddress
source · [−]pub struct MemoryRegionAddress(pub u64);Expand description
Represents an offset inside a region.
Tuple Fields
0: u64Trait Implementations
sourceimpl Address for MemoryRegionAddress
impl Address for MemoryRegionAddress
sourcefn new(value: u64) -> MemoryRegionAddress
fn new(value: u64) -> MemoryRegionAddress
Creates an address from a raw address value.
sourcefn 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
sourcefn checked_add(&self, other: u64) -> Option<MemoryRegionAddress>
fn checked_add(&self, other: u64) -> Option<MemoryRegionAddress>
Computes self + other, returning None if overflow occurred.
sourcefn overflowing_add(&self, other: u64) -> (MemoryRegionAddress, bool)
fn overflowing_add(&self, other: u64) -> (MemoryRegionAddress, bool)
Computes self + other. Read more
sourcefn unchecked_add(&self, offset: u64) -> MemoryRegionAddress
fn unchecked_add(&self, offset: u64) -> MemoryRegionAddress
Computes self + offset. Read more
sourcefn 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.
sourcefn overflowing_sub(&self, other: u64) -> (MemoryRegionAddress, bool)
fn overflowing_sub(&self, other: u64) -> (MemoryRegionAddress, bool)
Computes self - other. Read more
sourcefn unchecked_sub(&self, other: u64) -> MemoryRegionAddress
fn unchecked_sub(&self, other: u64) -> MemoryRegionAddress
Computes self - other. Read more
sourcefn 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.
sourcefn 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
sourcefn 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.
sourcefn 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. Read more
sourceimpl AddressValue for MemoryRegionAddress
impl AddressValue for MemoryRegionAddress
sourceimpl BitAnd<u64> for MemoryRegionAddress
impl BitAnd<u64> for MemoryRegionAddress
type Output = MemoryRegionAddress
type Output = MemoryRegionAddress
The resulting type after applying the & operator.
sourcefn bitand(self, other: u64) -> MemoryRegionAddress
fn bitand(self, other: u64) -> MemoryRegionAddress
Performs the & operation. Read more
sourceimpl BitOr<u64> for MemoryRegionAddress
impl BitOr<u64> for MemoryRegionAddress
type Output = MemoryRegionAddress
type Output = MemoryRegionAddress
The resulting type after applying the | operator.
sourcefn bitor(self, other: u64) -> MemoryRegionAddress
fn bitor(self, other: u64) -> MemoryRegionAddress
Performs the | operation. Read more
sourceimpl<B: Bitmap> Bytes<MemoryRegionAddress> for GuestRegionMmap<B>
impl<B: Bitmap> Bytes<MemoryRegionAddress> for GuestRegionMmap<B>
sourcefn 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);sourcefn 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);sourcefn 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");sourcefn 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");sourcefn 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");sourcefn 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");sourcefn 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 more
sourcefn 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 more
sourcefn 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.
sourcefn 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.
sourceimpl Clone for MemoryRegionAddress
impl Clone for MemoryRegionAddress
sourcefn clone(&self) -> MemoryRegionAddress
fn clone(&self) -> MemoryRegionAddress
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 Debug for MemoryRegionAddress
impl Debug for MemoryRegionAddress
sourceimpl Default for MemoryRegionAddress
impl Default for MemoryRegionAddress
sourcefn default() -> MemoryRegionAddress
fn default() -> MemoryRegionAddress
Returns the “default value” for a type. Read more
sourceimpl Ord for MemoryRegionAddress
impl Ord for MemoryRegionAddress
sourcefn cmp(&self, other: &MemoryRegionAddress) -> Ordering
fn cmp(&self, other: &MemoryRegionAddress) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<MemoryRegionAddress> for MemoryRegionAddress
impl PartialEq<MemoryRegionAddress> for MemoryRegionAddress
sourcefn 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 ==. Read more
sourcefn ne(&self, other: &MemoryRegionAddress) -> bool
fn ne(&self, other: &MemoryRegionAddress) -> bool
This method tests for !=.
sourceimpl PartialOrd<MemoryRegionAddress> for MemoryRegionAddress
impl PartialOrd<MemoryRegionAddress> for MemoryRegionAddress
sourcefn partial_cmp(&self, other: &MemoryRegionAddress) -> Option<Ordering>
fn partial_cmp(&self, other: &MemoryRegionAddress) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn 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 more
impl Copy for MemoryRegionAddress
impl Eq for MemoryRegionAddress
impl StructuralEq for MemoryRegionAddress
impl StructuralPartialEq for MemoryRegionAddress
Auto Trait Implementations
impl RefUnwindSafe for MemoryRegionAddress
impl Send for MemoryRegionAddress
impl Sync for MemoryRegionAddress
impl Unpin for MemoryRegionAddress
impl UnwindSafe for MemoryRegionAddress
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