Skip to content

Commit 7dfff15

Browse files
committed
Page align region length
1 parent 32a2df9 commit 7dfff15

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/frame_allocator.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use os_bootinfo::{MemoryMap, MemoryRegion, MemoryRegionType};
22
use x86_64::structures::paging::{PhysFrame, PAGE_SIZE};
3+
use x86_64::align_up;
34

45
pub(crate) struct FrameAllocator<'a> {
56
pub memory_map: &'a mut MemoryMap,
@@ -16,6 +17,7 @@ impl<'a> FrameAllocator<'a> {
1617
if region.len < page_size {
1718
continue;
1819
}
20+
1921
assert_eq!(
2022
0,
2123
region.start_addr.as_u64() & 0xfff,
@@ -61,14 +63,16 @@ impl<'a> FrameAllocator<'a> {
6163
self.add_region_overwrite(region, false);
6264
}
6365

64-
fn add_region_overwrite(&mut self, region: MemoryRegion, overwrite: bool) {
66+
fn add_region_overwrite(&mut self, mut region: MemoryRegion, overwrite: bool) {
6567
assert_eq!(
6668
0,
6769
region.start_addr.as_u64() & 0xfff,
6870
"Region start address is not page aligned: {:?}",
6971
region
7072
);
7173

74+
region.len = align_up(region.len, PAGE_SIZE.into());
75+
7276
let mut region_already_inserted = false;
7377
let mut split_region = None;
7478

0 commit comments

Comments
 (0)