pub struct MmapMemory {
pub flags: u32,
pub memory_size: usize,
pub guest_address: GuestPhysAddr,
pub host_address: *mut u8,
}
Expand description
A general purpose VM memory section that can exploit some Linux Kernel features.
Fields§
§flags: u32
§memory_size: usize
§guest_address: GuestPhysAddr
§host_address: *mut u8
Implementations§
Source§impl MmapMemory
impl MmapMemory
pub fn new( flags: u32, memory_size: usize, guest_address: GuestPhysAddr, huge_pages: bool, mergeable: bool, ) -> MmapMemory
Sourcepub unsafe fn as_slice_mut(&self) -> &mut [u8] ⓘ
pub unsafe fn as_slice_mut(&self) -> &mut [u8] ⓘ
This can create multiple aliasing. During the lifetime of the returned slice, the memory must not be altered, dropped or simmilar.
Sourcepub unsafe fn as_slice_uninit_mut(&self) -> &mut [MaybeUninit<u8>]
pub unsafe fn as_slice_uninit_mut(&self) -> &mut [MaybeUninit<u8>]
Same as [as_slice_mut
], but for MaybeUninit<u8>
. Actually the memory is initialized, as Mmap zero initializes it, but some fns like [hermit_entry::elf::load_kernel
] require MaybeUninit
s.
Sourcepub unsafe fn slice_at(
&self,
addr: GuestPhysAddr,
len: usize,
) -> Result<&[u8], MemoryError>
pub unsafe fn slice_at( &self, addr: GuestPhysAddr, len: usize, ) -> Result<&[u8], MemoryError>
Read a section of the memory.
§Safety
This is unsafe, as can create multiple aliasing. During the lifetime of the returned slice, the memory must not be altered to prevent undfined behaviour.
Sourcepub unsafe fn slice_at_mut(
&self,
addr: GuestPhysAddr,
len: usize,
) -> Result<&mut [u8], MemoryError>
pub unsafe fn slice_at_mut( &self, addr: GuestPhysAddr, len: usize, ) -> Result<&mut [u8], MemoryError>
Writeable access to a section of the memory.
§Safety
This is unsafe, as it can create multiple aliasing. During the lifetime of the returned slice, the memory must not be altered to prevent undfined behavior.
Sourcepub fn host_address(
&self,
addr: GuestPhysAddr,
) -> Result<*const u8, MemoryError>
pub fn host_address( &self, addr: GuestPhysAddr, ) -> Result<*const u8, MemoryError>
Returns the host address of the given internal physical address in the memory, if the address is valid.
Sourcepub fn read<T>(&self, addr: GuestPhysAddr) -> Result<T, MemoryError>
pub fn read<T>(&self, addr: GuestPhysAddr) -> Result<T, MemoryError>
Read the value in the memory at the given address
Sourcepub unsafe fn get_ref<T>(&self, addr: GuestPhysAddr) -> Result<&T, MemoryError>
pub unsafe fn get_ref<T>(&self, addr: GuestPhysAddr) -> Result<&T, MemoryError>
Get a reference to the type at the given address in the memory.
Sourcepub unsafe fn get_ref_mut<T>(
&self,
addr: GuestPhysAddr,
) -> Result<&mut T, MemoryError>
pub unsafe fn get_ref_mut<T>( &self, addr: GuestPhysAddr, ) -> Result<&mut T, MemoryError>
Get a mutable reference to the type at the given address in the memory.