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
+3 -1
View File
@@ -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
+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;
}