pub struct MemorySet<B: MappingBackend> { /* private fields */ }
Expand description
A container that maintains memory mappings (MemoryArea
).
Implementations§
Source§impl<B: MappingBackend> MemorySet<B>
impl<B: MappingBackend> MemorySet<B>
Sourcepub fn iter(&self) -> impl Iterator<Item = &MemoryArea<B>>
pub fn iter(&self) -> impl Iterator<Item = &MemoryArea<B>>
Returns the iterator over all memory areas.
Sourcepub fn overlaps(&self, range: AddrRange<B::Addr>) -> bool
pub fn overlaps(&self, range: AddrRange<B::Addr>) -> bool
Returns whether the given address range overlaps with any existing area.
Sourcepub fn find(&self, addr: B::Addr) -> Option<&MemoryArea<B>>
pub fn find(&self, addr: B::Addr) -> Option<&MemoryArea<B>>
Finds the memory area that contains the given address.
Sourcepub fn find_free_area(
&self,
hint: B::Addr,
size: usize,
limit: AddrRange<B::Addr>,
) -> Option<B::Addr>
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.
Sourcepub fn map(
&mut self,
area: MemoryArea<B>,
page_table: &mut B::PageTable,
unmap_overlap: bool,
) -> MappingResult
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.
Sourcepub fn unmap(
&mut self,
start: B::Addr,
size: usize,
page_table: &mut B::PageTable,
) -> MappingResult
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.
Sourcepub fn clear(&mut self, page_table: &mut B::PageTable) -> MappingResult
pub fn clear(&mut self, page_table: &mut B::PageTable) -> MappingResult
Remove all memory areas and the underlying mappings.
Sourcepub fn protect(
&mut self,
start: B::Addr,
size: usize,
update_flags: impl Fn(B::Flags) -> Option<B::Flags>,
page_table: &mut B::PageTable,
) -> MappingResult
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
.