Skip to content

Commit

Permalink
Merge #208
Browse files Browse the repository at this point in the history
208: add support of big endian r=stlankes a=stlankes

Check the correct endian to determine the file size

Co-authored-by: Stefan Lankes <[email protected]>
  • Loading branch information
bors[bot] and stlankes authored Apr 15, 2023
2 parents 2db7c69 + 4be6b41 commit 8e05e2e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,19 @@ pub fn find_kernel() -> &'static [u8] {
}
}

// we assume that the loader use little endian
#[cfg(target_endian = "little")]
let file_size = if header.e_ident[EI_DATA] == ELFDATA2LSB {
header.e_shoff + (header.e_shentsize as u64 * header.e_shnum as u64)
} else {
let sz = header.e_shoff + (header.e_shentsize as u64 * header.e_shnum as u64);
sz.to_le()
header.e_shoff.to_le() + (header.e_shentsize.to_le() as u64 * header.e_shnum.to_le() as u64)
};
#[cfg(target_endian = "big")]
let file_size = if header.e_ident[EI_DATA] == ELFDATA2LSB {
header.e_shoff.to_be() + (header.e_shentsize.to_be() as u64 * header.e_shnum.to_be() as u64)
} else {
header.e_shoff + (header.e_shentsize as u64 * header.e_shnum as u64)
};

info!("Found ELF file with size {}", file_size);

unsafe { core::slice::from_raw_parts(module_start as *const u8, file_size.try_into().unwrap()) }
Expand Down

0 comments on commit 8e05e2e

Please sign in to comment.