Struct MemorySet

Source
pub struct MemorySet<B: MappingBackend> { /* private fields */ }
Expand description

A container that maintains memory mappings (MemoryArea).

Implementations§

Source§

impl<B: MappingBackend> MemorySet<B>

Source

pub const fn new() -> Self

Creates a new memory set.

Source

pub fn len(&self) -> usize

Returns the number of memory areas in the memory set.

Source

pub fn is_empty(&self) -> bool

Returns true if the memory set contains no memory areas.

Source

pub fn iter(&self) -> impl Iterator<Item = &MemoryArea<B>>

Returns the iterator over all memory areas.

Source

pub fn overlaps(&self, range: AddrRange<B::Addr>) -> bool

Returns whether the given address range overlaps with any existing area.

Source

pub fn find(&self, addr: B::Addr) -> Option<&MemoryArea<B>>

Finds the memory area that contains the given address.

Source

pub fn find_free_area( &self, hint: B::Addr, size: usize, limit: AddrRange<B::Addr>, ) -> Option<B::Addr>

Finds a free area that can accommodate the given size.

The search starts from the given hint address, and the area should be within the given limit range.

Returns the start address of the free area. Returns None if no such area is found.

Source

pub fn map( &mut self, area: MemoryArea<B>, page_table: &mut B::PageTable, unmap_overlap: bool, ) -> MappingResult

Add a new memory mapping.

The mapping is represented by a MemoryArea.

If the new area overlaps with any existing area, the behavior is determined by the unmap_overlap parameter. If it is true, the overlapped regions will be unmapped first. Otherwise, it returns an error.

Source

pub fn unmap( &mut self, start: B::Addr, size: usize, page_table: &mut B::PageTable, ) -> MappingResult

Remove memory mappings within the given address range.

All memory areas that are fully contained in the range will be removed directly. If the area intersects with the boundary, it will be shrinked. If the unmapped range is in the middle of an existing area, it will be split into two areas.

Source

pub fn clear(&mut self, page_table: &mut B::PageTable) -> MappingResult

Remove all memory areas and the underlying mappings.

Source

pub fn protect( &mut self, start: B::Addr, size: usize, update_flags: impl Fn(B::Flags) -> Option<B::Flags>, page_table: &mut B::PageTable, ) -> MappingResult

Change the flags of memory mappings within the given address range.

update_flags is a function that receives old flags and processes new flags (e.g., some flags can not be changed through this interface). It returns None if there is no bit to change.

Memory areas will be skipped according to update_flags. Memory areas that are fully contained in the range or contains the range or intersects with the boundary will be handled similarly to munmap.

Trait Implementations§

Source§

impl<B: MappingBackend> Debug for MemorySet<B>
where B::Addr: Debug, B::Flags: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for MemorySet<B>

§

impl<B> RefUnwindSafe for MemorySet<B>

§

impl<B> Send for MemorySet<B>
where <B as MappingBackend>::Addr: Send, <B as MappingBackend>::Flags: Send, B: Send,

§

impl<B> Sync for MemorySet<B>
where <B as MappingBackend>::Addr: Sync, <B as MappingBackend>::Flags: Sync, B: Sync,

§

impl<B> Unpin for MemorySet<B>

§

impl<B> UnwindSafe for MemorySet<B>

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.