diff options
author | Marvin Borner | 2020-08-15 13:17:18 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-15 13:17:18 +0200 |
commit | cb47a048d233e1f2433c815a06d53d8087e19dad (patch) | |
tree | b7f5984cb97094fa2b7f7825e1ebb4ff89f4b0f0 /kernel/features/load.c | |
parent | c047e2e981a25e15d3a7e141e532004300559e48 (diff) |
Some elf things
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r-- | kernel/features/load.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c index fd9883a..4468778 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -33,14 +33,22 @@ void elf_load(char *path, struct proc *proc) char *data = read_file(path); struct elf_header *h = (struct elf_header *)data; - assert(elf_verify(h)); - - printf("%d", h->type); - switch (h->type) { - case ET_EXEC: + if (!elf_verify(h)) return; - case ET_REL: + + if (h->type != ET_REL) return; + + struct elf_program_header *phdrs = (struct elf_program_header *)((u32 *)h + h->phoff); + + printf("%d", h->phnum); + for (int i = 0; i < h->phnum; i++) { + struct elf_program_header *phdr = &phdrs[i]; + printf("%d\n", phdr->type); + if (phdr->type != PT_LOAD) + continue; + memcpy((void *)phdr->vaddr, h + phdr->offset, phdr->filesz); + memset((void *)(phdr->vaddr + phdr->filesz), phdr->memsz - phdr->filesz, 0); } loop(); |