Skip to content

Commit

Permalink
Ensure MemoryRegions are aligned to 4096
Browse files Browse the repository at this point in the history
  • Loading branch information
Wasabi375 committed Jun 23, 2024
1 parent 9b3efcb commit b0cae12
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/src/legacy_memory_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::{
mem::MaybeUninit,
};
use x86_64::{
align_down, align_up,
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
PhysAddr,
};
Expand Down Expand Up @@ -232,9 +233,12 @@ where
.map(|start| UsedMemorySlice::new_from_len(start.as_u64(), ramdisk_slice_len)),
)
.chain(used_slices)
.map(|slice| UsedMemorySlice {
start: align_down(slice.start, 0x1000),
end: align_up(slice.end, 0x1000),
})
}

// TODO unit test
fn split_and_add_region<'a, U>(
mut region: MemoryRegion,
regions: &mut [MaybeUninit<MemoryRegion>],
Expand Down Expand Up @@ -347,7 +351,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
use bootloader_api::info::MemoryRegionKind;

#[derive(Copy, Clone, Debug)]
struct TestMemoryRegion {
Expand Down

0 comments on commit b0cae12

Please sign in to comment.