MappingArea

Struct MappingArea 

Source
pub struct MappingArea {
    vpn_range: PageNumRange<Vpn>,
    area_type: AreaType,
    map_type: MapType,
    permission: UniversalPTEFlag,
    frames: BTreeMap<Vpn, TrackedFrames>,
    file: Option<MmapFile>,
}
Expand description

内存空间中的一个内存映射区域

Fields§

§vpn_range: PageNumRange<Vpn>

此映射区域的虚拟页号范围

现已移除大页映射,不用在意 ~~ 注意!~~

~~ 创建后不要更改它,~~ ~~ 不要用它来映射或解除映射页~~

§area_type: AreaType

此映射区域的类型

§map_type: MapType

映射策略类型

§permission: UniversalPTEFlag

此映射区域的权限(使用 UniversalPTEFlag 以提高性能)

§frames: BTreeMap<Vpn, TrackedFrames>

用于帧映射区域的跟踪帧

§file: Option<MmapFile>

文件映射信息(如果是文件映射)

Implementations§

Source§

impl MappingArea

Source

pub fn vpn_range(&self) -> PageNumRange<Vpn>

Source

pub fn permission(&self) -> UniversalPTEFlag

Source

pub fn set_permission(&mut self, perm: UniversalPTEFlag)

Source

pub fn map_type(&self) -> MapType

Source

pub fn area_type(&self) -> AreaType

Source

pub fn get_ppn(&self, vpn: Vpn) -> Option<Ppn>

获取虚拟页号(VPN)对应的物理页号(PPN)(如果已映射)

Source

pub fn new( vpn_range: PageNumRange<Vpn>, area_type: AreaType, map_type: MapType, permission: UniversalPTEFlag, file: Option<MmapFile>, ) -> Self

Source

pub fn map_one( &mut self, page_table: &mut PageTableInner, vpn: Vpn, ) -> Result<(), PagingError>

映射单个虚拟页到物理页

Source

pub fn map( &mut self, page_table: &mut PageTableInner, ) -> Result<(), PagingError>

映射此映射区域中的所有页

Source

pub fn unmap_one( &mut self, page_table: &mut PageTableInner, vpn: Vpn, ) -> Result<(), PagingError>

解除映射单个虚拟页

Source

pub fn unmap( &mut self, page_table: &mut PageTableInner, ) -> Result<(), PagingError>

解除映射此映射区域中的所有页

Source

pub fn copy_data( &self, page_table: &mut PageTableInner, data: &[u8], offset: usize, )

复制数据到已映射的区域

Source

pub fn clone_metadata(&self) -> Self

克隆元数据,但不克隆帧 用于写时复制(COW)的 fork

Source

pub fn clone_with_data( &self, page_table: &mut PageTableInner, ) -> Result<Self, PagingError>

克隆映射区域及其数据 仅支持帧映射区域

Source

pub fn split_at( self, page_table: &mut PageTableInner, split_vpn: Vpn, ) -> Result<(Self, Self), PagingError>

拆分区域为两部分:[start, split_vpn) 和 [split_vpn, end)

§参数
  • page_table: 页表的可变引用
  • split_vpn: 拆分点(必须在区域范围内,且不等于边界)
§返回值
  • Ok((left, right)): 成功,返回拆分后的两个区域
  • Err(PagingError): 拆分失败
§注意
  • 原区域会被消耗(moved)
  • 调用者负责将拆分后的区域插入到 areas 列表中
  • 只支持 Framed 映射类型
Source

pub fn partial_change_permission( self, page_table: &mut PageTableInner, start_vpn: Vpn, end_vpn: Vpn, new_perm: UniversalPTEFlag, ) -> Result<Vec<Self>, PagingError>

部分修改权限:修改 [start_vpn, end_vpn) 范围的权限

§参数
  • page_table: 页表的可变引用
  • start_vpn: 起始 VPN(包含)
  • end_vpn: 结束 VPN(不包含)
  • new_perm: 新的权限标志
§返回值
  • Ok(alloc::vec::Vec<Self>): 成功,返回修改后的区域列表
    • 如果整个区域都在范围内:返回包含1个区域的向量(权限已修改)
    • 如果部分在范围内:返回包含2-3个区域的向量(分割后的区域)
§注意
  • 原区域会被消耗(moved)
  • 调用者负责将返回的区域插入到 areas 列表中
  • 只支持 Framed 映射类型
Source

pub fn partial_unmap( self, page_table: &mut PageTableInner, start_vpn: Vpn, end_vpn: Vpn, ) -> Result<Option<(Self, Option<Self>)>, PagingError>

部分解除映射:解除 [start_vpn, end_vpn) 范围的映射

§参数
  • page_table: 页表的可变引用
  • start_vpn: 起始 VPN(包含)
  • end_vpn: 结束 VPN(不包含)
§返回值
  • Ok(Option<(Self, Option<Self>)>): 成功
    • None: 整个区域被解除映射
    • Some((left, None)): 只剩左侧部分
    • Some((left, Some(right))): 中间被解除映射,剩下左右两部分
§注意
  • 原区域会被消耗(moved)
Source

pub fn load_from_file(&mut self) -> Result<(), PagingError>

从文件加载数据到已分配的物理页中

§错误
  • 文件读取失败
  • 页面未分配
Source

pub fn sync_file( &self, page_table: &mut PageTableInner, ) -> Result<(), PagingError>

将脏页写回文件

§参数
  • page_table: 页表引用,用于检查和清除 Dirty 位
§错误
  • 文件写入失败
  • 部分写入
Source§

impl MappingArea

动态扩展和收缩

Source

pub fn extend( &mut self, page_table: &mut PageTableInner, count: usize, ) -> Result<Vpn, PagingError>

通过在末尾添加页来扩展区域(仅限 4K 页)

返回新的结束 VPN

Source

pub fn shrink( &mut self, page_table: &mut PageTableInner, count: usize, ) -> Result<Vpn, PagingError>

通过从末尾移除页来收缩区域(仅限 4K 页)

返回新的结束 VPN

Trait Implementations§

Source§

impl Debug for MappingArea

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for MappingArea

§

impl !RefUnwindSafe for MappingArea

§

impl Send for MappingArea

§

impl Sync for MappingArea

§

impl Unpin for MappingArea

§

impl !UnwindSafe for MappingArea

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.