From 965a6a2c19b4f6a9ca31bf47d58c43bf6a9e46e1 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 22 Jun 2023 11:55:33 +0200 Subject: [PATCH] redone page size thing --- hbvm/src/vm/mem/mod.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hbvm/src/vm/mem/mod.rs b/hbvm/src/vm/mem/mod.rs index 26dc8a36..05bb5116 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, +}