summaryrefslogtreecommitdiff
path: root/src/user/lib/elfload.c
diff options
context:
space:
mode:
authordzwdz2022-07-20 13:50:38 +0200
committerdzwdz2022-07-20 13:50:38 +0200
commitbdb25024a3fe0c8630fd68d9ba618df595effa36 (patch)
treecbb8e994ee1b642f456c833da65b1c94c3ef7ae8 /src/user/lib/elfload.c
parent96f41ff64d8113307f1b60d2eb6852423db34d14 (diff)
syscall/execbuf: EXECBUF_JMP
Diffstat (limited to 'src/user/lib/elfload.c')
-rw-r--r--src/user/lib/elfload.c15
1 files changed, 11 insertions, 4 deletions
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 <shared/execbuf.h>
#include <shared/flags.h>
#include <shared/syscalls.h>
#include <user/lib/elf.h>
@@ -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?");
}