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 restore_metadata_preimage(&mut self, preimage: Self)
pub fn restore_metadata_preimage(&mut self, preimage: Self)
Restores a metadata preimage after the caller has reverted every materialized PTE and backend ownership change.
This method intentionally does not touch the page table: callers must first prove that the current mapping was detached and that every old leaf/frame reference was restored. Keeping that ordering explicit prevents a metadata rollback from masquerading as a complete rollback.
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>,
align: usize,
) -> Option<B::Addr>
pub fn find_free_area( &self, hint: B::Addr, size: usize, limit: AddrRange<B::Addr>, align: usize, ) -> 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.
§Notes
The align parameter specifies the alignment of the start address and
the size of the area. The start address of the resulting area will
be aligned to this value. Also, the size of the area must be a multiple
of this value.
§Returns
Returns the start address of the free area. Returns None if no such
area is found.
Sourcepub fn extend_area(
&mut self,
addr: B::Addr,
additional_size: usize,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
) -> MappingResult
pub fn extend_area( &mut self, addr: B::Addr, additional_size: usize, context: &mut B::MutationContext, page_table: &mut B::PageTable, ) -> MappingResult
Grows the area containing addr by additional_size at its end.
Sourcepub fn rollback_extend_area(
&mut self,
addr: B::Addr,
additional_size: usize,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
) -> MappingResult
pub fn rollback_extend_area( &mut self, addr: B::Addr, additional_size: usize, context: &mut B::MutationContext, page_table: &mut B::PageTable, ) -> MappingResult
Reverts a successful Self::extend_area before its surrounding
mutation is published. The newly materialized suffix is unmapped
first, then the metadata is shortened. A backend is allowed to report
that only a prefix was unmapped; in that case the caller receives
NeedsRepair and must not pretend that the preimage was restored.
Sourcepub fn map(
&mut self,
area: MemoryArea<B>,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
unmap_overlap: bool,
) -> MappingResult
pub fn map( &mut self, area: MemoryArea<B>, context: &mut B::MutationContext, 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 insert_prepared_area(&mut self, area: MemoryArea<B>) -> MappingResult
pub fn insert_prepared_area(&mut self, area: MemoryArea<B>) -> MappingResult
Publishes metadata without invoking the backend’s mapping operation.
The caller either owns an unpublished address space with prepared PTEs, or retains a reservation token that retires partially installed leaves if the subsequent page-table apply fails.
This is intentionally separate from Self::map: replaying map
after a fork clone has installed child PTEs would reject those exact
leaves as an overlap, while silently skipping the normal map preflight
would weaken every ordinary caller. The caller must retain rollback
ownership for the prepared backend state until this insertion and its
surrounding address-space publication complete.
Sourcepub fn replace_exact_backend(
&mut self,
start: B::Addr,
size: usize,
backend: B,
) -> MappingResult<B>
pub fn replace_exact_backend( &mut self, start: B::Addr, size: usize, backend: B, ) -> MappingResult<B>
Replaces the backend of one exact area without allocating or touching its materialized page-table state.
This is used by typed owners that need to publish a lifecycle state
transition (for example Present -> Quarantined) before a TLB
acknowledgement. Requiring an exact range prevents a backend that does
not support split ownership from being installed on a fragment.
Sourcepub fn unmap_exact(
&mut self,
start: B::Addr,
size: usize,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
) -> MappingResult<MemoryArea<B>>
pub fn unmap_exact( &mut self, start: B::Addr, size: usize, context: &mut B::MutationContext, page_table: &mut B::PageTable, ) -> MappingResult<MemoryArea<B>>
Removes one exact area without constructing the general unmap operation vector.
The exact form is useful in allocation-free retire paths whose owner already proved that the mapping cannot be split. Metadata is removed only after the backend has detached every materialized entry. The returned owner lets the caller release resources outside its lock.
Sourcepub fn unmap(
&mut self,
start: B::Addr,
size: usize,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
) -> MappingResult
pub fn unmap( &mut self, start: B::Addr, size: usize, context: &mut B::MutationContext, 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 validate_unmap(
&self,
start: B::Addr,
size: usize,
page_table: &B::PageTable,
) -> MappingResult
pub fn validate_unmap( &self, start: B::Addr, size: usize, page_table: &B::PageTable, ) -> MappingResult
Preflights every backend touched by an unmap without changing state.
Sourcepub fn unmap_metadata(&mut self, start: B::Addr, size: usize) -> MappingResult
pub fn unmap_metadata(&mut self, start: B::Addr, size: usize) -> MappingResult
Remove memory area metadata without calling the backend’s unmap hook.
This is intended for callers that have already moved or detached the affected page-table entries and only need to update VMA bookkeeping.
Sourcepub fn validate_area_metadata_replacement(
&self,
area: &MemoryArea<B>,
) -> MappingResult
pub fn validate_area_metadata_replacement( &self, area: &MemoryArea<B>, ) -> MappingResult
Validates that area can replace one contained metadata range.
Sourcepub fn replace_area_metadata(&mut self, area: MemoryArea<B>) -> MappingResult
pub fn replace_area_metadata(&mut self, area: MemoryArea<B>) -> MappingResult
Replaces area metadata without touching page-table entries.
Sourcepub fn clear(
&mut self,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
) -> MappingResult
pub fn clear( &mut self, context: &mut B::MutationContext, 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>,
context: &mut B::MutationContext,
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>, context: &mut B::MutationContext, 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.
Sourcepub fn protect_with_reported_flags(
&mut self,
start: B::Addr,
size: usize,
update_flags: impl Fn(B::Flags, B::Flags) -> Option<(B::Flags, B::Flags)>,
context: &mut B::MutationContext,
page_table: &mut B::PageTable,
) -> MappingResult
pub fn protect_with_reported_flags( &mut self, start: B::Addr, size: usize, update_flags: impl Fn(B::Flags, B::Flags) -> Option<(B::Flags, B::Flags)>, context: &mut B::MutationContext, page_table: &mut B::PageTable, ) -> MappingResult
Change backend/page-table flags and reported flags within the given range.