Skip to content

Commit 334e311

Browse files
committed
pvh: Add test for PVH note parsing
Add a test case as part of the load_elf() tests to verify the functionality that parses the ELF Note header to look for a PVH entry point address if one is encoded. This is done by parsing a minimal ELF binary that encodes a predefined address of 0x1e1fe1f, and verifying that the same value is read. A dummy note header is also included in the binary to verify the ability to ignore irrelevant notes. The minimal ELF source code (elfnote.S): #define ELFNOTE_START(name, type, flags) \ .pushsection .note.name, flags, @note ; \ .balign 4 ; \ .long 2f - 1f /* namesz */ ; \ .long 4484f - 3f /* descsz */ ; \ .long type ; \ 1:.asciz #name ; \ 2:.balign 4 ; \ 3: #define ELFNOTE_END \ 4484:.balign 4 ; \ .popsection ; #define ELFNOTE(name, type, desc) \ ELFNOTE_START(name, type, "a") \ desc ; \ ELFNOTE_END #define XEN_ELFNOTE_PHYS32_ENTRY 18 #define NT_VERSION 1 ELFNOTE(dummy, NT_VERSION, .quad 0xcafecafe) ELFNOTE(PVHNote, XEN_ELFNOTE_PHYS32_ENTRY, .quad 0x1e1fe1f) .section ".text","ax" .global _start _start: Built with: $ gcc elfnote.S -s -nostdlib -o test_elfnote.bin Signed-off-by: Alejandro Jimenez <[email protected]>
1 parent cb60fdf commit 334e311

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/loader/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ mod test {
544544
v
545545
}
546546

547+
#[cfg(feature = "elf")]
548+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
549+
fn make_elfnote() -> Vec<u8> {
550+
include_bytes!("test_elfnote.bin").to_vec()
551+
}
552+
547553
#[allow(safe_packed_borrows)]
548554
#[allow(non_snake_case)]
549555
#[test]
@@ -664,6 +670,14 @@ mod test {
664670
Some(highmem_start_address)
665671
)
666672
);
673+
674+
let pvhnote_image = make_elfnote();
675+
loader_result = Elf::load(&gm, None, &mut Cursor::new(&pvhnote_image), None).unwrap();
676+
println!(
677+
"PVH entry point at address {:8x} \n",
678+
loader_result.pvh_entry_addr.unwrap().raw_value()
679+
);
680+
assert_eq!(loader_result.pvh_entry_addr.unwrap().raw_value(), 0x1e1fe1f);
667681
}
668682

669683
#[test]

src/loader/test_elfnote.bin

648 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)