pub struct MapArea {
pub pages: Vec<Option<PhysPage>>,
pub vaddr: VirtAddr,
pub flags: MappingFlags,
pub backend: Option<MemBackend>,
}
Expand description
A continuous virtual area in user memory.
NOTE: Cloning a MapArea
needs allocating new phys pages and modifying a page table. So
Clone
trait won’t implemented.
Fields§
§pages: Vec<Option<PhysPage>>
phys pages of this area
vaddr: VirtAddr
start virtual address
flags: MappingFlags
mapping flags of this area
backend: Option<MemBackend>
whether the area is backed by a file
Implementations§
source§impl MapArea
impl MapArea
sourcepub fn new_lazy(
start: VirtAddr,
num_pages: usize,
flags: MappingFlags,
backend: Option<MemBackend>,
page_table: &mut PageTable
) -> Self
pub fn new_lazy( start: VirtAddr, num_pages: usize, flags: MappingFlags, backend: Option<MemBackend>, page_table: &mut PageTable ) -> Self
Create a lazy-load area and map it in page table (page fault PTE).
sourcepub fn new_alloc(
start: VirtAddr,
num_pages: usize,
flags: MappingFlags,
data: Option<&[u8]>,
backend: Option<MemBackend>,
page_table: &mut PageTable
) -> AxResult<Self>
pub fn new_alloc( start: VirtAddr, num_pages: usize, flags: MappingFlags, data: Option<&[u8]>, backend: Option<MemBackend>, page_table: &mut PageTable ) -> AxResult<Self>
Allocated an area and map it in page table.
sourcepub fn dealloc(&mut self, page_table: &mut PageTable)
pub fn dealloc(&mut self, page_table: &mut PageTable)
Deallocate all phys pages and unmap the area in page table.
sourcepub fn handle_page_fault(
&mut self,
addr: VirtAddr,
flags: MappingFlags,
page_table: &mut PageTable
) -> bool
pub fn handle_page_fault( &mut self, addr: VirtAddr, flags: MappingFlags, page_table: &mut PageTable ) -> bool
如果处理失败,返回false,此时直接退出当前程序
sourcepub fn sync_page_with_backend(&mut self, page_index: usize)
pub fn sync_page_with_backend(&mut self, page_index: usize)
Sync pages in index back to self.backend
(if there is one).
Panics
Panics if index is out of bounds.
sourcepub fn shrink_left(&mut self, new_start: VirtAddr, page_table: &mut PageTable)
pub fn shrink_left(&mut self, new_start: VirtAddr, page_table: &mut PageTable)
Deallocate some pages from the start of the area. This function will unmap them in a page table. You need to flush TLB after this function.
sourcepub fn shrink_right(&mut self, new_end: VirtAddr, page_table: &mut PageTable)
pub fn shrink_right(&mut self, new_end: VirtAddr, page_table: &mut PageTable)
Deallocate some pages from the end of the area. This function will unmap them in a page table. You need to flush TLB after this function.
sourcepub fn split3(&mut self, start: VirtAddr, end: VirtAddr) -> (Self, Self)
pub fn split3(&mut self, start: VirtAddr, end: VirtAddr) -> (Self, Self)
Split this area into 3.
sourcepub fn remove_mid(
&mut self,
left_end: VirtAddr,
right_start: VirtAddr,
page_table: &mut PageTable
) -> Self
pub fn remove_mid( &mut self, left_end: VirtAddr, right_start: VirtAddr, page_table: &mut PageTable ) -> Self
Create a second area in the right part of the area, [self.vaddr, left_end) and [right_start, self.end_va()). This function will unmap deleted pages in a page table. You need to flush TLB after calling this.
source§impl MapArea
impl MapArea
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
return the size of the area, which thinks the page size is default 4K.
sourcepub unsafe fn as_slice(&self) -> &[u8] ⓘ
pub unsafe fn as_slice(&self) -> &[u8] ⓘ
Safety
This function is unsafe because it dereferences a raw pointer. It will return a slice of the area’s memory, whose len is the same as the area’s size.
sourcepub fn overlap_with(&self, start: VirtAddr, end: VirtAddr) -> bool
pub fn overlap_with(&self, start: VirtAddr, end: VirtAddr) -> bool
If [start, end) overlaps with self.
sourcepub fn contained_in(&self, start: VirtAddr, end: VirtAddr) -> bool
pub fn contained_in(&self, start: VirtAddr, end: VirtAddr) -> bool
If [start, end] contains self.
sourcepub fn strict_contain(&self, start: VirtAddr, end: VirtAddr) -> bool
pub fn strict_contain(&self, start: VirtAddr, end: VirtAddr) -> bool
If self strictly contains [start, end], which stands for the start and end are not equal to self’s.
sourcepub fn update_flags(&mut self, flags: MappingFlags, page_table: &mut PageTable)
pub fn update_flags(&mut self, flags: MappingFlags, page_table: &mut PageTable)
Update area’s mapping flags and write it to page table. You need to flush TLB after calling this function.
sourcepub fn clone_alloc(&self, page_table: &mut PageTable) -> AxResult<Self>
pub fn clone_alloc(&self, page_table: &mut PageTable) -> AxResult<Self>
Allocating new phys pages and clone it self. This function will modify the page table as well.