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;
28 // [0x7f, 'E', 'L', 'F']
29 #define ELFMAGIC 0x464c457fU
39 #define DEFAULT_LOADER "usr/ld"
45 elf32_hlf_t e_machine;
46 elf32_wrd_t e_version;
52 elf32_hlf_t e_phentsize;
54 elf32_hlf_t e_shentsize;
56 elf32_hlf_t e_shstrndx;
74 struct elf32_ehdr eheader;
75 struct elf32_phdr* pheaders;
78 #define declare_elf32(elf, elf_vfile) \
79 struct elf32 elf = { .elf_file = elf_vfile, .pheaders = (void*)0 }
82 elf32_check_exec(const struct elf32* elf, int type);
85 elf32_check_arch(const struct elf32* elf);
88 elf32_open(struct elf32* elf, const char* path);
91 elf32_openat(struct elf32* elf, const void* elf_vfile);
94 elf32_static_linked(const struct elf32* elf);
97 elf32_close(struct elf32* elf);
100 * @brief Try to find the PT_INTERP section. If found, copy it's content to
103 * @param elf Opened elf32 descriptor
105 * @param len size of path_out buffer
109 elf32_find_loader(const struct elf32* elf, char* path_out, size_t len);
112 elf32_read_ehdr(struct elf32* elf);
115 elf32_read_phdr(struct elf32* elf);
118 * @brief Estimate how much memeory will be acquired if we load all loadable
125 elf32_loadable_memsz(const struct elf32* elf);
127 #define SIZE_EHDR sizeof(struct elf32_ehdr)
128 #define SIZE_PHDR sizeof(struct elf32_phdr)
130 #endif /* __LUNAIX_ELF32_H */