fix(main): Fixes rounding issue in kernel num_pages (#468)

This is #466 for the `main` branch

Co-authored-by: Benjamin Eckel <bhelx@simst.im>
This commit is contained in:
zach
2023-09-18 17:38:38 -07:00
committed by GitHub
parent d040c8b8a8
commit 016e9158ef
2 changed files with 7 additions and 3 deletions

View File

@@ -119,9 +119,13 @@ pub struct MemoryBlock {
/// Returns the number of pages needed for the given number of bytes
pub fn num_pages(nbytes: u64) -> usize {
let nbytes = nbytes as f64;
let page = PAGE_SIZE as f64;
((nbytes / page) + 0.5) as usize
let npages = nbytes / PAGE_SIZE as u64;
let remainder = nbytes % PAGE_SIZE as u64;
if remainder != 0 {
(npages + 1) as usize
} else {
npages as usize
}
}
// Get the `MemoryRoot` at the correct offset in memory

Binary file not shown.