pub struct MemoryMappingArena {
    addr: *mut u8,
    size: usize,
}
Expand description

Tracks Fixed Memory Maps within an anonymous memory-mapped fixed-sized arena in the current process.

Fields§

§addr: *mut u8§size: usize

Implementations§

source§

impl MemoryMappingArena

source

pub fn new(size: usize) -> Result<MemoryMappingArena>

Creates an mmap arena of size bytes.

§Arguments
  • size - Size of memory region in bytes.
source

pub fn add_anon_protection( &mut self, offset: usize, size: usize, prot: Protection ) -> Result<()>

Anonymously maps size bytes at offset bytes from the start of the arena with prot protections. offset must be page aligned.

§Arguments
  • offset - Page aligned offset into the arena in bytes.
  • size - Size of memory region in bytes.
  • prot - Protection (e.g. readable/writable) of the memory region.
source

pub fn add_anon(&mut self, offset: usize, size: usize) -> Result<()>

Anonymously maps size bytes at offset bytes from the start of the arena. offset must be page aligned.

§Arguments
  • offset - Page aligned offset into the arena in bytes.
  • size - Size of memory region in bytes.
source

pub fn add_fd( &mut self, offset: usize, size: usize, fd: &dyn AsRawDescriptor ) -> Result<()>

Maps size bytes from the start of the given fd at offset bytes from the start of the arena. offset must be page aligned.

§Arguments
  • offset - Page aligned offset into the arena in bytes.
  • size - Size of memory region in bytes.
  • fd - File descriptor to mmap from.
source

pub fn add_fd_offset( &mut self, offset: usize, size: usize, fd: &dyn AsRawDescriptor, fd_offset: u64 ) -> Result<()>

Maps size bytes starting at fs_offset bytes from within the given fd at offset bytes from the start of the arena. offset must be page aligned.

§Arguments
  • offset - Page aligned offset into the arena in bytes.
  • size - Size of memory region in bytes.
  • fd - File descriptor to mmap from.
  • fd_offset - Offset in bytes from the beginning of fd to start the mmap.
source

pub fn add_fd_offset_protection( &mut self, offset: usize, size: usize, fd: &dyn AsRawDescriptor, fd_offset: u64, prot: Protection ) -> Result<()>

Maps size bytes starting at fs_offset bytes from within the given fd at offset bytes from the start of the arena with prot protections. offset must be page aligned.

§Arguments
  • offset - Page aligned offset into the arena in bytes.
  • size - Size of memory region in bytes.
  • fd - File descriptor to mmap from.
  • fd_offset - Offset in bytes from the beginning of fd to start the mmap.
  • prot - Protection (e.g. readable/writable) of the memory region.
source

fn try_add( &mut self, offset: usize, size: usize, prot: Protection, fd: Option<(&dyn AsRawDescriptor, u64)> ) -> Result<()>

Helper method that calls appropriate MemoryMapping constructor and adds the resulting map into the arena.

source

pub fn remove(&mut self, offset: usize, size: usize) -> Result<()>

Removes size bytes at offset bytes from the start of the arena. offset must be page aligned.

§Arguments
  • offset - Page aligned offset into the arena in bytes.
  • size - Size of memory region in bytes.

Trait Implementations§

source§

impl Drop for MemoryMappingArena

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<MemoryMapping> for MemoryMappingArena

source§

fn from(mmap: MemoryMapping) -> Self

Converts to this type from the input type.
source§

impl From<MemoryMapping> for MemoryMappingArena

source§

fn from(mmap: CrateMemoryMapping) -> Self

Converts to this type from the input type.
source§

impl MappedRegion for MemoryMappingArena

source§

fn as_ptr(&self) -> *mut u8

Returns a pointer to the beginning of the memory region. Should only be used for passing this region to ioctls for setting guest memory.
source§

fn size(&self) -> usize

Returns the size of the memory region in bytes.
source§

fn add_fd_mapping( &mut self, offset: usize, size: usize, fd: &dyn AsRawDescriptor, fd_offset: u64, prot: Protection ) -> Result<()>

Maps size bytes starting at fd_offset bytes from within the given fd at offset bytes from the start of the region with prot protections. offset must be page aligned. Read more
source§

fn remove_mapping(&mut self, offset: usize, size: usize) -> Result<()>

Remove size-byte mapping starting at offset.
source§

impl Send for MemoryMappingArena

source§

impl Sync for MemoryMappingArena

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>,

§

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>,

§

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.