mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-28 17:44:10 +00:00
kernel_loader: return entry point of loaded kernel
BUG=b:234155022 TEST=cargo test -p kernel_loader Change-Id: I807d42a1cc5e2a88006fa4acc5bc7b089d0406af Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3673613 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Alexandre Courbot <acourbot@chromium.org> Reviewed-by: Anton Romanov <romanton@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
b5dbe329be
commit
333bf60e91
1 changed files with 12 additions and 0 deletions
|
@ -38,6 +38,8 @@ pub enum Error {
|
|||
CommandLineOverflow,
|
||||
#[error("invalid Elf magic number")]
|
||||
InvalidElfMagicNumber,
|
||||
#[error("invalid entry point")]
|
||||
InvalidEntryPoint,
|
||||
#[error("invalid Program Header Address")]
|
||||
InvalidProgramHeaderAddress,
|
||||
#[error("invalid Program Header memory size")]
|
||||
|
@ -69,6 +71,9 @@ pub struct LoadedKernel {
|
|||
|
||||
/// Size of the kernel image in bytes.
|
||||
pub size: u64,
|
||||
|
||||
/// Entry point address of the kernel.
|
||||
pub entry: GuestAddress,
|
||||
}
|
||||
|
||||
/// Loads a kernel from a vmlinux elf image to a slice
|
||||
|
@ -147,9 +152,15 @@ where
|
|||
|
||||
let size = kernel_end - kernel_start.offset();
|
||||
|
||||
// `e_entry` of 0 means there is no entry point, which we do not want to allow.
|
||||
if ehdr.e_entry == 0 {
|
||||
return Err(Error::InvalidEntryPoint);
|
||||
}
|
||||
|
||||
Ok(LoadedKernel {
|
||||
end: GuestAddress(kernel_end),
|
||||
size,
|
||||
entry: GuestAddress(ehdr.e_entry),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -264,6 +275,7 @@ mod test {
|
|||
let kernel = load_kernel(&gm, kernel_addr, &mut image).expect("failed to load ELF");
|
||||
assert_eq!(kernel.end, GuestAddress(0x20_0035));
|
||||
assert_eq!(kernel.size, 0x20_0035);
|
||||
assert_eq!(kernel.entry, GuestAddress(0x20_000e));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue