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
impl Address for GuestAddress
source§fn new(value: u64) -> GuestAddress
fn new(value: u64) -> GuestAddress
Creates an address from a raw address value.
source§fn checked_offset_from(&self, base: GuestAddress) -> Option<u64>
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>
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)
fn overflowing_add(&self, other: u64) -> (GuestAddress, bool)
Computes
self + other
. Read moresource§fn unchecked_add(&self, offset: u64) -> GuestAddress
fn unchecked_add(&self, offset: u64) -> GuestAddress
Computes
self + offset
. Read moresource§fn checked_sub(&self, other: u64) -> Option<GuestAddress>
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)
fn overflowing_sub(&self, other: u64) -> (GuestAddress, bool)
Computes
self - other
. Read moresource§fn unchecked_sub(&self, other: u64) -> GuestAddress
fn unchecked_sub(&self, other: u64) -> GuestAddress
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 GuestAddress
impl AddressValue for GuestAddress
source§impl BitAnd<u64> for GuestAddress
impl BitAnd<u64> for GuestAddress
§type Output = GuestAddress
type Output = GuestAddress
The resulting type after applying the
&
operator.source§impl BitOr<u64> for GuestAddress
impl BitOr<u64> for GuestAddress
§type Output = GuestAddress
type Output = GuestAddress
The resulting type after applying the
|
operator.source§impl Clone for GuestAddress
impl Clone for GuestAddress
source§fn clone(&self) -> GuestAddress
fn clone(&self) -> GuestAddress
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 GuestAddress
impl Debug for GuestAddress
source§impl Default for GuestAddress
impl Default for GuestAddress
source§fn default() -> GuestAddress
fn default() -> GuestAddress
Returns the “default value” for a type. Read more
source§impl Ord for GuestAddress
impl Ord for GuestAddress
source§fn cmp(&self, other: &GuestAddress) -> Ordering
fn cmp(&self, other: &GuestAddress) -> 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 GuestAddress
impl PartialEq for GuestAddress
source§fn eq(&self, other: &GuestAddress) -> bool
fn eq(&self, other: &GuestAddress) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for GuestAddress
impl PartialOrd for GuestAddress
source§fn partial_cmp(&self, other: &GuestAddress) -> Option<Ordering>
fn partial_cmp(&self, other: &GuestAddress) -> 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 GuestAddress
impl Eq for GuestAddress
impl StructuralPartialEq for GuestAddress
Auto Trait Implementations§
impl Freeze for GuestAddress
impl RefUnwindSafe for GuestAddress
impl Send for GuestAddress
impl Sync for GuestAddress
impl Unpin for GuestAddress
impl UnwindSafe for GuestAddress
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> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
impl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
source§fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<(), Error>
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>
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,
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,
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,
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§fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
Writes a slice into the container at
addr
. Read moresource§fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>
fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>
Reads data from the container at
addr
into a slice. Read moresource§fn read_exact_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: Read,
fn read_exact_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: Read,
source§fn store<O>(
&self,
val: O,
addr: GuestAddress,
order: Ordering,
) -> Result<(), Error>where
O: AtomicAccess,
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,
fn load<O>(&self, addr: GuestAddress, order: Ordering) -> Result<O, Error>where
O: AtomicAccess,
Atomically load a value from the specified address.
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
)