Skip to main content

ax_memory_set/
backend.rs

1use ax_memory_addr::MemoryAddr;
2
3/// Underlying operations to do when manipulating mappings within the specific
4/// [`MemoryArea`](crate::MemoryArea).
5///
6/// The backend can be different for different memory areas. e.g., for linear
7/// mappings, the target physical address is known when it is added to the page
8/// table. For lazy mappings, an empty mapping needs to be added to the page
9/// table to trigger a page fault.
10pub trait MappingBackend: Clone {
11    /// The address type used in the memory area.
12    type Addr: MemoryAddr;
13    /// The flags type used in the memory area.
14    type Flags: Copy;
15    /// The page table type used in the memory area.
16    type PageTable;
17
18    /// What to do when mapping a region within the area with the given flags.
19    fn map(
20        &self,
21        start: Self::Addr,
22        size: usize,
23        flags: Self::Flags,
24        page_table: &mut Self::PageTable,
25    ) -> bool;
26
27    /// What to do when unmaping a memory region within the area.
28    fn unmap(&self, start: Self::Addr, size: usize, page_table: &mut Self::PageTable) -> bool;
29
30    /// What to do when changing access flags.
31    fn protect(
32        &self,
33        start: Self::Addr,
34        size: usize,
35        new_flags: Self::Flags,
36        page_table: &mut Self::PageTable,
37    ) -> bool;
38
39    /// Splits the backend into two backends at the given alignment difference.
40    fn split(&mut self, align_diff: usize) -> Option<Self>;
41
42    /// Shrinks the backend from the left by the given size.
43    ///
44    /// The backend start address is increased by `shrink_size`.
45    fn shrink_left(&mut self, _shrink_size: usize) {}
46
47    /// Shrinks the backend from the right by the given size.
48    ///
49    /// The backend end address is decreased by `shrink_size`.
50    fn shrink_right(&mut self, _shrink_size: usize) {}
51}