Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ impl VirtAddr {
self.0
}

/// Preforms a checked add between two virtual addresses
///
/// Panics if an integer overflow occurs
#[inline]
pub fn checked_add<U>(self, addr: U) -> VirtAddr
where
U: Into<u64>,
{
VirtAddr::new(
self.as_u64()
.checked_add(addr.into())
.expect("Integer overflow"),
)
}
/// Creates a virtual address from the given pointer
// cfg(target_pointer_width = "32") is only here for backwards
// compatibility: Earlier versions of this crate did not have any `cfg()`
Expand Down
2 changes: 1 addition & 1 deletion src/structures/paging/mapper/offset_page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PhysOffset {

unsafe impl PageTableFrameMapping for PhysOffset {
fn frame_to_pointer(&self, frame: PhysFrame) -> *mut PageTable {
let virt = self.offset + frame.start_address().as_u64();
let virt = self.offset.checked_add(frame.start_address().as_u64());
virt.as_mut_ptr()
}
}
Expand Down