Struct aarch64_paging::idmap::IdMap
source · [−]pub struct IdMap { /* private fields */ }
Expand description
Manages a level 1 page table using identity mapping, where every virtual address is either unmapped or mapped to the identical IPA.
This assumes that identity mapping is used both for the page table being managed, and for code that is managing it.
Mappings should be added with map_range
before calling
activate
to start using the new page table. To make changes which may
require break-before-make semantics you must first call deactivate
to
switch back to a previous static page table, and then activate
again after making the desired
changes.
Example
use aarch64_paging::{
idmap::IdMap,
paging::{Attributes, MemoryRegion},
};
const ASID: usize = 1;
const ROOT_LEVEL: usize = 1;
// Create a new page table with identity mapping.
let mut idmap = IdMap::new(ASID, ROOT_LEVEL);
// Map a 2 MiB region of memory as read-write.
idmap.map_range(
&MemoryRegion::new(0x80200000, 0x80400000),
Attributes::NORMAL | Attributes::NON_GLOBAL | Attributes::EXECUTE_NEVER,
).unwrap();
// Set `TTBR0_EL1` to activate the page table.
idmap.activate();
// Write something to the memory...
// Restore `TTBR0_EL1` to its earlier value while we modify the page table.
idmap.deactivate();
// Now change the mapping to read-only and executable.
idmap.map_range(
&MemoryRegion::new(0x80200000, 0x80400000),
Attributes::NORMAL | Attributes::NON_GLOBAL | Attributes::READ_ONLY,
).unwrap();
idmap.activate();
Implementations
sourceimpl IdMap
impl IdMap
sourcepub fn new(asid: usize, rootlevel: usize) -> Self
pub fn new(asid: usize, rootlevel: usize) -> Self
Creates a new identity-mapping page table with the given ASID and root level.
sourcepub fn activate(&mut self)
pub fn activate(&mut self)
Activates the page table by setting TTBR0_EL1
to point to it, and saves the previous value
of TTBR0_EL1
so that it may later be restored by deactivate
.
Panics if a previous value of TTBR0_EL1
is already saved and not yet used by a call to
deactivate
.
sourcepub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Deactivates the page table, by setting TTBR0_EL1
back to the value it had before
activate
was called, and invalidating the TLB for this page table’s
configured ASID.
Panics if there is no saved TTRB0_EL1
value because activate
has not previously been
called.
sourcepub fn map_range(
&mut self,
range: &MemoryRegion,
flags: Attributes
) -> Result<(), MapError>
pub fn map_range(
&mut self,
range: &MemoryRegion,
flags: Attributes
) -> Result<(), MapError>
Maps the given range of virtual addresses to the identical 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.
Errors
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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for IdMap
impl !Send for IdMap
impl !Sync for IdMap
impl Unpin for IdMap
impl UnwindSafe for IdMap
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more