pub struct MemorySet { /* private fields */ }
Expand description
PageTable + MemoryArea for a process (task)
Implementations§
source§impl MemorySet
impl MemorySet
sourcepub fn page_table_token(&self) -> usize
pub fn page_table_token(&self) -> usize
Get the root page table token.
sourcepub fn new_with_kernel_mapped() -> Self
pub fn new_with_kernel_mapped() -> Self
Create a new MemorySet with kernel mapped regions.
sourcepub fn page_table_root_ppn(&self) -> PhysAddr
pub fn page_table_root_ppn(&self) -> PhysAddr
The root page table physical address.
sourcepub fn new_region(
&mut self,
vaddr: VirtAddr,
size: usize,
flags: MappingFlags,
data: Option<&[u8]>,
backend: Option<MemBackend>
)
pub fn new_region( &mut self, vaddr: VirtAddr, size: usize, flags: MappingFlags, data: Option<&[u8]>, backend: Option<MemBackend> )
Allocate contiguous region. If no data, it will create a lazy load region.
sourcepub fn split_for_area(&mut self, start: VirtAddr, size: usize)
pub fn split_for_area(&mut self, start: VirtAddr, size: usize)
Make [start, end) unmapped and dealloced. You need to flush TLB after this.
NOTE: modified map area will have the same PhysAddr.
sourcepub fn find_free_area(&self, hint: VirtAddr, size: usize) -> Option<VirtAddr>
pub fn find_free_area(&self, hint: VirtAddr, size: usize) -> Option<VirtAddr>
Find a free area with given start virtual address and size. Return the start address of the area.
sourcepub fn mmap(
&mut self,
start: VirtAddr,
size: usize,
flags: MappingFlags,
fixed: bool,
backend: Option<MemBackend>
) -> isize
pub fn mmap( &mut self, start: VirtAddr, size: usize, flags: MappingFlags, fixed: bool, backend: Option<MemBackend> ) -> isize
mmap. You need to flush tlb after this.
sourcepub fn munmap(&mut self, start: VirtAddr, size: usize)
pub fn munmap(&mut self, start: VirtAddr, size: usize)
munmap. You need to flush TLB after this.
sourcepub fn mprotect(&mut self, start: VirtAddr, size: usize, flags: MappingFlags)
pub fn mprotect(&mut self, start: VirtAddr, size: usize, flags: MappingFlags)
Edit the page table to update flags in given virt address segment. You need to flush TLB after calling this function.
NOTE: It’s possible that this function will break map areas into two for different mapping flag settings.
sourcepub fn handle_page_fault(
&mut self,
addr: VirtAddr,
flags: MappingFlags
) -> AxResult<()>
pub fn handle_page_fault( &mut self, addr: VirtAddr, flags: MappingFlags ) -> AxResult<()>
It will map newly allocated page in the page table. You need to flush TLB after this.
sourcepub fn unmap_user_areas(&mut self)
pub fn unmap_user_areas(&mut self)
将用户分配的页面从页表中直接解映射,内核分配的页面依然保留
sourcepub fn query(
&self,
vaddr: VirtAddr
) -> AxResult<(PhysAddr, MappingFlags, PageSize)>
pub fn query( &self, vaddr: VirtAddr ) -> AxResult<(PhysAddr, MappingFlags, PageSize)>
Query the page table to get the physical address, flags and page size of the given virtual
sourcepub fn map_page_without_alloc(
&mut self,
vaddr: VirtAddr,
paddr: PhysAddr,
flags: MappingFlags
) -> AxResult<()>
pub fn map_page_without_alloc( &mut self, vaddr: VirtAddr, paddr: PhysAddr, flags: MappingFlags ) -> AxResult<()>
Map a 4K region without allocating physical memory.
Create a new SharedMem with given key. You need to add the returned SharedMem to global SHARED_MEMS or process’s private_mem.
Panics: SharedMem with the key already exist.
Panics: shmid is already taken.
Panics: shmid is already taken in the process.
Get a SharedMem by shmid.
Get a private SharedMem by shmid.
Attach a SharedMem to the memory set.
Detach a SharedMem from the memory set.
TODO: implement this
source§impl MemorySet
impl MemorySet
sourcepub fn manual_alloc_for_lazy(&mut self, addr: VirtAddr) -> AxResult<()>
pub fn manual_alloc_for_lazy(&mut self, addr: VirtAddr) -> AxResult<()>
判断某一个虚拟地址是否在内存集中。 若当前虚拟地址在内存集中,且对应的是lazy分配,暂未分配物理页的情况下, 则为其分配物理页面。
若不在内存集中,则返回None。
若在内存集中,且已经分配了物理页面,则不做处理。