From 26cfe46dc75ced675b38a538cc59f98450eadce7 Mon Sep 17 00:00:00 2001 From: Alejandro Jimenez Date: Thu, 27 Feb 2020 23:14:59 -0500 Subject: [PATCH] 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. 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 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 --- src/loader/mod.rs | 14 ++++++++++++++ src/loader/test_elfnote.bin | Bin 0 -> 544 bytes 2 files changed, 14 insertions(+) create mode 100755 src/loader/test_elfnote.bin diff --git a/src/loader/mod.rs b/src/loader/mod.rs index 818ff0ae..d0750ca1 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -544,6 +544,12 @@ mod test { v } + #[cfg(feature = "elf")] + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + fn make_elfnote() -> Vec { + include_bytes!("test_elfnote.bin").to_vec() + } + #[allow(safe_packed_borrows)] #[allow(non_snake_case)] #[test] @@ -664,6 +670,14 @@ mod test { Some(highmem_start_address) ) ); + + let pvhnote_image = make_elfnote(); + loader_result = Elf::load(&gm, None, &mut Cursor::new(&pvhnote_image), None).unwrap(); + println!( + "PVH entry point at address {:8x} \n", + loader_result.pvh_entry_addr.unwrap().raw_value() + ); + assert_eq!(loader_result.pvh_entry_addr.unwrap().raw_value(), 0x1e1fe1f); } #[test] diff --git a/src/loader/test_elfnote.bin b/src/loader/test_elfnote.bin new file mode 100755 index 0000000000000000000000000000000000000000..98a076446bc77987aabc068140caad157679310e GIT binary patch literal 544 zcmb<-^>JfjWMqH=CI&kO5bpzn16T+`GB7A0lmKNc7?^-03j;G)EelvBjDYEY&>x_} zFdAqQSOla8gg1bBAld=Ug3%Bj15^~E7Nmd!iiLo5K$wSLen~2W{J)1_*MZCv0b*t# zcJ~WqU=Lhdr6Q#5vncAxYx!qW-?7|rSjwPRoKaj-RFas)pqB^KtOqj$!b{I9)k`YP z%t_JBOaYogIp78w!4AYsP@`b}gZWzq%?gkokbxwSgRK7yG(^ro6{#RA2C~uhg8~K= R9_RoTA3A6fNYM