Struct MmapRegion
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§
§impl<B> MmapRegion<B>where
B: NewBitmap,
impl<B> MmapRegion<B>where
B: NewBitmap,
pub fn new(size: usize) -> Result<MmapRegion<B>, Error>
pub fn new(size: usize) -> Result<MmapRegion<B>, Error>
Creates a shared anonymous mapping of size bytes.
§Arguments
size- The size of the memory region in bytes.
pub fn from_file(
file_offset: FileOffset,
size: usize,
) -> Result<MmapRegion<B>, Error>
pub fn from_file( file_offset: FileOffset, size: usize, ) -> Result<MmapRegion<B>, Error>
Creates a shared file mapping of size bytes.
§Arguments
file_offset- The mapping will be created at offsetfile_offset.startin the file referred to byfile_offset.file.size- The size of the memory region in bytes.
pub fn build(
file_offset: Option<FileOffset>,
size: usize,
prot: i32,
flags: i32,
) -> Result<MmapRegion<B>, Error>
pub fn build( file_offset: Option<FileOffset>, size: usize, prot: i32, flags: i32, ) -> Result<MmapRegion<B>, Error>
Creates a mapping based on the provided arguments.
§Arguments
file_offset- if provided, the method will create a file mapping at offsetfile_offset.startin 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.
pub unsafe fn build_raw(
addr: *mut u8,
size: usize,
prot: i32,
flags: i32,
) -> Result<MmapRegion<B>, Error>
pub unsafe fn build_raw( addr: *mut u8, size: usize, prot: i32, flags: i32, ) -> Result<MmapRegion<B>, 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 tommapfor 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.
§impl<B> MmapRegion<B>where
B: Bitmap,
impl<B> MmapRegion<B>where
B: Bitmap,
pub 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.
pub 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).
pub fn prot(&self) -> i32
pub fn prot(&self) -> i32
Returns the value of the prot parameter passed to mmap when mapping this region.
pub fn flags(&self) -> i32
pub fn flags(&self) -> i32
Returns the value of the flags parameter passed to mmap when mapping this region.
pub fn fds_overlap<T>(&self, other: &MmapRegion<T>) -> boolwhere
T: Bitmap,
pub fn fds_overlap<T>(&self, other: &MmapRegion<T>) -> boolwhere
T: Bitmap,
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.
pub fn set_hugetlbfs(&mut self, hugetlbfs: bool)
pub fn set_hugetlbfs(&mut self, hugetlbfs: bool)
Set the hugetlbfs of the region
pub fn is_hugetlbfs(&self) -> Option<bool>
pub fn is_hugetlbfs(&self) -> Option<bool>
Returns true if the region is hugetlbfs
Trait Implementations§
§impl<B> Debug for MmapRegion<B>where
B: Debug,
impl<B> Debug for MmapRegion<B>where
B: Debug,
§impl<B> VolatileMemory for MmapRegion<B>where
B: Bitmap,
impl<B> VolatileMemory for MmapRegion<B>where
B: Bitmap,
§fn get_slice(
&self,
offset: usize,
count: usize,
) -> Result<VolatileSlice<'_, <B as WithBitmapSlice<'_>>::S>, Error>
fn get_slice( &self, offset: usize, count: usize, ) -> Result<VolatileSlice<'_, <B as WithBitmapSlice<'_>>::S>, Error>
§fn as_volatile_slice(
&self,
) -> VolatileSlice<'_, <Self::B as WithBitmapSlice<'_>>::S>
fn as_volatile_slice( &self, ) -> VolatileSlice<'_, <Self::B as WithBitmapSlice<'_>>::S>
§fn get_ref<T>(
&self,
offset: usize,
) -> Result<VolatileRef<'_, T, <Self::B as WithBitmapSlice<'_>>::S>, Error>where
T: ByteValued,
fn get_ref<T>(
&self,
offset: usize,
) -> Result<VolatileRef<'_, T, <Self::B as WithBitmapSlice<'_>>::S>, Error>where
T: ByteValued,
VolatileRef at offset.§fn get_array_ref<T>(
&self,
offset: usize,
n: usize,
) -> Result<VolatileArrayRef<'_, T, <Self::B as WithBitmapSlice<'_>>::S>, Error>where
T: ByteValued,
fn get_array_ref<T>(
&self,
offset: usize,
n: usize,
) -> Result<VolatileArrayRef<'_, T, <Self::B as WithBitmapSlice<'_>>::S>, Error>where
T: ByteValued,
§unsafe fn aligned_as_ref<T>(&self, offset: usize) -> Result<&T, Error>where
T: ByteValued,
unsafe fn aligned_as_ref<T>(&self, offset: usize) -> Result<&T, Error>where
T: ByteValued,
§unsafe fn aligned_as_mut<T>(&self, offset: usize) -> Result<&mut T, Error>where
T: ByteValued,
unsafe fn aligned_as_mut<T>(&self, offset: usize) -> Result<&mut T, Error>where
T: ByteValued,
T at offset. Mutable accesses performed
using the resulting reference are not automatically accounted for by the dirty bitmap
tracking functionality. Read moreimpl<B> Send for MmapRegion<B>where
B: Send,
impl<B> Sync for MmapRegion<B>where
B: Sync,
Auto Trait Implementations§
impl<B> Freeze for MmapRegion<B>where
B: Freeze,
impl<B> RefUnwindSafe for MmapRegion<B>where
B: RefUnwindSafe,
impl<B> Unpin for MmapRegion<B>where
B: Unpin,
impl<B> UnwindSafe for MmapRegion<B>where
B: UnwindSafe,
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.