[][src]Struct vm_memory::guest_memory::GuestAddress

pub struct GuestAddress(pub u64);

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.

Trait Implementations

impl Address for GuestAddress[src]

impl AddressValue for GuestAddress[src]

type V = u64

Type of the raw address value.

impl BitAnd<u64> for GuestAddress[src]

type Output = GuestAddress

The resulting type after applying the & operator.

impl BitOr<u64> for GuestAddress[src]

type Output = GuestAddress

The resulting type after applying the | operator.

impl<T: GuestMemory> Bytes<GuestAddress> for T[src]

type E = Error

Associated error codes

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

Examples

  • Write a slice at guestaddress 0x200.

    let start_addr = GuestAddress(0x1000);
    let mut gm =
            GuestMemoryMmap::from_ranges(&vec![(start_addr, 0x400)])
            .expect("Could not create guest memory");
    let res = gm.write_slice(&[1, 2, 3, 4, 5], start_addr);
    assert!(res.is_ok());

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

Examples

  • Read a slice of length 16 at guestaddress 0x200.

    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];
    let res = gm.read_slice(buf, start_addr);
    assert!(res.is_ok());

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

Examples

  • Read bytes from /dev/urandom

    let start_addr = GuestAddress(0x1000);
    let gm =
        GuestMemoryMmap::from_ranges(&vec![(start_addr, 0x400)])
        .expect("Could not create guest memory");
    let mut file = File::open(Path::new("/dev/urandom"))
        .expect("could not open /dev/urandom");
    let addr = GuestAddress(0x1010);
    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");

fn write_to<F>(
    &self,
    addr: GuestAddress,
    dst: &mut F,
    count: usize
) -> Result<usize> where
    F: Write
[src]

Examples

  • Write 128 bytes to /dev/null

    let start_addr = GuestAddress(0x1000);
    let gm =
        GuestMemoryMmap::from_ranges(&vec![(start_addr, 1024)])
        .expect("Could not create guest memory");
    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");

impl Clone for GuestAddress[src]

impl Copy for GuestAddress[src]

impl Debug for GuestAddress[src]

impl Default for GuestAddress[src]

impl Eq for GuestAddress[src]

impl Ord for GuestAddress[src]

impl PartialEq<GuestAddress> for GuestAddress[src]

impl PartialOrd<GuestAddress> for GuestAddress[src]

impl StructuralEq for GuestAddress[src]

impl StructuralPartialEq for GuestAddress[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.