From 3847b0a54e69191fba424a2e26ab2436f0882d4c Mon Sep 17 00:00:00 2001 From: Yuki Okumura Date: Thu, 26 Oct 2023 22:16:57 +0900 Subject: [PATCH] wasmlinux: Add newtask feature --- arch/lkl/kernel/syscalls.c | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/lkl/kernel/syscalls.c b/arch/lkl/kernel/syscalls.c index aee30189f1e30e..c53e9c005c7c48 100644 --- a/arch/lkl/kernel/syscalls.c +++ b/arch/lkl/kernel/syscalls.c @@ -187,6 +187,60 @@ long lkl_syscall(long no, int nargs, long *params) return ret; } +// #ifdef __wasm__ + +static long +wasmlinux_newtask(long clone_flags){ + struct task_struct *task; + struct task_struct *newtask; + int ret; + pid_t pid; + + task = lkl_ops->tls_get(task_key); + + ret = lkl_cpu_get(); + if (ret < 0) + return 0; + + switch_to_host_task(task); + + pid = kernel_thread(host_task_stub, NULL, clone_flags); + if (pid < 0) + return 0; + + rcu_read_lock(); + newtask = find_task_by_pid_ns(pid, &init_pid_ns); + rcu_read_unlock(); + + host_task_id++; + + snprintf(task->comm, sizeof(task->comm), "host%d", host_task_id); + + switch_to_host_task(newtask); + + lkl_cpu_put(); + + return (long)newtask; +} + +long wasmlinux_create_process_ctx(void){ + const long FLAGS = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD); + + return wasmlinux_newtask(FLAGS); +} + +long wasmlinux_create_thread_ctx(void){ + const long FLAGS = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_THREAD | CLONE_SIGHAND | SIGCHLD); + + return wasmlinux_newtask(FLAGS); +} + +void wasmlinux_set_ctx(long ctx){ + lkl_ops->tls_set(task_key, (void*)ctx); +} + +// #endif + static struct task_struct *idle_host_task; /* called from idle, don't failed, don't block */