From d127146846f4d6561e15000d1469b715dafdb627 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 2 Nov 2024 15:28:23 +0200 Subject: initial exec support --- src/uapi/proc.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'src/uapi') diff --git a/src/uapi/proc.c b/src/uapi/proc.c index 3b65a04..8d90687 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -108,46 +108,27 @@ SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp) return_args1(t, ERR_PERM); /* exec is only allowed if we own all our own resources */ - if (t->refcount) + if (t->refcount != 1) return_args1(t, ERR_INVAL); /* mark binary to be kept */ - struct mem_region *b = find_used_region(&t->uvmem.region, bin); + struct mem_region *b = find_addr_region(&t->uvmem.region, bin); if (!b) return_args1(t, ERR_ADDR); - set_bit(b->flags, MR_KEEP); - - struct mem_region *i = 0; + struct mem_region *i = NULL; if (interp) { /* mark interpreter to be kept */ - i = find_used_region(&t->uvmem.region, interp); + i = find_addr_region(&t->uvmem.region, interp); if (!i) - return_args1(t, ERR_INVAL); + return_args1(t, ERR_ADDR); - set_bit(i->flags, MR_KEEP); } - /* free everything except regions to be kept */ - clear_uvmem(t); - - /* restore to normal */ - clear_bit(b->flags, MR_KEEP); - if (interp) - clear_bit(b->flags, MR_KEEP); - - /* should hopefully never actually fail, but if it does, we don't really - * have any choice but to kill the thread. */ - if (prepare_proc(t, bin, interp)) { - /* this kills the thread */ - orphanize(t); - unorphanize(t); - /* should never be reached as we control the thread so we should - * be able to directly jump to pid 1 */ - assert(false); - } + if (prepare_proc(t, bin, interp)) + return_args1(t, ERR_INVAL); - return_args4(t, 0, t->tid, SYS_USER_SPAWNED, t->pid); + set_ret4(t, 0, t->tid, SYS_USER_SPAWNED, t->pid); } /** -- cgit v1.3