LinearMap

Struct LinearMap 

Source
pub struct LinearMap { /* private fields */ }
Expand description

Manages a level 1 page table using linear mapping, where every virtual address is either unmapped or mapped to an IPA with a fixed offset.

This assumes that the same linear mapping is used both for the page table being managed, and for code that is managing it.

Implementations§

Source§

impl LinearMap

Source

pub fn new( asid: usize, rootlevel: usize, offset: isize, translation_regime: TranslationRegime, va_range: VaRange, ) -> Self

Creates a new identity-mapping page table with the given ASID, root level and offset, for use in the given TTBR.

This will map any virtual address va which is added to the table to the physical address va + offset.

The offset must be a multiple of PAGE_SIZE; if not this will panic.

Source

pub fn size(&self) -> usize

Returns the size in bytes of the virtual address space which can be mapped in this page table.

This is a function of the chosen root level.

Source

pub unsafe fn activate(&mut self) -> usize

Activates the page table by programming the physical address of the root page table into TTBRn_ELx, along with the provided ASID. The previous value of TTBRn_ELx is returned so that it may later be restored by passing it to deactivate.

In test builds or builds that do not target aarch64, the TTBR0_EL1 access is omitted.

§Safety

The caller must ensure that the page table doesn’t unmap any memory which the program is using, or introduce aliases which break Rust’s aliasing rules. The page table must not be dropped as long as its mappings are required, as it will automatically be deactivated when it is dropped.

Source

pub unsafe fn deactivate(&mut self, previous_ttbr: usize)

Deactivates the page table, by setting TTBRn_ELx to the provided value, and invalidating the TLB for this page table’s configured ASID. The provided TTBR value should be the value returned by the preceding activate call.

In test builds or builds that do not target aarch64, the TTBR0_EL1 access is omitted.

§Safety

The caller must ensure that the previous page table which this is switching back to doesn’t unmap any memory which the program is using.

Source

pub fn map_range( &mut self, range: &MemoryRegion, flags: Attributes, ) -> Result<(), MapError>

Maps the given range of virtual addresses to the corresponding physical addresses with the given flags.

This should generally only be called while the page table is not active. In particular, any change that may require break-before-make per the architecture must be made while the page table is inactive. Mapping a previously unmapped memory range may be done while the page table is active. This function writes block and page entries, but only maps them if flags contains Attributes::VALID, otherwise the entries remain invalid.

§Errors

Returns MapError::InvalidVirtualAddress if adding the configured offset to any virtual address within the range would result in overflow.

Returns MapError::RegionBackwards if the range is backwards.

Returns MapError::AddressRange if the largest address in the range is greater than the largest virtual address covered by the page table given its root level.

Returns MapError::InvalidFlags if the flags argument has unsupported attributes set.

Returns [`MapError::BreakBeforeMakeViolation’] if the range intersects with live mappings, and modifying those would violate architectural break-before-make (BBM) requirements.

Source

pub fn map_range_with_constraints( &mut self, range: &MemoryRegion, flags: Attributes, constraints: Constraints, ) -> Result<(), MapError>

Maps the given range of virtual addresses to the corresponding physical addresses with the given flags, taking the given constraints into account.

This should generally only be called while the page table is not active. In particular, any change that may require break-before-make per the architecture must be made while the page table is inactive. Mapping a previously unmapped memory range may be done while the page table is active. This function writes block and page entries, but only maps them if flags contains Attributes::VALID, otherwise the entries remain invalid.

§Errors

Returns MapError::InvalidVirtualAddress if adding the configured offset to any virtual address within the range would result in overflow.

Returns MapError::RegionBackwards if the range is backwards.

Returns MapError::AddressRange if the largest address in the range is greater than the largest virtual address covered by the page table given its root level.

Returns MapError::InvalidFlags if the flags argument has unsupported attributes set.

Returns [`MapError::BreakBeforeMakeViolation’] if the range intersects with live mappings, and modifying those would violate architectural break-before-make (BBM) requirements.

Source

pub fn modify_range<F>( &mut self, range: &MemoryRegion, f: &F, ) -> Result<(), MapError>
where F: Fn(&MemoryRegion, &mut Descriptor, usize) -> Result<(), ()> + ?Sized,

Applies the provided updater function to the page table descriptors covering a given memory range.

This may involve splitting block entries if the provided range is not currently mapped down to its precise boundaries. For visiting all the descriptors covering a memory range without potential splitting (and no descriptor updates), use walk_range instead.

The updater function receives the following arguments:

  • The virtual address range mapped by each page table descriptor. A new descriptor will have been allocated before the invocation of the updater function if a page table split was needed.
  • A mutable reference to the page table descriptor that permits modifications.
  • The level of a translation table the descriptor belongs to.

The updater function should return:

  • Ok to continue updating the remaining entries.
  • Err to signal an error and stop updating the remaining entries.

This should generally only be called while the page table is not active. In particular, any change that may require break-before-make per the architecture must be made while the page table is inactive. Mapping a previously unmapped memory range may be done while the page table is active.

§Errors

Returns MapError::PteUpdateFault if the updater function returns an error.

Returns MapError::RegionBackwards if the range is backwards.

Returns MapError::AddressRange if the largest address in the range is greater than the largest virtual address covered by the page table given its root level.

Returns [`MapError::BreakBeforeMakeViolation’] if the range intersects with live mappings, and modifying those would violate architectural break-before-make (BBM) requirements.

Source

pub fn walk_range<F>( &self, range: &MemoryRegion, f: &mut F, ) -> Result<(), MapError>

Applies the provided callback function to the page table descriptors covering a given memory range.

The callback function receives the following arguments:

  • The range covered by the current step in the walk. This is always a subrange of range even when the descriptor covers a region that exceeds it.
  • The page table descriptor itself.
  • The level of a translation table the descriptor belongs to.

The callback function should return:

  • Ok to continue visiting the remaining entries.
  • Err to signal an error and stop visiting the remaining entries.
§Errors

Returns MapError::PteUpdateFault if the callback function returns an error.

Returns MapError::RegionBackwards if the range is backwards.

Returns MapError::AddressRange if the largest address in the range is greater than the largest virtual address covered by the page table given its root level.

Source

pub fn root_address(&self) -> PhysicalAddress

Returns the physical address of the root table.

This may be used to activate the page table by setting the appropriate TTBRn_ELx if you wish to do so yourself rather than by calling activate. Make sure to call mark_active after doing so.

Source

pub fn mark_active(&mut self)

Marks the page table as active.

This should be called if the page table is manually activated by calling root_address and setting some TTBR with it. This will cause map_range and modify_range to perform extra checks to avoid violating break-before-make requirements.

It is called automatically by activate.

Source

pub fn mark_inactive(&mut self)

Marks the page table as inactive.

This may be called after manually disabling the use of the page table, such as by setting the relevant TTBR to a different address.

It is called automatically by deactivate.

Trait Implementations§

Source§

impl Debug for LinearMap

Source§

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

Formats the value using the given formatter. 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> 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.