pub struct PageTableRef<T, A>where
T: TableMeta,
A: FrameAllocator,{
pub root: Frame<T, A>,
}Fields§
§root: Frame<T, A>Implementations§
Source§impl<T, A> PageTableRef<T, A>where
T: TableMeta,
A: FrameAllocator,
impl<T, A> PageTableRef<T, A>where
T: TableMeta,
A: FrameAllocator,
Sourcepub unsafe fn new(allocator: A) -> Result<PageTableRef<T, A>, PagingError>
pub unsafe fn new(allocator: A) -> Result<PageTableRef<T, A>, PagingError>
pub fn from_paddr(paddr: PhysAddr, allocator: A) -> PageTableRef<T, A>
Sourcepub fn map_page(
&mut self,
vaddr: VirtAddr,
paddr: PhysAddr,
page_size: usize,
config: <<T as TableMeta>::P as PageTableEntry>::PteConfig,
) -> Result<(), PagingError>
pub fn map_page( &mut self, vaddr: VirtAddr, paddr: PhysAddr, page_size: usize, config: <<T as TableMeta>::P as PageTableEntry>::PteConfig, ) -> Result<(), PagingError>
Maps one page with the requested page size.
Sourcepub fn map_region(
&mut self,
start_vaddr: VirtAddr,
get_paddr: impl Fn(VirtAddr) -> PhysAddr,
size: usize,
config: <<T as TableMeta>::P as PageTableEntry>::PteConfig,
allow_huge: bool,
) -> Result<(), PagingError>
pub fn map_region( &mut self, start_vaddr: VirtAddr, get_paddr: impl Fn(VirtAddr) -> PhysAddr, size: usize, config: <<T as TableMeta>::P as PageTableEntry>::PteConfig, allow_huge: bool, ) -> Result<(), PagingError>
Maps a contiguous virtual region, choosing large pages when possible. Mappings installed by this call are rolled back if a later page fails. TLB invalidation is deferred and batched until the region has been updated.
Sourcepub fn unmap_page(
&mut self,
vaddr: VirtAddr,
) -> Result<(PhysAddr, <<T as TableMeta>::P as PageTableEntry>::PteConfig, usize), PagingError>
pub fn unmap_page( &mut self, vaddr: VirtAddr, ) -> Result<(PhysAddr, <<T as TableMeta>::P as PageTableEntry>::PteConfig, usize), PagingError>
Unmaps one page and returns its physical address, flags, and page size.
Sourcepub fn protect_page(
&mut self,
vaddr: VirtAddr,
config: <<T as TableMeta>::P as PageTableEntry>::PteConfig,
) -> Result<usize, PagingError>
pub fn protect_page( &mut self, vaddr: VirtAddr, config: <<T as TableMeta>::P as PageTableEntry>::PteConfig, ) -> Result<usize, PagingError>
Changes one existing mapping’s flags and returns its page size.
Sourcepub fn protect_region(
&mut self,
start_vaddr: VirtAddr,
size: usize,
config: <<T as TableMeta>::P as PageTableEntry>::PteConfig,
) -> Result<(), PagingError>
pub fn protect_region( &mut self, start_vaddr: VirtAddr, size: usize, config: <<T as TableMeta>::P as PageTableEntry>::PteConfig, ) -> Result<(), PagingError>
Changes flags for a region. Unmapped base pages are skipped.
Sourcepub fn remap_page(
&mut self,
vaddr: VirtAddr,
paddr: PhysAddr,
config: <<T as TableMeta>::P as PageTableEntry>::PteConfig,
) -> Result<usize, PagingError>
pub fn remap_page( &mut self, vaddr: VirtAddr, paddr: PhysAddr, config: <<T as TableMeta>::P as PageTableEntry>::PteConfig, ) -> Result<usize, PagingError>
Remaps one existing mapping and returns its page size.
Sourcepub fn query(
&self,
vaddr: VirtAddr,
) -> Result<(PhysAddr, <<T as TableMeta>::P as PageTableEntry>::PteConfig, usize), PagingError>
pub fn query( &self, vaddr: VirtAddr, ) -> Result<(PhysAddr, <<T as TableMeta>::P as PageTableEntry>::PteConfig, usize), PagingError>
Queries one mapping and returns the translated physical address, flags, and page size.
Sourcepub fn map(
&mut self,
config: &MapConfig<<<T as TableMeta>::P as PageTableEntry>::PteConfig>,
) -> Result<(), PagingError>
pub fn map( &mut self, config: &MapConfig<<<T as TableMeta>::P as PageTableEntry>::PteConfig>, ) -> Result<(), PagingError>
映射虚拟地址范围到物理地址范围
Sourcepub fn unmap_with_config(
&mut self,
config: &UnmapConfig,
) -> Result<(), PagingError>
pub fn unmap_with_config( &mut self, config: &UnmapConfig, ) -> Result<(), PagingError>
使用配置对象取消映射
Sourcepub fn walk_all(&self, config: WalkConfig) -> PageTableWalker<'_, T, A> ⓘ
pub fn walk_all(&self, config: WalkConfig) -> PageTableWalker<'_, T, A> ⓘ
创建页表遍历迭代器
pub fn walk( &self, start_vaddr: VirtAddr, end_vaddr: VirtAddr, ) -> impl Iterator<Item = PteInfo<<T as TableMeta>::P>>
Sourcepub fn walk_valid(&self) -> impl Iterator<Item = PteInfo<<T as TableMeta>::P>>
pub fn walk_valid(&self) -> impl Iterator<Item = PteInfo<<T as TableMeta>::P>>
遍历所有有效的最终映射页表项(过滤掉无效项和中间级别的页表指针)
pub const fn page_size() -> usize
pub const fn table_levels() -> usize
pub const fn valid_bits() -> usize
Sourcepub unsafe fn destroy(self)
pub unsafe fn destroy(self)
销毁整个页表结构
此方法会:
- 递归释放根帧及所有子页表帧
- 清除所有页表项(设为invalid)
- 不释放映射的物理页(数据页/大页)
§Safety
调用者必须确保:
- 没有其他代码在访问这个页表
- 没有CPU正在使用这个页表进行地址翻译
- 调用后不再使用这个PageTable实例
Sourcepub unsafe fn deallocate(&mut self)
pub unsafe fn deallocate(&mut self)
释放页表占用的所有页表帧
与destroy()不同,这个方法保留PageTable结构, 但释放所有关联的页表帧。调用后PageTable不再可用。
释放行为:
- 释放所有页表帧
- 清除所有页表项(设为invalid)
- 不释放映射的物理页(数据页/大页)
§Safety
调用者必须确保:
- 没有其他代码在访问这个页表
- 没有CPU正在使用这个页表进行地址翻译
Sourcepub fn deallocate_range(
&mut self,
start_vaddr: VirtAddr,
end_vaddr: VirtAddr,
) -> Result<(), PagingError>
pub fn deallocate_range( &mut self, start_vaddr: VirtAddr, end_vaddr: VirtAddr, ) -> Result<(), PagingError>
释放页表中的指定映射区域
释放指定虚拟地址范围内的所有页表项和子页表帧 在释放前将相关PTE设为invalid
Sourcepub fn translate(
&self,
vaddr: VirtAddr,
) -> Result<(PhysAddr, <T as TableMeta>::P), PagingError>
pub fn translate( &self, vaddr: VirtAddr, ) -> Result<(PhysAddr, <T as TableMeta>::P), PagingError>
Sourcepub fn translate_with_level(
&self,
vaddr: VirtAddr,
) -> Result<(PhysAddr, <T as TableMeta>::P, usize), PagingError>
pub fn translate_with_level( &self, vaddr: VirtAddr, ) -> Result<(PhysAddr, <T as TableMeta>::P, usize), PagingError>
Translates a virtual address and returns the matched PTE level.
Sourcepub fn translate_phys(&self, vaddr: VirtAddr) -> Result<PhysAddr, PagingError>
pub fn translate_phys(&self, vaddr: VirtAddr) -> Result<PhysAddr, PagingError>
Sourcepub fn root_paddr(&self) -> PhysAddr
pub fn root_paddr(&self) -> PhysAddr
获取页表的根帧物理地址
Trait Implementations§
Source§impl<T, A> Clone for PageTableRef<T, A>
impl<T, A> Clone for PageTableRef<T, A>
Source§fn clone(&self) -> PageTableRef<T, A>
fn clone(&self) -> PageTableRef<T, A>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T, A> Copy for PageTableRef<T, A>
Source§impl<T, A> Debug for PageTableRef<T, A>
impl<T, A> Debug for PageTableRef<T, A>
Source§impl<T, A> PageTableOp for PageTableRef<T, A>where
T: TableMeta,
A: FrameAllocator,
impl<T, A> PageTableOp for PageTableRef<T, A>where
T: TableMeta,
A: FrameAllocator,
type PteConfig = <<T as TableMeta>::P as PageTableEntry>::PteConfig
fn addr(&self) -> PhysAddr
fn map( &mut self, config: &MapConfig<<PageTableRef<T, A> as PageTableOp>::PteConfig>, ) -> Result<(), PagingError>
fn unmap( &mut self, virt_start: VirtAddr, size: usize, ) -> Result<(), PagingError>
Auto Trait Implementations§
impl<T, A> Freeze for PageTableRef<T, A>
impl<T, A> RefUnwindSafe for PageTableRef<T, A>where
Frame<T, A>: RefUnwindSafe,
impl<T, A> Send for PageTableRef<T, A>
impl<T, A> Sync for PageTableRef<T, A>
impl<T, A> Unpin for PageTableRef<T, A>
impl<T, A> UnsafeUnpin for PageTableRef<T, A>where
Frame<T, A>: UnsafeUnpin,
impl<T, A> UnwindSafe for PageTableRef<T, A>where
Frame<T, A>: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.