Do not allow phys_to_virt overflow

This commit is contained in:
Jeremy Soller
2022-08-26 11:07:21 -06:00
parent 61ba2e6c8e
commit 27bb8e44dd
+4 -1
View File
@@ -97,7 +97,10 @@ pub trait Arch: Clone + Copy {
#[inline(always)]
unsafe fn phys_to_virt(phys: PhysicalAddress) -> VirtualAddress {
VirtualAddress::new(phys.data() + Self::PHYS_OFFSET)
match phys.data().checked_add(Self::PHYS_OFFSET) {
Some(some) => VirtualAddress::new(some),
None => panic!("phys_to_virt({:#x}) overflow", phys.data()),
}
}
fn virt_is_valid(address: VirtualAddress) -> bool;