Let jump in pagetable cursor return Result

This commit is contained in:
Chen Chengjun 2024-08-27 11:40:04 +08:00 committed by Tate, Hongliang Tian
parent d179fa8788
commit 0c01590981
2 changed files with 15 additions and 11 deletions

View File

@ -253,14 +253,16 @@ where
}
/// Jumps to the given virtual address.
/// If the target address is out of the range, this method will return `Err`.
///
/// # Panics
///
/// This method panics if the address is out of the range where the cursor is required to operate,
/// or has bad alignment.
pub fn jump(&mut self, va: Vaddr) {
assert!(self.barrier_va.contains(&va));
/// This method panics if the address has bad alignment.
pub fn jump(&mut self, va: Vaddr) -> Result<(), PageTableError> {
assert!(va % C::BASE_PAGE_SIZE == 0);
if !self.barrier_va.contains(&va) {
return Err(PageTableError::InvalidVaddr(va));
}
loop {
let cur_node_start = self.va & !(page_size::<C>(self.level + 1) - 1);
@ -268,14 +270,14 @@ where
// If the address is within the current node, we can jump directly.
if cur_node_start <= va && va < cur_node_end {
self.va = va;
return;
return Ok(());
}
// There is a corner case that the cursor is depleted, sitting at the start of the
// next node but the next node is not locked because the parent is not locked.
if self.va >= self.barrier_va.end && self.level == self.guard_level {
self.va = va;
return;
return Ok(());
}
debug_assert!(self.level < self.guard_level);
@ -405,7 +407,7 @@ where
///
/// This method panics if the address is out of the range where the cursor is required to operate,
/// or has bad alignment.
pub fn jump(&mut self, va: Vaddr) {
pub fn jump(&mut self, va: Vaddr) -> Result<(), PageTableError> {
self.0.jump(va)
}

View File

@ -311,8 +311,9 @@ impl Cursor<'_> {
}
/// Jump to the virtual address.
pub fn jump(&mut self, va: Vaddr) {
self.0.jump(va);
pub fn jump(&mut self, va: Vaddr) -> Result<()> {
self.0.jump(va)?;
Ok(())
}
/// Get the virtual address of the current slot.
@ -340,8 +341,9 @@ impl CursorMut<'_> {
/// Jump to the virtual address.
///
/// This is the same as [`Cursor::jump`].
pub fn jump(&mut self, va: Vaddr) {
self.0.jump(va);
pub fn jump(&mut self, va: Vaddr) -> Result<()>{
self.0.jump(va)?;
Ok(())
}
/// Get the virtual address of the current slot.