3 * @author Lunaixsky (lunaxisky@qq.com)
8 * Define generic structure that described in Executable and Linking Format
11 * Define interface on manipulate such structure
13 * @copyright Copyright (c) 2024
17 #ifndef __LUNAIX_ELF32_H
18 #define __LUNAIX_ELF32_H
20 #include <lunaix/types.h>
35 // [0x7f, 'E', 'L', 'F']
36 #define ELFMAGIC_LE 0x464c457fU
42 #define DEFAULT_LOADER "usr/ld"
50 struct elf_ehdr eheader;
51 struct elf_phdr* pheaders;
54 #define declare_elf32(elf, elf_vfile) \
55 struct elf elf = { .elf_file = elf_vfile, .pheaders = (void*)0 }
58 elf_check_exec(const struct elf* elf, int type);
61 elf_check_arch(const struct elf* elf);
64 elf_open(struct elf* elf, const char* path);
67 elf_openat(struct elf* elf, void* elf_vfile);
70 elf_static_linked(const struct elf* elf);
73 elf_close(struct elf* elf);
76 * @brief Try to find the PT_INTERP section. If found, copy it's content to
79 * @param elf Opened elf32 descriptor
81 * @param len size of path_out buffer
85 elf_find_loader(const struct elf* elf, char* path_out, size_t len);
88 elf_read_ehdr(struct elf* elf);
91 elf_read_phdr(struct elf* elf);
94 * @brief Estimate how much memeory will be acquired if we load all loadable
101 elf_loadable_memsz(const struct elf* elf);
103 #define SIZE_EHDR sizeof(struct elf_ehdr)
104 #define SIZE_PHDR sizeof(struct elf_phdr)
106 #endif /* __LUNAIX_ELF32_H */