Trait base::MappedRegion

source ·
pub unsafe trait MappedRegion: Send + Sync {
    // Required methods
    fn as_ptr(&self) -> *mut u8;
    fn size(&self) -> usize;

    // Provided methods
    fn add_fd_mapping(
        &mut self,
        _offset: usize,
        _size: usize,
        _fd: &dyn AsRawDescriptor,
        _fd_offset: u64,
        _prot: Protection
    ) -> Result<()> { ... }
    fn remove_mapping(&mut self, _offset: usize, _size: usize) -> Result<()> { ... }
}
Expand description

A range of memory that can be msynced, for abstracting over different types of memory mappings.

Safety

Safe when implementers guarantee ptr..ptr+size is an mmaped region owned by this object that can’t be unmapped during the MappedRegion’s lifetime.

Required Methods§

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.

Provided Methods§

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.

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 remove_mapping(&mut self, _offset: usize, _size: usize) -> Result<()>

Remove size-byte mapping starting at offset.

Implementations§

source§

impl dyn MappedRegion

source

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

Calls msync with MS_SYNC on a mapping of size bytes starting at offset from the start of the region. offset..offset+size must be contained within the MappedRegion.

Implementors§