Skip to content

Commit 16834d0

Browse files
mogasergiuvictorduta
authored andcommitted
Allow KernelLoaderResult to also store the Elf64_Phdr
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
1 parent 051bfc1 commit 16834d0

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub mod loader;
105105

106106
#[allow(clippy::undocumented_unsafe_blocks)]
107107
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
108-
mod loader_gen;
108+
pub mod loader_gen;
109109
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
110110
pub use loader_gen::*;
111111

src/loader/elf/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl KernelLoader for Elf {
249249
}
250250

251251
// Read in each section pointed to by the program headers.
252-
for phdr in phdrs {
252+
for phdr in &phdrs {
253253
if phdr.p_type != elf::PT_LOAD || phdr.p_filesz == 0 {
254254
if phdr.p_type == elf::PT_NOTE {
255255
// The PVH boot protocol currently requires that the kernel is loaded at
@@ -293,6 +293,7 @@ impl KernelLoader for Elf {
293293

294294
// elf image has no setup_header which is defined for bzImage
295295
loader_result.setup_header = None;
296+
loader_result.phdrs = phdrs;
296297

297298
Ok(loader_result)
298299
}

src/loader/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl From<pe::Error> for Error {
143143
/// This specifies where the kernel is loading and passes additional
144144
/// information for the rest of the boot process to be completed by
145145
/// the VMM.
146-
#[derive(Clone, Copy, Debug, Default, PartialEq)]
146+
#[derive(Clone, Debug, Default, PartialEq)]
147147
pub struct KernelLoaderResult {
148148
/// Address in the guest memory where the kernel image starts to be loaded.
149149
pub kernel_load: GuestAddress,
@@ -159,8 +159,12 @@ pub struct KernelLoaderResult {
159159
/// <https://xenbits.xen.org/docs/unstable/misc/pvh.html>
160160
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
161161
pub pvh_boot_cap: elf::PvhBootCapability,
162+
/// Program headers.
163+
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
164+
pub phdrs: Vec<crate::loader_gen::elf::Elf64_Phdr>,
162165
}
163166

167+
164168
/// Trait that specifies kernel image loading support.
165169
pub trait KernelLoader {
166170
/// How to load a specific kernel image format into the guest memory.

src/loader_gen/x86_64/elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct elf64_hdr {
7575
pub type Elf64_Ehdr = elf64_hdr;
7676

7777
#[repr(C)]
78-
#[derive(Debug, Default, Copy, Clone)]
78+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7979
pub struct elf64_phdr {
8080
pub p_type: Elf64_Word,
8181
pub p_flags: Elf64_Word,

0 commit comments

Comments
 (0)