Struct vm_memory::guest_memory::GuestAddress

source ·
pub struct GuestAddress(pub u64);
Expand description

Represents a guest physical address (GPA).

§Notes:

On ARM64, a 32-bit hypervisor may be used to support a 64-bit guest. For simplicity, u64 is used to store the the raw value no matter if the guest a 32-bit or 64-bit virtual machine.

Tuple Fields§

§0: u64

Trait Implementations§

source§

impl Address for GuestAddress

source§

fn new(value: u64) -> GuestAddress

Creates an address from a raw address value.
source§

fn raw_value(&self) -> u64

Returns the raw value of the address.
source§

fn checked_offset_from(&self, base: GuestAddress) -> Option<u64>

Computes the offset from this address to the given base address. Read more
source§

fn checked_add(&self, other: u64) -> Option<GuestAddress>

Computes self + other, returning None if overflow occurred.
source§

fn overflowing_add(&self, other: u64) -> (GuestAddress, bool)

Computes self + other. Read more
source§

fn unchecked_add(&self, offset: u64) -> GuestAddress

Computes self + offset. Read more
source§

fn checked_sub(&self, other: u64) -> Option<GuestAddress>

Subtracts two addresses, checking for underflow. If underflow happens, None is returned.
source§

fn overflowing_sub(&self, other: u64) -> (GuestAddress, bool)

Computes self - other. Read more
source§

fn unchecked_sub(&self, other: u64) -> GuestAddress

Computes self - other. Read more
source§

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

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>

Returns self, aligned to the given power of two.
source§

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 GuestAddress

source§

type V = u64

Type of the raw address value.
source§

fn zero() -> Self::V

Return the value zero, coerced into the value type Self::V
source§

fn one() -> Self::V

Return the value zero, coerced into the value type Self::V
source§

impl BitAnd<u64> for GuestAddress

source§

type Output = GuestAddress

The resulting type after applying the & operator.
source§

fn bitand(self, other: u64) -> GuestAddress

Performs the & operation. Read more
source§

impl BitOr<u64> for GuestAddress

source§

type Output = GuestAddress

The resulting type after applying the | operator.
source§

fn bitor(self, other: u64) -> GuestAddress

Performs the | operation. Read more
source§

impl Clone for GuestAddress

source§

fn clone(&self) -> GuestAddress

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 Debug for GuestAddress

source§

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

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

impl Default for GuestAddress

source§

fn default() -> GuestAddress

Returns the “default value” for a type. Read more
source§

impl Ord for GuestAddress

source§

fn cmp(&self, other: &GuestAddress) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for GuestAddress

source§

fn eq(&self, other: &GuestAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for GuestAddress

source§

fn partial_cmp(&self, other: &GuestAddress) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for GuestAddress

source§

impl Eq for GuestAddress

source§

impl StructuralPartialEq for GuestAddress

Auto Trait Implementations§

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> Bytes<GuestAddress> for T
where T: GuestMemory + ?Sized,

source§

fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<(), Error>

§Examples
  • Write a slice at guestaddress 0x1000. (uses the backend-mmap feature)
gm.write_slice(&[1, 2, 3, 4, 5], start_addr)
    .expect("Could not write slice to guest memory");
source§

fn read_slice(&self, buf: &mut [u8], addr: GuestAddress) -> Result<(), Error>

§Examples
  • Read a slice of length 16 at guestaddress 0x1000. (uses the backend-mmap feature)
let start_addr = GuestAddress(0x1000);
let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
    .expect("Could not create guest memory");
let buf = &mut [0u8; 16];

gm.read_slice(buf, start_addr)
    .expect("Could not read slice from guest memory");
source§

fn read_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<usize, Error>
where F: Read,

§Examples
  • Read bytes from /dev/urandom (uses the backend-mmap feature)
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 write_to<F>( &self, addr: GuestAddress, dst: &mut F, count: usize, ) -> Result<usize, Error>
where F: Write,

§Examples
  • Write 128 bytes to /dev/null (uses the backend-mmap feature)
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 128 bytes to the provided address");
source§

fn write_all_to<F>( &self, addr: GuestAddress, dst: &mut F, count: usize, ) -> Result<(), Error>
where F: Write,

§Examples
  • Write 128 bytes to /dev/null (uses the backend-mmap feature)
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 128 bytes to the provided address");
source§

type E = Error

Associated error codes
source§

fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>

Writes a slice into the container at addr. Read more
source§

fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>

Reads data from the container at addr into a slice. Read more
source§

fn read_exact_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<(), Error>
where F: Read,

Reads exactly count bytes from an object and writes them into the container at addr. Read more
source§

fn store<O>( &self, val: O, addr: GuestAddress, order: Ordering, ) -> Result<(), Error>
where O: AtomicAccess,

Atomically store a value at the specified address.
source§

fn load<O>(&self, addr: GuestAddress, order: Ordering) -> Result<O, Error>
where O: AtomicAccess,

Atomically load a value from the specified address.
source§

fn write_obj<T: ByteValued>(&self, val: T, addr: A) -> Result<(), Self::E>

Writes an object into the container at addr. Read more
source§

fn read_obj<T: ByteValued>(&self, addr: A) -> Result<T, Self::E>

Reads an object from the container at addr. Read more
source§

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

source§

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>,

source§

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>,

source§

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.