From bdb25024a3fe0c8630fd68d9ba618df595effa36 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 20 Jul 2022 13:50:38 +0200 Subject: syscall/execbuf: EXECBUF_JMP --- src/user/lib/elfload.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/user/lib/elfload.c') diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c index c490325..565dfa2 100644 --- a/src/user/lib/elfload.c +++ b/src/user/lib/elfload.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -65,12 +66,13 @@ void elf_exec(void *base) { struct Elf64_Ehdr *ehdr = base; void *exebase; if (!valid_ehdr(ehdr)) return; + size_t spread = elf_spread(base); switch (ehdr->e_type) { case ET_EXEC: exebase = (void*)0; break; case ET_DYN: - exebase = _syscall_memflag((void*)0x1000, elf_spread(base), MEMFLAG_FINDFREE); + exebase = _syscall_memflag((void*)0x1000, spread, MEMFLAG_FINDFREE); if (!exebase) { printf("elf: out of memory\n"); _syscall_exit(1); @@ -83,7 +85,12 @@ void elf_exec(void *base) { if (!load_phdr(base, exebase, phi)) return; } - // TODO free memory - ((void(*)())exebase + ehdr->e_entry)(); - _syscall_exit(1); + + uint64_t buf[] = { + // TODO free lower memory + //EXECBUF_SYSCALL, _SYSCALL_MEMFLAG, exebase + spread, ~0 - 0xF0000, 0, 0, // free upper memory + EXECBUF_JMP, (uintptr_t)exebase + ehdr->e_entry, + }; + _syscall_execbuf(buf, sizeof buf); + printf("elf: execbuf failed?"); } -- cgit v1.2.3