Struct MmapMemory

Source
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

Source

pub fn new( flags: u32, memory_size: usize, guest_address: GuestPhysAddr, huge_pages: bool, mergeable: bool, ) -> MmapMemory

Source

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.

Source

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 MaybeUninits.

Source

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.

Source

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.

Source

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.

Source

pub fn read<T>(&self, addr: GuestPhysAddr) -> Result<T, MemoryError>

Read the value in the memory at the given address

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for MmapMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MmapMemory

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Index<usize> for MmapMemory

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V