syscalls: new thread syscall

This commit is contained in:
Matheus
2022-12-31 18:17:20 -03:00
parent 2a5fdd86f5
commit bbcda47dcd
2 changed files with 37 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
#include <kernel/syscalls.h>
#include <kernel/sched.h>
#include <kernel/env.h>
#include <arch/cls.h>
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;
}