elf: Add optional function ptr to load_elf() to parse ELF notes
This patch adds an optional function pointer, 'elf_note_fn', to load_elf() which causes load_elf() to additionally parse any ELF program headers of type PT_NOTE and check to see if the ELF Note is of the type specified by the 'translate_opaque' arg. If a matching ELF Note is found then the specfied function pointer is called to process the ELF note. Passing a NULL function pointer results in ELF Notes being skipped. The first consumer of this functionality is the PVHboot support which needs to read the XEN_ELFNOTE_PHYS32_ENTRY ELF Note while loading the uncompressed kernel binary in order to discover the boot entry address for the x86/HVM direct boot ABI. Signed-off-by: Liam Merwick <liam.merwick@oracle.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
d455ebc4f8
commit
4366e1db16
41 changed files with 113 additions and 70 deletions
|
|
@ -266,6 +266,7 @@ fail:
|
|||
}
|
||||
|
||||
static int glue(load_elf, SZ)(const char *name, int fd,
|
||||
uint64_t (*elf_note_fn)(void *, void *, bool),
|
||||
uint64_t (*translate_fn)(void *, uint64_t),
|
||||
void *translate_opaque,
|
||||
int must_swab, uint64_t *pentry,
|
||||
|
|
@ -498,6 +499,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
|
|||
data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_free(phdr);
|
||||
if (lowaddr)
|
||||
*lowaddr = (uint64_t)(elf_sword)low;
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ const char *load_elf_strerror(int error);
|
|||
|
||||
/** load_elf_ram_sym:
|
||||
* @filename: Path of ELF file
|
||||
* @elf_note_fn: optional function to parse ELF Note type
|
||||
* passed via @translate_opaque
|
||||
* @translate_fn: optional function to translate load addresses
|
||||
* @translate_opaque: opaque data passed to @translate_fn
|
||||
* @pentry: Populated with program entry point. Ignored if NULL.
|
||||
|
|
@ -125,6 +127,7 @@ typedef void (*symbol_fn_t)(const char *st_name, int st_info,
|
|||
uint64_t st_value, uint64_t st_size);
|
||||
|
||||
int load_elf_ram_sym(const char *filename,
|
||||
uint64_t (*elf_note_fn)(void *, void *, bool),
|
||||
uint64_t (*translate_fn)(void *, uint64_t),
|
||||
void *translate_opaque, uint64_t *pentry,
|
||||
uint64_t *lowaddr, uint64_t *highaddr, int big_endian,
|
||||
|
|
@ -136,6 +139,7 @@ int load_elf_ram_sym(const char *filename,
|
|||
* symbol callback function
|
||||
*/
|
||||
int load_elf_ram(const char *filename,
|
||||
uint64_t (*elf_note_fn)(void *, void *, bool),
|
||||
uint64_t (*translate_fn)(void *, uint64_t),
|
||||
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
|
||||
uint64_t *highaddr, int big_endian, int elf_machine,
|
||||
|
|
@ -146,6 +150,7 @@ int load_elf_ram(const char *filename,
|
|||
* Same as load_elf_ram(), but always loads the elf as ROM
|
||||
*/
|
||||
int load_elf_as(const char *filename,
|
||||
uint64_t (*elf_note_fn)(void *, void *, bool),
|
||||
uint64_t (*translate_fn)(void *, uint64_t),
|
||||
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
|
||||
uint64_t *highaddr, int big_endian, int elf_machine,
|
||||
|
|
@ -155,7 +160,9 @@ int load_elf_as(const char *filename,
|
|||
* Same as load_elf_as(), but doesn't allow the caller to specify an
|
||||
* AddressSpace.
|
||||
*/
|
||||
int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
|
||||
int load_elf(const char *filename,
|
||||
uint64_t (*elf_note_fn)(void *, void *, bool),
|
||||
uint64_t (*translate_fn)(void *, uint64_t),
|
||||
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
|
||||
uint64_t *highaddr, int big_endian, int elf_machine,
|
||||
int clear_lsb, int data_swab);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue