Skip to main content

MemorySet

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

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn validate_area_metadata_replacement( &self, area: &MemoryArea<B>, ) -> MappingResult

Validates that area can replace one contained metadata range.

Source

pub fn replace_area_metadata(&mut self, area: MemoryArea<B>) -> MappingResult

Replaces area metadata without touching page-table entries.

Source

pub fn clear( &mut self, context: &mut B::MutationContext, 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>, 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.

Source

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.

Trait Implementations§

Source§

impl<B: Clone + MappingBackend> Clone for MemorySet<B>
where B::Addr: Clone,

Source§

fn clone(&self) -> MemorySet<B>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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
Source§

impl<B: MappingBackend> Default for MemorySet<B>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.