redone page size thing

feature/trap-handlers
ondra05 2023-06-22 11:55:33 +02:00
parent e2156b436d
commit 3d6376051f
No known key found for this signature in database
GPG Key ID: 0DA6D2BB2285E881
1 changed files with 12 additions and 5 deletions

View File

@ -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,
}