From 21efbba39340300a7ba9d5f4f94017f5ff956833 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 2 Nov 2024 16:02:41 +0200 Subject: intial working sys_spawn --- src/uapi/proc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/uapi/proc.c') diff --git a/src/uapi/proc.c b/src/uapi/proc.c index 8d90687..51a1252 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -128,7 +128,11 @@ SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp) if (prepare_proc(t, bin, interp)) return_args1(t, ERR_INVAL); + set_thread(t); + set_return(t, t->callback); set_ret4(t, 0, t->tid, SYS_USER_SPAWNED, t->pid); + + flush_tlb_full(); } /** @@ -150,16 +154,24 @@ SYSCALL_DEFINE2(spawn)(struct tcb *t, sys_arg_t bin, sys_arg_t interp) if (!n) return_args1(t, ERR_OOMEM); - /** @todo copy over bin and interp into new process, this is not enough */ n->notify_id = c->notify_id; - stat_t ret = OK; - if ((ret = prepare_proc(n, bin, interp))) { + if (prepare_proc(n, bin, interp)) { /* this kills the thread */ orphanize(t); unorphanize(t); - return_args1(t, ret); + return_args1(t, ERR_INVAL); } + /** @todo should permissions be transferred? Probably, not but now there + * is a slightly annoying asymmetry between fork+exec vs spawn... */ + + /* temporarily switch to new thread to manipulate stack */ + use_tcb(n); + set_thread(n); + set_return(n, n->callback); + set_ret4(n, 0, n->tid, SYS_USER_SPAWNED, n->pid); + use_tcb(t); + return_args1(t, n->pid); } -- cgit v1.3