Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f94a10a authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "elf: Add elf headers helpers support"

parents cadcd886 5dd4bc7f
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -45,6 +45,39 @@ extern Elf64_Dyn _DYNAMIC [];

#endif

/* Generic helpers for ELF use */
/* Return first section header */
static inline struct elf_shdr *elf_sheader(struct elfhdr *hdr)
{
	return (struct elf_shdr *)((size_t)hdr + (size_t)hdr->e_shoff);
}

/* Return idx section header */
static inline struct elf_shdr *elf_section(struct elfhdr *hdr, int idx)
{
	return &elf_sheader(hdr)[idx];
}

/* Return first program header */
static inline struct elf_phdr *elf_pheader(struct elfhdr *hdr)
{
	return (struct elf_phdr *)((size_t)hdr + (size_t)hdr->e_phoff);
}

/* Return idx program header */
static inline struct elf_phdr *elf_program(struct elfhdr *hdr, int idx)
{
	return &elf_pheader(hdr)[idx];
}

/* Retunr section's string table header */
static inline char *elf_str_table(struct elfhdr *hdr)
{
	if (hdr->e_shstrndx == SHN_UNDEF)
		return NULL;
	return (char *)hdr + elf_section(hdr, hdr->e_shstrndx)->sh_offset;
}

/* Optional callbacks to write extra ELF notes. */
struct file;
struct coredump_params;