memory_set/
backend.rs

1use 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}