diff --git a/src/arch/x86_64/syscall.asm b/src/arch/x86_64/syscall.asm index 5a5f1d84..e938c615 100644 --- a/src/arch/x86_64/syscall.asm +++ b/src/arch/x86_64/syscall.asm @@ -45,7 +45,8 @@ extern syscall_fchmod extern syscall_linkat extern syscall_recvmsg extern syscall_futex -func_count equ 44 +extern syscall_newthread +func_count equ 45 func_table: @@ -93,6 +94,7 @@ func_table: dq syscall_linkat dq syscall_recvmsg dq syscall_futex + dq syscall_newthread section .text global asm_syscall_entry diff --git a/src/sys/syscalls/newthread.c b/src/sys/syscalls/newthread.c new file mode 100644 index 00000000..0814b715 --- /dev/null +++ b/src/sys/syscalls/newthread.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +syscallret syscall_newthread(void* nip, void* stack){ + syscallret retv; + retv.ret = -1; + + if(env_isset("nomultithread")){ + retv.errno = ENOSYS; + return retv; + } + + thread_t* thread = arch_getcls()->thread; + proc_t* proc = thread->proc; + + thread_t* new = sched_newuthread(nip, THREAD_DEFAULT_KSTACK_SIZE, stack, proc, false, THREAD_PRIORITY_USER); + + if(!new){ + retv.errno = ENOMEM; + return retv; + } + + new->ctx = thread->ctx; + + sched_queuethread(new); + + retv.errno = 0; + retv.ret = new->tid; + + return retv; + +}