Skip to content

Commit

Permalink
bzimage: Align start of initrd to page boundary
Browse files Browse the repository at this point in the history
We use 2MiB pages so align the start of the address for the initrd to
the page boundary to prevent the kernel trying to access memory outside
of the accessible memory (initrd is placed a the top of usable RAM.)

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed Dec 9, 2019
1 parent 6354879 commit cc2929f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bzimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
top_of_usable_ram = max_load_address;
}

let initrd_address = top_of_usable_ram - u64::from(f.get_size());
// Align address to 2MiB boundary as we use 2 MiB pages
let initrd_address = (top_of_usable_ram - u64::from(f.get_size())) & !((2 << 20) - 1);
let mut initrd_region = crate::mem::MemoryRegion::new(initrd_address, u64::from(f.get_size()));

let mut offset = 0;
Expand All @@ -94,7 +95,6 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
}

let dst = initrd_region.as_mut_slice(u64::from(offset), 512);

match f.read(dst) {
Err(crate::fat::Error::EndOfFile) => break,
Err(_) => return Err(Error::FileError),
Expand Down

0 comments on commit cc2929f

Please sign in to comment.