2023-06-20 14:10:28 -07:00
|
|
|
#include "syscall/thread.h"
|
|
|
|
|
2023-06-20 15:50:49 -07:00
|
|
|
#include "capability/capability.h"
|
2023-06-20 14:10:28 -07:00
|
|
|
#include "scheduler/scheduler.h"
|
|
|
|
|
|
|
|
z_err_t ThreadCreate(ZThreadCreateReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
auto cap = curr_proc.GetCapability(req->proc_cap);
|
2023-06-20 15:50:49 -07:00
|
|
|
RET_ERR(ValidateCapability<Process>(cap, ZC_PROC_SPAWN_THREAD));
|
2023-06-20 14:10:28 -07:00
|
|
|
|
|
|
|
auto parent_proc = cap->obj<Process>();
|
|
|
|
auto thread = parent_proc->CreateThread();
|
|
|
|
*req->thread_cap = curr_proc.AddNewCapability(thread, ZC_WRITE);
|
|
|
|
return Z_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
z_err_t ThreadStart(ZThreadStartReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
auto cap = curr_proc.GetCapability(req->thread_cap);
|
2023-06-20 15:50:49 -07:00
|
|
|
RET_ERR(ValidateCapability<Thread>(cap, ZC_WRITE));
|
2023-06-20 14:10:28 -07:00
|
|
|
|
|
|
|
auto thread = cap->obj<Thread>();
|
|
|
|
// FIXME: validate entry point is in user space.
|
|
|
|
thread->Start(req->entry, req->arg1, req->arg2);
|
|
|
|
return Z_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
z_err_t ThreadExit(ZThreadExitReq*) {
|
|
|
|
auto curr_thread = gScheduler->CurrentThread();
|
|
|
|
curr_thread->Exit();
|
|
|
|
panic("Returned from thread exit");
|
|
|
|
}
|