From 0189cc9d771e5911b07fbf91ca18da3a338f8d30 Mon Sep 17 00:00:00 2001 From: Nathan Lee Date: Sat, 3 Oct 2026 21:37:57 -0500 Subject: add first userspace invocation --- website-kernel/fs/binfmt_elf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'website-kernel/fs/binfmt_elf.c') 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 #include +#include #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); -- cgit v1.2.3