summaryrefslogtreecommitdiffstats
path: root/include/elf.h
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-09-12 07:53:05 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-09-12 07:53:05 +0200
commit9b1102c02bfd39352e0d2995c733edb7be3b0601 (patch)
tree3f089c640bab75c020b69f5dcf44d744a0a7f2e4 /include/elf.h
parentf48a1596f4e911d4516b986e4778f18321b39b48 (diff)
parenta10dbfc4175867c0d15f02b7f244837c5d41478e (diff)
downloadbarebox-9b1102c02bfd39352e0d2995c733edb7be3b0601.tar.gz
barebox-9b1102c02bfd39352e0d2995c733edb7be3b0601.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'include/elf.h')
-rw-r--r--include/elf.h29
1 files changed, 28 insertions, 1 deletions
diff --git a/include/elf.h b/include/elf.h
index 92c8d9c127..633f4992dd 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -400,11 +400,38 @@ static inline void arch_write_notes(struct file *file) { }
struct elf_image {
struct list_head list;
- unsigned long entry;
+ u8 class;
+ u64 entry;
void *buf;
};
struct elf_image *elf_load_image(void *buf);
void elf_release_image(struct elf_image *elf);
+#define ELF_GET_FIELD(__s, __field, __type) \
+static inline __type elf_##__s##_##__field(struct elf_image *elf, void *arg) { \
+ if (elf->class == ELFCLASS32) \
+ return (__type) ((struct elf32_##__s *) arg)->__field; \
+ else \
+ return (__type) ((struct elf64_##__s *) arg)->__field; \
+}
+
+ELF_GET_FIELD(hdr, e_entry, u64)
+ELF_GET_FIELD(hdr, e_phnum, u16)
+ELF_GET_FIELD(hdr, e_phoff, u64)
+ELF_GET_FIELD(hdr, e_type, u16)
+ELF_GET_FIELD(phdr, p_paddr, u64)
+ELF_GET_FIELD(phdr, p_filesz, u64)
+ELF_GET_FIELD(phdr, p_memsz, u64)
+ELF_GET_FIELD(phdr, p_type, u32)
+ELF_GET_FIELD(phdr, p_offset, u64)
+
+static inline unsigned long elf_size_of_phdr(struct elf_image *elf)
+{
+ if (elf->class == ELFCLASS32)
+ return sizeof(Elf32_Phdr);
+ else
+ return sizeof(Elf64_Phdr);
+}
+
#endif /* _LINUX_ELF_H */