1 #ifndef __LUNAIX_ELF32_H
2 #define __LUNAIX_ELF32_H
4 #include <lunaix/types.h>
6 typedef unsigned int elf32_ptr_t;
7 typedef unsigned short elf32_hlf_t;
8 typedef unsigned int elf32_off_t;
9 typedef unsigned int elf32_swd_t;
10 typedef unsigned int elf32_wrd_t;
27 // [0x7f, 'E', 'L', 'F']
28 #define ELFMAGIC 0x464c457fU
38 #define DEFAULT_LOADER "usr/ld"
44 elf32_hlf_t e_machine;
45 elf32_wrd_t e_version;
51 elf32_hlf_t e_phentsize;
53 elf32_hlf_t e_shentsize;
55 elf32_hlf_t e_shstrndx;
73 struct elf32_ehdr eheader;
74 struct elf32_phdr* pheaders;
77 #define declare_elf32(elf, elf_vfile) \
78 struct elf32 elf = { .elf_file = elf_vfile, .pheaders = (void*)0 }
81 elf32_open(struct elf32* elf, const char* path);
84 elf32_openat(struct elf32* elf, void* elf_vfile);
87 elf32_static_linked(const struct elf32* elf);
90 elf32_close(struct elf32* elf);
93 * @brief Try to find the PT_INTERP section. If found, copy it's content to
96 * @param elf Opened elf32 descriptor
98 * @param len size of path_out buffer
102 elf32_find_loader(const struct elf32* elf, char* path_out, size_t len);
105 elf32_read_ehdr(struct elf32* elf);
108 elf32_read_phdr(struct elf32* elf);
111 * @brief Estimate how much memeory will be acquired if we load all loadable
118 elf32_loadable_memsz(const struct elf32* elf);
120 #define SIZE_EHDR sizeof(struct elf32_ehdr)
121 #define SIZE_PHDR sizeof(struct elf32_phdr)
123 #endif /* __LUNAIX_ELF32_H */