Skip to main content

Frame

Struct Frame 

Source
pub struct Frame<T: TableMeta, A: FrameAllocator> {
    pub paddr: PhysAddr,
    pub allocator: A,
    /* private fields */
}
Expand description

页表帧,代表一个物理页面上的页表

Fields§

§paddr: PhysAddr§allocator: A

Implementations§

Source§

impl<T, A> Frame<T, A>

Source

pub fn new(allocator: A) -> PagingResult<Self>

创建新的页表帧(分配并清零)

Source

pub fn from_paddr(paddr: PhysAddr, allocator: A) -> Self

从物理地址创建Frame(不分配)

Source

pub fn from_pte(pte: &T::P, level: usize, allocator: A) -> Self

从PTE创建子Frame(用于遍历子页表)

Source

pub fn as_slice_mut(&mut self) -> &mut [T::P]

获取页表项的可变切片

Source

pub fn as_slice(&self) -> &[T::P]

获取页表项的不可变切片

Source

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

pub fn virt_to_index(vaddr: VirtAddr, level: usize) -> usize

计算指定级别的页表索引 从虚拟地址中提取对应级别的索引位

Source

pub fn reconstruct_vaddr( index: usize, level: usize, base_vaddr: VirtAddr, ) -> VirtAddr

重建完整的虚拟地址 从基地址和索引计算完整的虚拟地址

Source

pub fn deallocate_recursive(&mut self, level: usize)

递归释放当前帧及所有子帧

此方法会:

  1. 递归释放所有有效的子页表帧
  2. 清除所有页表项(设为invalid)
  3. 释放当前帧

注意:只释放页表帧,不释放映射的物理页(数据页/大页)

§Parameters
  • level: 当前帧所在的页表级别(1=叶子,数字越大级别越高)
§Safety

调用者必须确保:

  • 没有其他代码在访问这些页表
  • 没有CPU正在使用这些页表进行地址翻译
Source

pub fn deallocate_children(&mut self, level: usize)

只释放子页表帧,保留当前帧

遍历当前帧中的所有页表项:

  • 如果是大页或叶子级别的数据页:跳过(不释放物理页,也不清除映射)
  • 如果是非叶子级别的页表指针:递归释放子页表帧,并清除PTE
§Parameters
  • level: 当前帧所在的页表级别(1=叶子,数字越大级别越高)
Source

pub fn translate_recursive( &self, vaddr: VirtAddr, level: usize, ) -> PagingResult<T::P>

递归查找虚拟地址对应的页表项

§参数
  • vaddr: 要查找的虚拟地址
  • level: 当前页表级别
§返回值
  • Ok(T::P): 找到的页表项
  • Err(PagingError): 查找失败
Source

pub fn translate_recursive_with_level( &self, vaddr: VirtAddr, level: usize, ) -> PagingResult<(T::P, usize)>

递归查找虚拟地址对应的页表项,同时返回该PTE所在的级别

§参数
  • vaddr: 要查找的虚拟地址
  • level: 当前页表级别
§返回值
  • Ok((T::P, usize)): 找到的页表项及其所在的级别
  • Err(PagingError): 查找失败
Source

pub fn dealloc_entry_recursive(&mut self, index: usize, level: usize) -> bool

递归释放指定的单个页表项

如果该PTE指向有效的子页表,则递归释放该子页表及其所有子帧 在释放前将PTE设为invalid

注意:只释放页表帧,不释放映射的物理页

§Parameters
  • index: 要释放的PTE索引
  • level: 当前帧所在的页表级别
Source§

impl<T, A> Frame<T, A>

Source

pub fn map_range_recursive( &mut self, config: MapRecursiveConfig, ) -> PagingResult<()>

递归映射的核心实现

Source

pub fn unmap_range_recursive( &mut self, config: UnmapRecursiveConfig, ) -> PagingResult<bool>

递归取消映射的核心实现

返回值:bool 表示此帧是否为空(所有页表项都无效),可以回收

Trait Implementations§

Source§

impl<T: Clone + TableMeta, A: Clone + FrameAllocator> Clone for Frame<T, A>

Source§

fn clone(&self) -> Frame<T, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: TableMeta, A: FrameAllocator> Debug for Frame<T, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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>

§

impl<T, A> Send for Frame<T, A>

§

impl<T, A> Sync for Frame<T, A>

§

impl<T, A> Unpin for Frame<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> UnwindSafe for Frame<T, A>
where A: UnwindSafe, T: UnwindSafe,

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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>,

Source§

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

Source§

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.