pub struct Frame<T: TableMeta, A: FrameAllocator> {
pub paddr: PhysAddr,
pub allocator: A,
/* private fields */
}Expand description
页表帧,代表一个物理页面上的页表
Fields§
§paddr: PhysAddr§allocator: AImplementations§
Source§impl<T, A> Frame<T, A>where
T: TableMeta,
A: FrameAllocator,
impl<T, A> Frame<T, A>where
T: TableMeta,
A: FrameAllocator,
Sourcepub fn new(allocator: A) -> PagingResult<Self>
pub fn new(allocator: A) -> PagingResult<Self>
创建新的页表帧(分配并清零)
Sourcepub fn from_paddr(paddr: PhysAddr, allocator: A) -> Self
pub fn from_paddr(paddr: PhysAddr, allocator: A) -> Self
从物理地址创建Frame(不分配)
Sourcepub fn as_slice_mut(&mut self) -> &mut [T::P]
pub fn as_slice_mut(&mut self) -> &mut [T::P]
获取页表项的可变切片
Sourcepub fn level_size(level: usize) -> usize
pub fn level_size(level: usize) -> usize
计算指定级别对应的映射大小
- Level 1 (叶子): PAGE_SIZE
- Level 2: PAGE_SIZE << LEVEL_BITS[最后一级]
- Level 3: PAGE_SIZE << (LEVEL_BITS[最后一级] + LEVEL_BITS[倒数第二级])
- Level N: PAGE_SIZE << (sum of LEVEL_BITS from last to N-1)
Sourcepub fn virt_to_index(vaddr: VirtAddr, level: usize) -> usize
pub fn virt_to_index(vaddr: VirtAddr, level: usize) -> usize
计算指定级别的页表索引 从虚拟地址中提取对应级别的索引位
Sourcepub fn reconstruct_vaddr(
index: usize,
level: usize,
base_vaddr: VirtAddr,
) -> VirtAddr
pub fn reconstruct_vaddr( index: usize, level: usize, base_vaddr: VirtAddr, ) -> VirtAddr
重建完整的虚拟地址 从基地址和索引计算完整的虚拟地址
Sourcepub fn deallocate_recursive(&mut self, level: usize)
pub fn deallocate_recursive(&mut self, level: usize)
Sourcepub fn deallocate_children(&mut self, level: usize)
pub fn deallocate_children(&mut self, level: usize)
只释放子页表帧,保留当前帧
遍历当前帧中的所有页表项:
- 如果是大页或叶子级别的数据页:跳过(不释放物理页,也不清除映射)
- 如果是非叶子级别的页表指针:递归释放子页表帧,并清除PTE
§Parameters
level: 当前帧所在的页表级别(1=叶子,数字越大级别越高)
Sourcepub fn translate_recursive(
&self,
vaddr: VirtAddr,
level: usize,
) -> PagingResult<T::P>
pub fn translate_recursive( &self, vaddr: VirtAddr, level: usize, ) -> PagingResult<T::P>
Sourcepub fn translate_recursive_with_level(
&self,
vaddr: VirtAddr,
level: usize,
) -> PagingResult<(T::P, usize)>
pub fn translate_recursive_with_level( &self, vaddr: VirtAddr, level: usize, ) -> PagingResult<(T::P, usize)>
Source§impl<T, A> Frame<T, A>where
T: TableMeta,
A: FrameAllocator,
impl<T, A> Frame<T, A>where
T: TableMeta,
A: FrameAllocator,
Sourcepub fn map_range_recursive(
&mut self,
config: MapRecursiveConfig,
) -> PagingResult<()>
pub fn map_range_recursive( &mut self, config: MapRecursiveConfig, ) -> PagingResult<()>
递归映射的核心实现
Sourcepub fn unmap_range_recursive(
&mut self,
config: UnmapRecursiveConfig,
) -> PagingResult<bool>
pub fn unmap_range_recursive( &mut self, config: UnmapRecursiveConfig, ) -> PagingResult<bool>
递归取消映射的核心实现
返回值:bool 表示此帧是否为空(所有页表项都无效),可以回收
Trait Implementations§
impl<T: Copy + TableMeta, A: Copy + FrameAllocator> Copy for Frame<T, A>
Auto Trait Implementations§
impl<T, A> Freeze for Frame<T, A>where
A: Freeze,
impl<T, A> RefUnwindSafe for Frame<T, A>where
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> Send for Frame<T, A>
impl<T, A> Sync for Frame<T, A>
impl<T, A> Unpin for Frame<T, A>
impl<T, A> UnwindSafe for Frame<T, A>where
A: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more