pub struct GuestRegionMmap<B = ()> { /* private fields */ }
backend-mmap
only.Expand description
GuestMemoryRegion
implementation that mmaps the guest’s
memory region in the current process.
Represents a continuous region of the guest’s physical memory that is backed by a mapping in the virtual address space of the calling process.
Implementations§
Source§impl<B: Bitmap> GuestRegionMmap<B>
impl<B: Bitmap> GuestRegionMmap<B>
Sourcepub fn new(
mapping: MmapRegion<B>,
guest_base: GuestAddress,
) -> Result<Self, Error>
pub fn new( mapping: MmapRegion<B>, guest_base: GuestAddress, ) -> Result<Self, Error>
Create a new memory-mapped memory region for the guest’s physical memory.
Source§impl<B: NewBitmap> GuestRegionMmap<B>
impl<B: NewBitmap> GuestRegionMmap<B>
Sourcepub fn from_range(
addr: GuestAddress,
size: usize,
file: Option<FileOffset>,
) -> Result<Self, Error>
Available on crate feature xen
only.
pub fn from_range( addr: GuestAddress, size: usize, file: Option<FileOffset>, ) -> Result<Self, Error>
xen
only.Create a new Unix memory-mapped memory region from guest’s physical memory, size and file. This must only be used for tests, doctests, benches and is not designed for end consumers.
Methods from Deref<Target = MmapRegion<B>>§
Sourcepub fn as_ptr(&self) -> *mut u8
Available on crate feature xen
and Unix only.
pub fn as_ptr(&self) -> *mut u8
xen
and Unix only.Returns a pointer to the beginning of the memory region. Mutable accesses performed using the resulting pointer are not automatically accounted for by the dirty bitmap tracking functionality.
Should only be used for passing this region to ioctls for setting guest memory.
Sourcepub fn size(&self) -> usize
Available on crate feature xen
and Unix only.
pub fn size(&self) -> usize
xen
and Unix only.Returns the size of this region.
Sourcepub fn file_offset(&self) -> Option<&FileOffset>
Available on crate feature xen
and Unix only.
pub fn file_offset(&self) -> Option<&FileOffset>
xen
and Unix only.Returns information regarding the offset into the file backing this region (if any).
Sourcepub fn prot(&self) -> i32
Available on crate feature xen
and Unix only.
pub fn prot(&self) -> i32
xen
and Unix only.Returns the value of the prot
parameter passed to mmap
when mapping this region.
Sourcepub fn flags(&self) -> i32
Available on crate feature xen
and Unix only.
pub fn flags(&self) -> i32
xen
and Unix only.Returns the value of the flags
parameter passed to mmap
when mapping this region.
Sourcepub fn fds_overlap<T: Bitmap>(&self, other: &MmapRegion<T>) -> bool
Available on crate feature xen
and Unix only.
pub fn fds_overlap<T: Bitmap>(&self, other: &MmapRegion<T>) -> bool
xen
and Unix only.Checks whether this region and other
are backed by overlapping
FileOffset
objects.
This is mostly a sanity check available for convenience, as different file descriptors can alias the same file.
Sourcepub fn is_hugetlbfs(&self) -> Option<bool>
Available on crate feature xen
and Unix only.
pub fn is_hugetlbfs(&self) -> Option<bool>
xen
and Unix only.Returns true
if the region is hugetlbfs
Sourcepub fn bitmap(&self) -> &B
Available on crate feature xen
and Unix only.
pub fn bitmap(&self) -> &B
xen
and Unix only.Returns a reference to the inner bitmap object.
Sourcepub fn xen_mmap_flags(&self) -> u32
Available on crate feature xen
and Unix only.
pub fn xen_mmap_flags(&self) -> u32
xen
and Unix only.Returns xen mmap flags.
Sourcepub fn xen_mmap_data(&self) -> u32
Available on crate feature xen
and Unix only.
pub fn xen_mmap_data(&self) -> u32
xen
and Unix only.Returns xen mmap data.
Trait Implementations§
Source§impl<B: Bitmap> Bytes<MemoryRegionAddress> for GuestRegionMmap<B>
impl<B: Bitmap> Bytes<MemoryRegionAddress> for GuestRegionMmap<B>
Source§fn 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);
Source§fn 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);
Source§fn read_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<usize>where
F: Read,
👎Deprecated: Use .read_volatile_from
or the functions of the ReadVolatile
trait instead
fn read_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<usize>where
F: Read,
.read_volatile_from
or the functions of the ReadVolatile
trait instead§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");
Source§fn read_exact_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<()>where
F: Read,
👎Deprecated: Use .read_exact_volatile_from
or the functions of the ReadVolatile
trait instead
fn read_exact_from<F>(
&self,
addr: MemoryRegionAddress,
src: &mut F,
count: usize,
) -> Result<()>where
F: Read,
.read_exact_volatile_from
or the functions of the ReadVolatile
trait instead§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");
Source§fn write_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<usize>where
F: Write,
👎Deprecated: Use .write_volatile_to
or the functions of the WriteVolatile
trait instead
fn write_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<usize>where
F: Write,
.write_volatile_to
or the functions of the WriteVolatile
trait insteadWrites 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");
Source§fn write_all_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<()>where
F: Write,
👎Deprecated: Use .write_all_volatile_to
or the functions of the WriteVolatile
trait instead
fn write_all_to<F>(
&self,
addr: MemoryRegionAddress,
dst: &mut F,
count: usize,
) -> Result<()>where
F: Write,
.write_all_volatile_to
or the functions of the WriteVolatile
trait insteadWrites 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");
Source§fn write_slice(&self, buf: &[u8], addr: MemoryRegionAddress) -> Result<()>
fn write_slice(&self, buf: &[u8], addr: MemoryRegionAddress) -> Result<()>
addr
. Read moreSource§fn read_slice(&self, buf: &mut [u8], addr: MemoryRegionAddress) -> Result<()>
fn read_slice(&self, buf: &mut [u8], addr: MemoryRegionAddress) -> Result<()>
addr
to fill an entire slice. Read moreSource§fn store<T: AtomicAccess>(
&self,
val: T,
addr: MemoryRegionAddress,
order: Ordering,
) -> Result<()>
fn store<T: AtomicAccess>( &self, val: T, addr: MemoryRegionAddress, order: Ordering, ) -> Result<()>
Source§fn load<T: AtomicAccess>(
&self,
addr: MemoryRegionAddress,
order: Ordering,
) -> Result<T>
fn load<T: AtomicAccess>( &self, addr: MemoryRegionAddress, order: Ordering, ) -> Result<T>
Source§impl<B: Debug> Debug for GuestRegionMmap<B>
impl<B: Debug> Debug for GuestRegionMmap<B>
Source§impl<B> Deref for GuestRegionMmap<B>
impl<B> Deref for GuestRegionMmap<B>
Source§type Target = MmapRegion<B>
type Target = MmapRegion<B>
Source§fn deref(&self) -> &MmapRegion<B>
fn deref(&self) -> &MmapRegion<B>
Source§impl<B: Bitmap> GuestMemoryRegion for GuestRegionMmap<B>
impl<B: Bitmap> GuestMemoryRegion for GuestRegionMmap<B>
Source§fn len(&self) -> GuestUsize
fn len(&self) -> GuestUsize
Source§fn start_addr(&self) -> GuestAddress
fn start_addr(&self) -> GuestAddress
Source§fn get_host_address(&self, addr: MemoryRegionAddress) -> Result<*mut u8>
fn get_host_address(&self, addr: MemoryRegionAddress) -> Result<*mut u8>
Source§fn file_offset(&self) -> Option<&FileOffset>
fn file_offset(&self) -> Option<&FileOffset>
Source§fn get_slice(
&self,
offset: MemoryRegionAddress,
count: usize,
) -> Result<VolatileSlice<'_, BS<'_, B>>>
fn get_slice( &self, offset: MemoryRegionAddress, count: usize, ) -> Result<VolatileSlice<'_, BS<'_, B>>>
Source§fn is_hugetlbfs(&self) -> Option<bool>
fn is_hugetlbfs(&self) -> Option<bool>
HugeTLBFS
.
Returns Some(true) if the region is backed by hugetlbfs.
None represents that no information is available. Read moreSource§fn last_addr(&self) -> GuestAddress
fn last_addr(&self) -> GuestAddress
Source§fn check_address(
&self,
addr: MemoryRegionAddress,
) -> Option<MemoryRegionAddress>
fn check_address( &self, addr: MemoryRegionAddress, ) -> Option<MemoryRegionAddress>
Source§fn address_in_range(&self, addr: MemoryRegionAddress) -> bool
fn address_in_range(&self, addr: MemoryRegionAddress) -> bool
true
if the given address is within this region.