1 /* 2 * Copyright (C) 2016 Citrix Systems R&D Ltd. 3 */ 4 5 #ifndef __XEN_LIVEPATCH_ELF_H__ 6 #define __XEN_LIVEPATCH_ELF_H__ 7 8 #include <xen/types.h> 9 #include <xen/elfstructs.h> 10 11 /* The following describes an Elf file as consumed by Xen Live Patch. */ 12 struct livepatch_elf_sec { 13 const Elf_Shdr *sec; /* Hooked up in elf_resolve_sections.*/ 14 const char *name; /* Human readable name hooked in 15 elf_resolve_section_names. */ 16 const void *data; /* Pointer to the section (done by 17 elf_resolve_sections). */ 18 void *load_addr; /* A pointer to the allocated destination. 19 Done by load_payload_data. */ 20 }; 21 22 struct livepatch_elf_sym { 23 const Elf_Sym *sym; 24 const char *name; 25 }; 26 27 struct livepatch_elf { 28 const char *name; /* Pointer to payload->name. */ 29 size_t len; /* Length of the ELF file. */ 30 const Elf_Ehdr *hdr; /* ELF file. */ 31 struct livepatch_elf_sec *sec; /* Array of sections, allocated by us. */ 32 struct livepatch_elf_sym *sym; /* Array of symbols , allocated by us. */ 33 unsigned int nsym; 34 const struct livepatch_elf_sec *symtab;/* Pointer to .symtab section - aka to 35 sec[symtab_idx]. */ 36 const struct livepatch_elf_sec *strtab;/* Pointer to .strtab section. */ 37 unsigned int symtab_idx; 38 }; 39 40 const struct livepatch_elf_sec * 41 livepatch_elf_sec_by_name(const struct livepatch_elf *elf, 42 const char *name); 43 int livepatch_elf_load(struct livepatch_elf *elf, const void *data); 44 void livepatch_elf_free(struct livepatch_elf *elf); 45 46 int livepatch_elf_resolve_symbols(struct livepatch_elf *elf); 47 int livepatch_elf_perform_relocs(struct livepatch_elf *elf); 48 livepatch_elf_ignore_section(const Elf_Shdr * sec)49static inline bool livepatch_elf_ignore_section(const Elf_Shdr *sec) 50 { 51 return !(sec->sh_flags & SHF_ALLOC) || sec->sh_size == 0; 52 } 53 #endif /* __XEN_LIVEPATCH_ELF_H__ */ 54 55 /* 56 * Local variables: 57 * mode: C 58 * c-file-style: "BSD" 59 * c-basic-offset: 4 60 * tab-width: 4 61 * indent-tabs-mode: nil 62 * End: 63 */ 64