ros666::mm::memory_set

Struct MemorySet

Source
pub struct MemorySet {
    pub page_table: PageTable,
    pub areas: Vec<MapArea>,
}
Expand description

地址空间

地址空间包含了一组虚拟内存,基于三级页表实现了虚拟内存到物理内存的映射

Fields§

§page_table: PageTable§areas: Vec<MapArea>

Implementations§

Source§

impl MemorySet

Source

pub fn empty() -> Self

创建一个空的 MemorySet

Source

pub fn token(&self) -> usize

获取页表 token

token 即 satp (satp: Supervisor Address Translation and Protection) 寄存器的值

在启用 Sv39 页表时,satp 即作为三级页表的根节点。其第 60-63 位为模式位,为 0b100 时启用 Sv39 页表

Source

pub fn activate(&self)

激活当前 MemorySet

Source

pub fn push(&mut self, area: MapArea, data: Option<&[u8]>)

添加一个 MapArea 到 MemorySet

§参数
  • area - 要添加的 MapArea
  • data - 可选的数据,用于初始化映射区域
Source

pub fn insert( &mut self, va_range: Range<VirtualAddress>, permission: MapPermission, )

插入一个虚拟地址范围到 MemorySet

§参数
  • va_range - 虚拟地址范围
  • permission - 映射权限
Source

pub fn remove_area(&mut self, start_vpn: VirtualPageNumber)

移除一个 MapArea

§参数
  • start_vpn - 要移除的 MapArea 的起始虚拟页号
Source

pub fn map_trampoline(&mut self)

映射跳板

Source

pub fn translate(&self, vpn: VirtualPageNumber) -> Option<PageTableEntry>

翻译虚拟页号到页表项

§参数
  • vpn - 虚拟页号
§返回值

返回对应的页表项

Source

pub fn recycle(&mut self)

回收所有 MapArea

Source

pub fn new_kernel() -> Self

创建内核 MemorySet

Source

pub fn from_elf_app(elf: &[u8]) -> (Self, usize, usize)

从 ELF 文件创建用户 MemorySet

§参数
  • elf - ELF 文件数据
§返回值

返回创建的 MemorySet、用户栈顶地址和入口点地址

Source

pub fn from_existed_user(user_space: &MemorySet) -> Self

从已存在的用户 MemorySet 创建新的 MemorySet

§参数
  • user_space - 已存在的用户 MemorySet
§返回值

返回新的 MemorySet

Auto Trait Implementations§

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