Struct axmem::MapArea

source ·
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

source

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).

source

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.

source

pub fn dealloc(&mut self, page_table: &mut PageTable)

Deallocate all phys pages and unmap the area in page table.

source

pub fn handle_page_fault( &mut self, addr: VirtAddr, flags: MappingFlags, page_table: &mut PageTable ) -> bool

如果处理失败,返回false,此时直接退出当前程序

source

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.

source

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.

source

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.

source

pub fn split(&mut self, addr: VirtAddr) -> Self

Split this area into 2.

source

pub fn split3(&mut self, start: VirtAddr, end: VirtAddr) -> (Self, Self)

Split this area into 3.

source

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

source

pub fn size(&self) -> usize

return the size of the area, which thinks the page size is default 4K.

source

pub fn end_va(&self) -> VirtAddr

return the end virtual address of the area.

source

pub fn allocated(&self) -> bool

return whether all the pages have been allocated.

source

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.

source

pub fn fill(&mut self, byte: u8)

Fill self with byte.

source

pub fn overlap_with(&self, start: VirtAddr, end: VirtAddr) -> bool

If [start, end) overlaps with self.

source

pub fn contained_in(&self, start: VirtAddr, end: VirtAddr) -> bool

If [start, end] contains self.

source

pub fn contains(&self, start: VirtAddr, end: VirtAddr) -> bool

If self contains [start, end].

source

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.

source

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.

source

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.

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> AsAny for T
where T: Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

把当前对象转化为 Any 类型,供后续 downcast 使用
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

供 downcast_mut 使用
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>,

§

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>,

§

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.