diff options
Diffstat (limited to 'website-kernel/fs/binfmt_elf.c')
| -rw-r--r-- | website-kernel/fs/binfmt_elf.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/website-kernel/fs/binfmt_elf.c b/website-kernel/fs/binfmt_elf.c index edf1781..f8073ae 100644 --- a/website-kernel/fs/binfmt_elf.c +++ b/website-kernel/fs/binfmt_elf.c @@ -1,5 +1,6 @@ #include <fs/elf.h> #include <sys.h> +#include <log.h> #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -34,10 +35,6 @@ int elf_chk_header(struct elf_header *header) { return 0; } - if (header->e_phoff != 0) { - return 0; // Not PIE - } - if (header->e_phentsize != sizeof(struct elf_program_header)) { return 0; } @@ -66,6 +63,7 @@ void elf_exec(void *executable) { struct elf_header *hdr = executable; if (!elf_chk_header(hdr)) { + printk("Magic bytes invalid, returning...\n"); return; } @@ -88,11 +86,15 @@ void elf_exec(void *executable) { continue; } - void *dst = (void *)(bias + (uintptr_t)base); + void *dst = (void *)(bias + phdrs[i].p_vaddr); + printk("section at file 0x%x will be loaded at 0x%x (v_addr requested: 0x%x)\n", + (uint8_t *)executable + phdrs[i].p_offset, dst, phdrs[i].p_vaddr); memcpy((uint8_t *)executable + phdrs[i].p_offset, dst, phdrs[i].p_filesz); memzero((uint8_t *)dst + phdrs[i].p_filesz, phdrs[i].p_memsz - phdrs[i].p_filesz); } + printk("Mounted program and will jump to entrypoint 0x%x (e_entry: 0x%x)\n", (uintptr_t)(hdr->e_entry + bias), (uintptr_t)hdr->e_entry); + __userspace_invoke((elf_entry)(hdr->e_entry + bias)); kfree(base); |
