mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Rename PageTableQueryResult
to PageTableItem
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
6df0a3073c
commit
e597a10088
@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use ostd::mm::{
|
use ostd::mm::{vm_space::VmItem, CachePolicy, Frame, PageFlags, PageProperty, VmIo, VmSpace};
|
||||||
vm_space::VmQueryResult, CachePolicy, Frame, PageFlags, PageProperty, VmIo, VmSpace,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{interval::Interval, is_intersected, Vmar, Vmar_};
|
use super::{interval::Interval, is_intersected, Vmar, Vmar_};
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -221,12 +219,12 @@ impl VmMapping {
|
|||||||
drop(cursor);
|
drop(cursor);
|
||||||
|
|
||||||
match map_info {
|
match map_info {
|
||||||
VmQueryResult::Mapped { va, prop, .. } => {
|
VmItem::Mapped { va, prop, .. } => {
|
||||||
if !prop.flags.contains(PageFlags::W) {
|
if !prop.flags.contains(PageFlags::W) {
|
||||||
self.handle_page_fault(va, false, true)?;
|
self.handle_page_fault(va, false, true)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VmQueryResult::NotMapped { va, .. } => {
|
VmItem::NotMapped { va, .. } => {
|
||||||
self.handle_page_fault(va, true, true)?;
|
self.handle_page_fault(va, true, true)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ use super::{
|
|||||||
use crate::mm::{page::DynPage, Paddr, PageProperty, Vaddr};
|
use crate::mm::{page::DynPage, Paddr, PageProperty, Vaddr};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum PageTableQueryResult {
|
pub enum PageTableItem {
|
||||||
NotMapped {
|
NotMapped {
|
||||||
va: Vaddr,
|
va: Vaddr,
|
||||||
len: usize,
|
len: usize,
|
||||||
@ -195,7 +195,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the information of the current slot.
|
/// Gets the information of the current slot.
|
||||||
pub fn query(&mut self) -> Result<PageTableQueryResult, PageTableError> {
|
pub fn query(&mut self) -> Result<PageTableItem, PageTableError> {
|
||||||
if self.va >= self.barrier_va.end {
|
if self.va >= self.barrier_va.end {
|
||||||
return Err(PageTableError::InvalidVaddr(self.va));
|
return Err(PageTableError::InvalidVaddr(self.va));
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ where
|
|||||||
|
|
||||||
let pte = self.read_cur_pte();
|
let pte = self.read_cur_pte();
|
||||||
if !pte.is_present() {
|
if !pte.is_present() {
|
||||||
return Ok(PageTableQueryResult::NotMapped {
|
return Ok(PageTableItem::NotMapped {
|
||||||
va,
|
va,
|
||||||
len: page_size::<C>(level),
|
len: page_size::<C>(level),
|
||||||
});
|
});
|
||||||
@ -218,14 +218,14 @@ where
|
|||||||
|
|
||||||
match self.cur_child() {
|
match self.cur_child() {
|
||||||
Child::Page(page) => {
|
Child::Page(page) => {
|
||||||
return Ok(PageTableQueryResult::Mapped {
|
return Ok(PageTableItem::Mapped {
|
||||||
va,
|
va,
|
||||||
page,
|
page,
|
||||||
prop: pte.prop(),
|
prop: pte.prop(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Child::Untracked(pa) => {
|
Child::Untracked(pa) => {
|
||||||
return Ok(PageTableQueryResult::MappedUntracked {
|
return Ok(PageTableItem::MappedUntracked {
|
||||||
va,
|
va,
|
||||||
pa,
|
pa,
|
||||||
len: page_size::<C>(level),
|
len: page_size::<C>(level),
|
||||||
@ -355,7 +355,7 @@ impl<'a, M: PageTableMode, E: PageTableEntryTrait, C: PagingConstsTrait> Iterato
|
|||||||
where
|
where
|
||||||
[(); C::NR_LEVELS as usize]:,
|
[(); C::NR_LEVELS as usize]:,
|
||||||
{
|
{
|
||||||
type Item = PageTableQueryResult;
|
type Item = PageTableItem;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let result = self.query();
|
let result = self.query();
|
||||||
@ -415,7 +415,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the information of the current slot.
|
/// Gets the information of the current slot.
|
||||||
pub fn query(&mut self) -> Result<PageTableQueryResult, PageTableError> {
|
pub fn query(&mut self) -> Result<PageTableItem, PageTableError> {
|
||||||
self.0.query()
|
self.0.query()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ use crate::{
|
|||||||
mod node;
|
mod node;
|
||||||
use node::*;
|
use node::*;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
pub use cursor::{Cursor, CursorMut, PageTableQueryResult};
|
pub use cursor::{Cursor, CursorMut, PageTableItem};
|
||||||
#[cfg(ktest)]
|
#[cfg(ktest)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
|
@ -114,8 +114,6 @@ fn test_user_copy_on_write() {
|
|||||||
assert!(child_pt.query(from.start + 10).is_none());
|
assert!(child_pt.query(from.start + 10).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
type Qr = PageTableQueryResult;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
struct BasePagingConsts {}
|
struct BasePagingConsts {}
|
||||||
|
|
||||||
@ -141,9 +139,9 @@ fn test_base_protect_query() {
|
|||||||
cursor.map(page.clone().into(), prop);
|
cursor.map(page.clone().into(), prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (qr, i) in pt.cursor(&from).unwrap().zip(from_ppn) {
|
for (item, i) in pt.cursor(&from).unwrap().zip(from_ppn) {
|
||||||
let Qr::Mapped { va, page, prop } = qr else {
|
let PageTableItem::Mapped { va, page, prop } = item else {
|
||||||
panic!("Expected Mapped, got {:#x?}", qr);
|
panic!("Expected Mapped, got {:#x?}", item);
|
||||||
};
|
};
|
||||||
assert_eq!(prop.flags, PageFlags::RW);
|
assert_eq!(prop.flags, PageFlags::RW);
|
||||||
assert_eq!(prop.cache, CachePolicy::Writeback);
|
assert_eq!(prop.cache, CachePolicy::Writeback);
|
||||||
@ -151,9 +149,9 @@ fn test_base_protect_query() {
|
|||||||
}
|
}
|
||||||
let prot = PAGE_SIZE * 18..PAGE_SIZE * 20;
|
let prot = PAGE_SIZE * 18..PAGE_SIZE * 20;
|
||||||
unsafe { pt.protect(&prot, |p| p.flags -= PageFlags::W).unwrap() };
|
unsafe { pt.protect(&prot, |p| p.flags -= PageFlags::W).unwrap() };
|
||||||
for (qr, i) in pt.cursor(&prot).unwrap().zip(18..20) {
|
for (item, i) in pt.cursor(&prot).unwrap().zip(18..20) {
|
||||||
let Qr::Mapped { va, page, prop } = qr else {
|
let PageTableItem::Mapped { va, page, prop } = item else {
|
||||||
panic!("Expected Mapped, got {:#x?}", qr);
|
panic!("Expected Mapped, got {:#x?}", item);
|
||||||
};
|
};
|
||||||
assert_eq!(prop.flags, PageFlags::R);
|
assert_eq!(prop.flags, PageFlags::R);
|
||||||
assert_eq!(va..va + page.size(), i * PAGE_SIZE..(i + 1) * PAGE_SIZE);
|
assert_eq!(va..va + page.size(), i * PAGE_SIZE..(i + 1) * PAGE_SIZE);
|
||||||
@ -190,9 +188,9 @@ fn test_untracked_large_protect_query() {
|
|||||||
let mapped_pa_of_va = |va: Vaddr| va - (from.start - to.start);
|
let mapped_pa_of_va = |va: Vaddr| va - (from.start - to.start);
|
||||||
let prop = PageProperty::new(PageFlags::RW, CachePolicy::Writeback);
|
let prop = PageProperty::new(PageFlags::RW, CachePolicy::Writeback);
|
||||||
unsafe { pt.map(&from, &to, prop).unwrap() };
|
unsafe { pt.map(&from, &to, prop).unwrap() };
|
||||||
for (qr, i) in pt.cursor(&from).unwrap().zip(0..512 + 2 + 2) {
|
for (item, i) in pt.cursor(&from).unwrap().zip(0..512 + 2 + 2) {
|
||||||
let Qr::MappedUntracked { va, pa, len, prop } = qr else {
|
let PageTableItem::MappedUntracked { va, pa, len, prop } = item else {
|
||||||
panic!("Expected MappedUntracked, got {:#x?}", qr);
|
panic!("Expected MappedUntracked, got {:#x?}", item);
|
||||||
};
|
};
|
||||||
assert_eq!(pa, mapped_pa_of_va(va));
|
assert_eq!(pa, mapped_pa_of_va(va));
|
||||||
assert_eq!(prop.flags, PageFlags::RW);
|
assert_eq!(prop.flags, PageFlags::RW);
|
||||||
@ -214,35 +212,35 @@ fn test_untracked_large_protect_query() {
|
|||||||
let ppn = from_ppn.start + 18..from_ppn.start + 20;
|
let ppn = from_ppn.start + 18..from_ppn.start + 20;
|
||||||
let va = UNTRACKED_OFFSET + PAGE_SIZE * ppn.start..UNTRACKED_OFFSET + PAGE_SIZE * ppn.end;
|
let va = UNTRACKED_OFFSET + PAGE_SIZE * ppn.start..UNTRACKED_OFFSET + PAGE_SIZE * ppn.end;
|
||||||
unsafe { pt.protect(&va, |p| p.flags -= PageFlags::W).unwrap() };
|
unsafe { pt.protect(&va, |p| p.flags -= PageFlags::W).unwrap() };
|
||||||
for (qr, i) in pt
|
for (item, i) in pt
|
||||||
.cursor(&(va.start - PAGE_SIZE..va.start))
|
.cursor(&(va.start - PAGE_SIZE..va.start))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.zip(ppn.start - 1..ppn.start)
|
.zip(ppn.start - 1..ppn.start)
|
||||||
{
|
{
|
||||||
let Qr::MappedUntracked { va, pa, len, prop } = qr else {
|
let PageTableItem::MappedUntracked { va, pa, len, prop } = item else {
|
||||||
panic!("Expected MappedUntracked, got {:#x?}", qr);
|
panic!("Expected MappedUntracked, got {:#x?}", item);
|
||||||
};
|
};
|
||||||
assert_eq!(pa, mapped_pa_of_va(va));
|
assert_eq!(pa, mapped_pa_of_va(va));
|
||||||
assert_eq!(prop.flags, PageFlags::RW);
|
assert_eq!(prop.flags, PageFlags::RW);
|
||||||
let va = va - UNTRACKED_OFFSET;
|
let va = va - UNTRACKED_OFFSET;
|
||||||
assert_eq!(va..va + len, i * PAGE_SIZE..(i + 1) * PAGE_SIZE);
|
assert_eq!(va..va + len, i * PAGE_SIZE..(i + 1) * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
for (qr, i) in pt.cursor(&va).unwrap().zip(ppn.clone()) {
|
for (item, i) in pt.cursor(&va).unwrap().zip(ppn.clone()) {
|
||||||
let Qr::MappedUntracked { va, pa, len, prop } = qr else {
|
let PageTableItem::MappedUntracked { va, pa, len, prop } = item else {
|
||||||
panic!("Expected MappedUntracked, got {:#x?}", qr);
|
panic!("Expected MappedUntracked, got {:#x?}", item);
|
||||||
};
|
};
|
||||||
assert_eq!(pa, mapped_pa_of_va(va));
|
assert_eq!(pa, mapped_pa_of_va(va));
|
||||||
assert_eq!(prop.flags, PageFlags::R);
|
assert_eq!(prop.flags, PageFlags::R);
|
||||||
let va = va - UNTRACKED_OFFSET;
|
let va = va - UNTRACKED_OFFSET;
|
||||||
assert_eq!(va..va + len, i * PAGE_SIZE..(i + 1) * PAGE_SIZE);
|
assert_eq!(va..va + len, i * PAGE_SIZE..(i + 1) * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
for (qr, i) in pt
|
for (item, i) in pt
|
||||||
.cursor(&(va.end..va.end + PAGE_SIZE))
|
.cursor(&(va.end..va.end + PAGE_SIZE))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.zip(ppn.end..ppn.end + 1)
|
.zip(ppn.end..ppn.end + 1)
|
||||||
{
|
{
|
||||||
let Qr::MappedUntracked { va, pa, len, prop } = qr else {
|
let PageTableItem::MappedUntracked { va, pa, len, prop } = item else {
|
||||||
panic!("Expected MappedUntracked, got {:#x?}", qr);
|
panic!("Expected MappedUntracked, got {:#x?}", item);
|
||||||
};
|
};
|
||||||
assert_eq!(pa, mapped_pa_of_va(va));
|
assert_eq!(pa, mapped_pa_of_va(va));
|
||||||
assert_eq!(prop.flags, PageFlags::RW);
|
assert_eq!(prop.flags, PageFlags::RW);
|
||||||
|
@ -26,7 +26,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
cpu::CpuExceptionInfo,
|
cpu::CpuExceptionInfo,
|
||||||
mm::{
|
mm::{
|
||||||
page_table::{self, PageTableQueryResult as PtQr},
|
page_table::{self, PageTableItem},
|
||||||
Frame, MAX_USERSPACE_VADDR,
|
Frame, MAX_USERSPACE_VADDR,
|
||||||
},
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -211,7 +211,7 @@ impl Default for VmSpace {
|
|||||||
pub struct Cursor<'a>(page_table::Cursor<'a, UserMode, PageTableEntry, PagingConsts>);
|
pub struct Cursor<'a>(page_table::Cursor<'a, UserMode, PageTableEntry, PagingConsts>);
|
||||||
|
|
||||||
impl Iterator for Cursor<'_> {
|
impl Iterator for Cursor<'_> {
|
||||||
type Item = VmQueryResult;
|
type Item = VmItem;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let result = self.query();
|
let result = self.query();
|
||||||
@ -226,8 +226,8 @@ impl Cursor<'_> {
|
|||||||
/// Query about the current slot.
|
/// Query about the current slot.
|
||||||
///
|
///
|
||||||
/// This function won't bring the cursor to the next slot.
|
/// This function won't bring the cursor to the next slot.
|
||||||
pub fn query(&mut self) -> Result<VmQueryResult> {
|
pub fn query(&mut self) -> Result<VmItem> {
|
||||||
Ok(self.0.query().map(|ptqr| ptqr.try_into().unwrap())?)
|
Ok(self.0.query().map(|item| item.try_into().unwrap())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Jump to the virtual address.
|
/// Jump to the virtual address.
|
||||||
@ -253,8 +253,8 @@ impl CursorMut<'_> {
|
|||||||
/// This is the same as [`Cursor::query`].
|
/// This is the same as [`Cursor::query`].
|
||||||
///
|
///
|
||||||
/// This function won't bring the cursor to the next slot.
|
/// This function won't bring the cursor to the next slot.
|
||||||
pub fn query(&mut self) -> Result<VmQueryResult> {
|
pub fn query(&mut self) -> Result<VmItem> {
|
||||||
Ok(self.0.query().map(|ptqr| ptqr.try_into().unwrap())?)
|
Ok(self.0.query().map(|item| item.try_into().unwrap())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Jump to the virtual address.
|
/// Jump to the virtual address.
|
||||||
@ -339,7 +339,7 @@ impl CursorMut<'_> {
|
|||||||
|
|
||||||
/// The result of a query over the VM space.
|
/// The result of a query over the VM space.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum VmQueryResult {
|
pub enum VmItem {
|
||||||
/// The current slot is not mapped.
|
/// The current slot is not mapped.
|
||||||
NotMapped {
|
NotMapped {
|
||||||
/// The virtual address of the slot.
|
/// The virtual address of the slot.
|
||||||
@ -358,20 +358,22 @@ pub enum VmQueryResult {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<PtQr> for VmQueryResult {
|
impl TryFrom<PageTableItem> for VmItem {
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
|
|
||||||
fn try_from(ptqr: PtQr) -> core::result::Result<Self, Self::Error> {
|
fn try_from(item: PageTableItem) -> core::result::Result<Self, Self::Error> {
|
||||||
match ptqr {
|
match item {
|
||||||
PtQr::NotMapped { va, len } => Ok(VmQueryResult::NotMapped { va, len }),
|
PageTableItem::NotMapped { va, len } => Ok(VmItem::NotMapped { va, len }),
|
||||||
PtQr::Mapped { va, page, prop } => Ok(VmQueryResult::Mapped {
|
PageTableItem::Mapped { va, page, prop } => Ok(VmItem::Mapped {
|
||||||
va,
|
va,
|
||||||
frame: page
|
frame: page
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| "found typed memory mapped into `VmSpace`")?,
|
.map_err(|_| "found typed memory mapped into `VmSpace`")?,
|
||||||
prop,
|
prop,
|
||||||
}),
|
}),
|
||||||
PtQr::MappedUntracked { .. } => Err("found untracked memory mapped into `VmSpace`"),
|
PageTableItem::MappedUntracked { .. } => {
|
||||||
|
Err("found untracked memory mapped into `VmSpace`")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user