From 227374239ce397eb6b471bd8a058538ffc326756 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 2 Nov 2024 19:28:42 +0200 Subject: make it more obvious dynamic elf isn't supported + also cleans up a few warnings I've been annoyed by --- src/elf.c | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'src/elf.c') diff --git a/src/elf.c b/src/elf.c index d101d1e..d590109 100644 --- a/src/elf.c +++ b/src/elf.c @@ -162,24 +162,17 @@ static stat_t __map_exec(struct tcb *t, return OK; } -/** - * Map ELF dynamic object. - * - * @param t Thread space to work in. - * @param bin Address of binary to map. - * @param ei_c ELF identity class. - * @param phstart Program header start. - * @param phnum Number of program header entries. - * @param phsize Size of page header entry. - * @return Base of dynamic mapping. - */ -static vm_t __map_dyn(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, - size_t phnum, size_t phsize) +static vm_t __prepare_exec(struct tcb *t, uint8_t ei_c, vm_t elf) { - /** \todo this path should only be taken when no PT_INTERP is defined, as - * making sure ld is loaded should be done in userspace. Maybe a bit - * hacky, I know.*/ - return 0; + vm_t phstart = ptradd(elf, elf_header_prop(ei_c, elf, e_phoff)); + size_t phnum = elf_header_prop(ei_c, elf, e_phnum); + size_t phsize = elf_header_prop(ei_c, elf, e_phentsize); + + vm_t entry = elf_header_prop(ei_c, elf, e_entry); + if (__map_exec(t, elf, ei_c, phstart, phnum, phsize)) + return 0; + + return entry; } /** @@ -195,24 +188,19 @@ static vm_t __map_dyn(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, */ static vm_t __prepare_proc(struct tcb *t, uint8_t ei_c, vm_t elf, vm_t interp) { + UNUSED(interp); + short e_type = elf_header_prop(ei_c, elf, e_type); - if (e_type != ET_DYN && e_type != ET_EXEC) - return 0; - vm_t phstart = ptradd(elf, elf_header_prop(ei_c, elf, e_phoff)); - size_t phnum = elf_header_prop(ei_c, elf, e_phnum); - size_t phsize = elf_header_prop(ei_c, elf, e_phentsize); + if (e_type == ET_EXEC) + return __prepare_exec(t, ei_c, elf); - vm_t entry = elf_header_prop(ei_c, elf, e_entry); - if (e_type == ET_EXEC) { - if (__map_exec(t, elf, ei_c, phstart, phnum, phsize)) - return 0; - - return entry; - } else { - vm_t o = __map_dyn(t, elf, ei_c, phstart, phnum, phsize); - return o + entry; + if (e_type == ET_DYN) { + bug("dynamic elf not currently implemented\n"); + return 0; } + + return 0; } /* sets up all memory regions etc, returns the entry address */ -- cgit v1.3