redone page size thing

This commit is contained in:
Erin 2023-06-22 11:55:33 +02:00 committed by ondra05
parent a08e0172c9
commit 965a6a2c19

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