mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-16 08: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.
|
||||
/// 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)
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user