summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-07-26 20:26:58 -0500
committerNathan Lee <me@nwlee.tech>2026-07-26 20:26:58 -0500
commitdcf065f3438b53b9bfd9628810040f94619d8c18 (patch)
tree62ab1212483f87227001b0ec84532990ba4d12dd /kernel
parente98a69fd70533aa9f9b2bd1367e1ec158579d4c0 (diff)
feat: update ELF parser
- added more header validity checks - create section name retrieval
Diffstat (limited to 'kernel')
-rw-r--r--kernel/elf.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/kernel/elf.c b/kernel/elf.c
index f1ceb2d..69c4128 100644
--- a/kernel/elf.c
+++ b/kernel/elf.c
@@ -8,5 +8,34 @@ int elf_chk_header(struct elf_header *header) {
return -1;
}
+ if (header->e_ident[EI_CLASS] != ELFHOSTCLASS) {
+ return -1;
+ }
+
+ if (header->e_ident[EI_DATA] != ELFHOSTDATA) {
+ return -1;
+ }
+
+ if (header->e_ident[EI_VERSION] != EV_CURRENT) {
+ return -1;
+ }
+
return 0;
}
+
+struct elf_section_header *elf_get_section(struct elf_header *hdr, void *data, uint32_t index) {
+ uint8_t *base = (uint8_t *)data;
+
+ if (index >= hdr->e_shnum) {
+ return 0;
+ }
+
+ return (struct elf_section_header *)(base
+ + hdr->e_shoff
+ + index * hdr->e_shentsize);
+}
+
+char *elf_get_section_name(struct elf_header *hdr, struct elf_section_header *section, void *data) {
+ struct elf_section_header *shstrtab = elf_get_section(hdr, data, hdr->e_shstrndx);
+ return (char *)((uintptr_t)section->sh_name + (uintptr_t)shstrtab->sh_offset + (uintptr_t)data);
+}