From a06dbb8a63d825ebb1ad65372ce1ce1f572891bc Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 21 Oct 2022 16:06:00 +0300 Subject: initial spawn implementation --- common/proc.c | 2 +- common/tcb.c | 5 +++++ common/uapi/proc.c | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/proc.c b/common/proc.c index b2caa54..6a3bedf 100644 --- a/common/proc.c +++ b/common/proc.c @@ -23,7 +23,7 @@ stat_t prepare_proc(struct tcb *t, vm_t bin, vm_t interp) alloc_stacks(t); set_thread(t); - set_return(entry); + set_return(t, entry); return OK; } diff --git a/common/tcb.c b/common/tcb.c index 8ff86ab..f618cd6 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -342,3 +342,8 @@ stat_t clone_proc_maps(struct tcb *r) return OK; } + +void set_return(struct tcb *t, vm_t v) +{ + t->exec = v; +} diff --git a/common/uapi/proc.c b/common/uapi/proc.c index d1d2bd7..a668246 100644 --- a/common/uapi/proc.c +++ b/common/uapi/proc.c @@ -91,7 +91,11 @@ SYSCALL_DEFINE2(exec)(sys_arg_t bin, sys_arg_t interp){ */ SYSCALL_DEFINE2(spawn)(sys_arg_t bin, sys_arg_t interp) { - /* @todo implement */ + struct tcb *t = create_proc(NULL); + if (!t) + return (struct sys_ret){ERR_OOMEM, 0, 0, 0, 0, 0}; + + return (struct sys_ret){prepare_proc(t, bin, interp), t->pid, 0, 0, 0, 0}; } /** -- cgit v1.3