Skip to content

Commit b0cae12

Browse files
committed
Ensure MemoryRegions are aligned to 4096
1 parent 9b3efcb commit b0cae12

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

common/src/legacy_memory_region.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::{
55
mem::MaybeUninit,
66
};
77
use x86_64::{
8+
align_down, align_up,
89
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
910
PhysAddr,
1011
};
@@ -232,9 +233,12 @@ where
232233
.map(|start| UsedMemorySlice::new_from_len(start.as_u64(), ramdisk_slice_len)),
233234
)
234235
.chain(used_slices)
236+
.map(|slice| UsedMemorySlice {
237+
start: align_down(slice.start, 0x1000),
238+
end: align_up(slice.end, 0x1000),
239+
})
235240
}
236241

237-
// TODO unit test
238242
fn split_and_add_region<'a, U>(
239243
mut region: MemoryRegion,
240244
regions: &mut [MaybeUninit<MemoryRegion>],
@@ -347,7 +351,6 @@ where
347351
#[cfg(test)]
348352
mod tests {
349353
use super::*;
350-
use bootloader_api::info::MemoryRegionKind;
351354

352355
#[derive(Copy, Clone, Debug)]
353356
struct TestMemoryRegion {

0 commit comments

Comments
 (0)