Skip to content

Commit

Permalink
pvh: Add test for PVH note parsing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aljimenezb committed Mar 5, 2020
1 parent 163c35c commit c351804
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ mod test {
v
}

#[cfg(feature = "elf")]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn make_elfnote() -> Vec<u8> {
include_bytes!("test_elfnote.bin").to_vec()
}

#[allow(safe_packed_borrows)]
#[allow(non_snake_case)]
#[test]
Expand Down Expand Up @@ -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]
Expand Down
Binary file added src/loader/test_elfnote.bin
Binary file not shown.

0 comments on commit c351804

Please sign in to comment.