Struct vm_memory::mmap::MmapRegion
source · pub struct MmapRegion<B = ()> { /* private fields */ }
Expand description
Helper structure for working with mmaped memory regions in Unix.
The structure is used for accessing the guest’s physical memory by mmapping it into the current process.
§Limitations
When running a 64-bit virtual machine on a 32-bit hypervisor, only part of the guest’s physical memory may be mapped into the current process due to the limited virtual address space size of the process.
Implementations§
source§impl<B: NewBitmap> MmapRegion<B>
impl<B: NewBitmap> MmapRegion<B>
sourcepub fn new(size: usize) -> Result<Self, Error>
pub fn new(size: usize) -> Result<Self, Error>
Creates a shared anonymous mapping of size
bytes.
§Arguments
size
- The size of the memory region in bytes.
sourcepub fn from_file(file_offset: FileOffset, size: usize) -> Result<Self, Error>
pub fn from_file(file_offset: FileOffset, size: usize) -> Result<Self, Error>
Creates a shared file mapping of size
bytes.
§Arguments
file_offset
- The mapping will be created at offsetfile_offset.start
in the file referred to byfile_offset.file
.size
- The size of the memory region in bytes.
sourcepub fn build(
file_offset: Option<FileOffset>,
size: usize,
prot: i32,
flags: i32,
) -> Result<Self, Error>
pub fn build( file_offset: Option<FileOffset>, size: usize, prot: i32, flags: i32, ) -> Result<Self, Error>
Creates a mapping based on the provided arguments.
§Arguments
file_offset
- if provided, the method will create a file mapping at offsetfile_offset.start
in the file referred to byfile_offset.file
.size
- The size of the memory region in bytes.prot
- The desired memory protection of the mapping.flags
- This argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.
sourcepub unsafe fn build_raw(
addr: *mut u8,
size: usize,
prot: i32,
flags: i32,
) -> Result<Self, Error>
pub unsafe fn build_raw( addr: *mut u8, size: usize, prot: i32, flags: i32, ) -> Result<Self, Error>
Creates a MmapRegion
instance for an externally managed mapping.
This method is intended to be used exclusively in situations in which the mapping backing the region is provided by an entity outside the control of the caller (e.g. the dynamic linker).
§Arguments
addr
- Pointer to the start of the mapping. Must be page-aligned.size
- The size of the memory region in bytes.prot
- Must correspond to the memory protection attributes of the existing mapping.flags
- Must correspond to the flags that were passed tommap
for the creation of the existing mapping.
§Safety
To use this safely, the caller must guarantee that addr
and size
define a region within
a valid mapping that is already present in the process.
source§impl<B: Bitmap> MmapRegion<B>
impl<B: Bitmap> MmapRegion<B>
sourcepub fn as_ptr(&self) -> *mut u8
pub fn as_ptr(&self) -> *mut u8
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 file_offset(&self) -> Option<&FileOffset>
pub fn file_offset(&self) -> Option<&FileOffset>
Returns information regarding the offset into the file backing this region (if any).
sourcepub fn prot(&self) -> i32
pub fn prot(&self) -> i32
Returns the value of the prot
parameter passed to mmap
when mapping this region.
sourcepub fn flags(&self) -> i32
pub fn flags(&self) -> i32
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
pub fn fds_overlap<T: Bitmap>(&self, other: &MmapRegion<T>) -> bool
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 set_hugetlbfs(&mut self, hugetlbfs: bool)
pub fn set_hugetlbfs(&mut self, hugetlbfs: bool)
Set the hugetlbfs of the region
sourcepub fn is_hugetlbfs(&self) -> Option<bool>
pub fn is_hugetlbfs(&self) -> Option<bool>
Returns true
if the region is hugetlbfs
Trait Implementations§
source§impl<B: Debug> Debug for MmapRegion<B>
impl<B: Debug> Debug for MmapRegion<B>
source§impl<B> Drop for MmapRegion<B>
impl<B> Drop for MmapRegion<B>
source§impl<B: Bitmap> VolatileMemory for MmapRegion<B>
impl<B: Bitmap> VolatileMemory for MmapRegion<B>
source§fn as_volatile_slice(&self) -> VolatileSlice<'_, BS<'_, Self::B>>
fn as_volatile_slice(&self) -> VolatileSlice<'_, BS<'_, Self::B>>
source§fn get_ref<T: ByteValued>(
&self,
offset: usize,
) -> Result<VolatileRef<'_, T, BS<'_, Self::B>>>
fn get_ref<T: ByteValued>( &self, offset: usize, ) -> Result<VolatileRef<'_, T, BS<'_, Self::B>>>
VolatileRef
at offset
.source§fn get_array_ref<T: ByteValued>(
&self,
offset: usize,
n: usize,
) -> Result<VolatileArrayRef<'_, T, BS<'_, Self::B>>>
fn get_array_ref<T: ByteValued>( &self, offset: usize, n: usize, ) -> Result<VolatileArrayRef<'_, T, BS<'_, Self::B>>>
source§unsafe fn aligned_as_ref<T: ByteValued>(&self, offset: usize) -> Result<&T>
unsafe fn aligned_as_ref<T: ByteValued>(&self, offset: usize) -> Result<&T>
source§unsafe fn aligned_as_mut<T: ByteValued>(&self, offset: usize) -> Result<&mut T>
unsafe fn aligned_as_mut<T: ByteValued>(&self, offset: usize) -> Result<&mut T>
T
at offset
. Mutable accesses performed
using the resulting reference are not automatically accounted for by the dirty bitmap
tracking functionality. Read moresource§fn get_atomic_ref<T: AtomicInteger>(&self, offset: usize) -> Result<&T>
fn get_atomic_ref<T: AtomicInteger>(&self, offset: usize) -> Result<&T>
T
at offset
. Mutable accesses performed
using the resulting reference are not automatically accounted for by the dirty bitmap
tracking functionality. Read more