diff --git a/hbvm/src/vm/mem/mod.rs b/hbvm/src/vm/mem/mod.rs index 26dc8a3..05bb511 100644 --- a/hbvm/src/vm/mem/mod.rs +++ b/hbvm/src/vm/mem/mod.rs @@ -206,9 +206,9 @@ impl Iterator for PageSplitter { ptr as *mut u8, perm, match lvl { - 0 => 4096, - 1 => 1024_usize.pow(2) * 2, - 2 => 1024_usize.pow(3), + 0 => PageSize::Size4K, + 1 => PageSize::Size2M, + 2 => PageSize::Size1G, _ => return None, }, self.addr as usize & ((1 << (lvl * 9 + 12)) - 1), @@ -220,9 +220,9 @@ impl Iterator for PageSplitter { return None; }; - let avail = (size - offset).clamp(0, self.size); + let avail = (size as usize - offset).clamp(0, self.size); self.addr += size as u64; - self.size = self.size.saturating_sub(size); + self.size = self.size.saturating_sub(size as _); Some(PageSplitResult { ptr: unsafe { base.add(offset) }, size: avail, @@ -230,3 +230,10 @@ impl Iterator for PageSplitter { }) } } + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum PageSize { + Size4K = 4096, + Size2M = 1024 * 1024 * 2, + Size1G = 1024 * 1024 * 1024, +}