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
sourceimpl Address for GuestAddress
impl Address for GuestAddress
sourcefn new(value: u64) -> GuestAddress
fn new(value: u64) -> GuestAddress
Creates an address from a raw address value.
sourcefn 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
sourcefn checked_add(&self, other: u64) -> Option<GuestAddress>
fn checked_add(&self, other: u64) -> Option<GuestAddress>
Computes self + other
, returning None
if overflow occurred.
sourcefn overflowing_add(&self, other: u64) -> (GuestAddress, bool)
fn overflowing_add(&self, other: u64) -> (GuestAddress, bool)
Computes self + other
. Read more
sourcefn unchecked_add(&self, offset: u64) -> GuestAddress
fn unchecked_add(&self, offset: u64) -> GuestAddress
Computes self + offset
. Read more
sourcefn 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.
sourcefn overflowing_sub(&self, other: u64) -> (GuestAddress, bool)
fn overflowing_sub(&self, other: u64) -> (GuestAddress, bool)
Computes self - other
. Read more
sourcefn unchecked_sub(&self, other: u64) -> GuestAddress
fn unchecked_sub(&self, other: u64) -> GuestAddress
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 GuestAddress
impl AddressValue for GuestAddress
sourceimpl BitAnd<u64> for GuestAddress
impl BitAnd<u64> for GuestAddress
type Output = GuestAddress
type Output = GuestAddress
The resulting type after applying the &
operator.
sourcefn bitand(self, other: u64) -> GuestAddress
fn bitand(self, other: u64) -> GuestAddress
Performs the &
operation. Read more
sourceimpl BitOr<u64> for GuestAddress
impl BitOr<u64> for GuestAddress
type Output = GuestAddress
type Output = GuestAddress
The resulting type after applying the |
operator.
sourcefn bitor(self, other: u64) -> GuestAddress
fn bitor(self, other: u64) -> GuestAddress
Performs the |
operation. Read more
sourceimpl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T
impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T
sourcefn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<()>
fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<()>
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");
sourcefn read_slice(&self, buf: &mut [u8], addr: GuestAddress) -> Result<()>
fn read_slice(&self, buf: &mut [u8], addr: GuestAddress) -> Result<()>
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");
sourcefn read_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize
) -> Result<usize> where
F: Read,
fn read_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize
) -> Result<usize> 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");
sourcefn write_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize
) -> Result<usize> where
F: Write,
fn write_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize
) -> Result<usize> 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");
sourcefn write_all_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize
) -> Result<()> where
F: Write,
fn write_all_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize
) -> Result<()> 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");
sourcefn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize>
fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize>
Writes a slice into the container at addr
. Read more
sourcefn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize>
fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize>
Reads data from the container at addr
into a slice. Read more
sourcefn read_exact_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize
) -> Result<()> where
F: Read,
fn read_exact_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize
) -> Result<()> where
F: Read,
Reads exactly count
bytes from an object and writes them into the container at addr
. Read more
sourcefn store<O: AtomicAccess>(
&self,
val: O,
addr: GuestAddress,
order: Ordering
) -> Result<()>
fn store<O: AtomicAccess>(
&self,
val: O,
addr: GuestAddress,
order: Ordering
) -> Result<()>
Atomically store a value at the specified address.
sourcefn load<O: AtomicAccess>(
&self,
addr: GuestAddress,
order: Ordering
) -> Result<O>
fn load<O: AtomicAccess>(
&self,
addr: GuestAddress,
order: Ordering
) -> Result<O>
Atomically load a value from the specified address.
sourceimpl Clone for GuestAddress
impl Clone for GuestAddress
sourcefn clone(&self) -> GuestAddress
fn clone(&self) -> GuestAddress
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 GuestAddress
impl Debug for GuestAddress
sourceimpl Default for GuestAddress
impl Default for GuestAddress
sourcefn default() -> GuestAddress
fn default() -> GuestAddress
Returns the “default value” for a type. Read more
sourceimpl Ord for GuestAddress
impl Ord for GuestAddress
sourceimpl PartialEq<GuestAddress> for GuestAddress
impl PartialEq<GuestAddress> for GuestAddress
sourcefn 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 ==
. Read more
sourcefn ne(&self, other: &GuestAddress) -> bool
fn ne(&self, other: &GuestAddress) -> bool
This method tests for !=
.
sourceimpl PartialOrd<GuestAddress> for GuestAddress
impl PartialOrd<GuestAddress> for GuestAddress
sourcefn partial_cmp(&self, other: &GuestAddress) -> Option<Ordering>
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 · 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 GuestAddress
impl Eq for GuestAddress
impl StructuralEq for GuestAddress
impl StructuralPartialEq for GuestAddress
Auto Trait Implementations
impl RefUnwindSafe for GuestAddress
impl Send for GuestAddress
impl Sync for GuestAddress
impl Unpin for GuestAddress
impl UnwindSafe for GuestAddress
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more