mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-16 17:46:48 +00:00
Let jump in pagetable cursor return Result
This commit is contained in:
parent
d179fa8788
commit
0c01590981
@ -253,14 +253,16 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Jumps to the given virtual address.
|
/// Jumps to the given virtual address.
|
||||||
|
/// If the target address is out of the range, this method will return `Err`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// This method panics if the address is out of the range where the cursor is required to operate,
|
/// This method panics if the address has bad alignment.
|
||||||
/// or has bad alignment.
|
pub fn jump(&mut self, va: Vaddr) -> Result<(), PageTableError> {
|
||||||
pub fn jump(&mut self, va: Vaddr) {
|
|
||||||
assert!(self.barrier_va.contains(&va));
|
|
||||||
assert!(va % C::BASE_PAGE_SIZE == 0);
|
assert!(va % C::BASE_PAGE_SIZE == 0);
|
||||||
|
if !self.barrier_va.contains(&va) {
|
||||||
|
return Err(PageTableError::InvalidVaddr(va));
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let cur_node_start = self.va & !(page_size::<C>(self.level + 1) - 1);
|
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 the address is within the current node, we can jump directly.
|
||||||
if cur_node_start <= va && va < cur_node_end {
|
if cur_node_start <= va && va < cur_node_end {
|
||||||
self.va = va;
|
self.va = va;
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is a corner case that the cursor is depleted, sitting at the start of the
|
// 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.
|
// 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 {
|
if self.va >= self.barrier_va.end && self.level == self.guard_level {
|
||||||
self.va = va;
|
self.va = va;
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert!(self.level < self.guard_level);
|
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,
|
/// This method panics if the address is out of the range where the cursor is required to operate,
|
||||||
/// or has bad alignment.
|
/// or has bad alignment.
|
||||||
pub fn jump(&mut self, va: Vaddr) {
|
pub fn jump(&mut self, va: Vaddr) -> Result<(), PageTableError> {
|
||||||
self.0.jump(va)
|
self.0.jump(va)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +311,9 @@ impl Cursor<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Jump to the virtual address.
|
/// Jump to the virtual address.
|
||||||
pub fn jump(&mut self, va: Vaddr) {
|
pub fn jump(&mut self, va: Vaddr) -> Result<()> {
|
||||||
self.0.jump(va);
|
self.0.jump(va)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the virtual address of the current slot.
|
/// Get the virtual address of the current slot.
|
||||||
@ -340,8 +341,9 @@ impl CursorMut<'_> {
|
|||||||
/// Jump to the virtual address.
|
/// Jump to the virtual address.
|
||||||
///
|
///
|
||||||
/// This is the same as [`Cursor::jump`].
|
/// This is the same as [`Cursor::jump`].
|
||||||
pub fn jump(&mut self, va: Vaddr) {
|
pub fn jump(&mut self, va: Vaddr) -> Result<()>{
|
||||||
self.0.jump(va);
|
self.0.jump(va)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the virtual address of the current slot.
|
/// Get the virtual address of the current slot.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user