acadia/zion/syscall/thread.cpp

44 lines
1.3 KiB
C++
Raw Normal View History

#include "syscall/thread.h"
#include "capability/capability.h"
2023-06-26 15:01:55 -07:00
#include "debug/debug.h"
#include "scheduler/scheduler.h"
2023-06-22 02:17:50 -07:00
glcr::ErrorCode ThreadCreate(ZThreadCreateReq* req) {
auto& curr_proc = gScheduler->CurrentProcess();
auto cap = curr_proc.GetCapability(req->proc_cap);
RET_ERR(ValidateCapability<Process>(cap, ZC_PROC_SPAWN_THREAD));
auto parent_proc = cap->obj<Process>();
auto thread = parent_proc->CreateThread();
2023-06-22 02:17:50 -07:00
*req->thread_cap = curr_proc.AddNewCapability(thread, ZC_WRITE | ZC_READ);
2023-06-21 18:28:54 -07:00
return glcr::OK;
}
2023-06-22 02:17:50 -07:00
glcr::ErrorCode ThreadStart(ZThreadStartReq* req) {
auto& curr_proc = gScheduler->CurrentProcess();
auto cap = curr_proc.GetCapability(req->thread_cap);
RET_ERR(ValidateCapability<Thread>(cap, ZC_WRITE));
auto thread = cap->obj<Thread>();
// FIXME: validate entry point is in user space.
thread->Start(req->entry, req->arg1, req->arg2);
2023-06-21 18:28:54 -07:00
return glcr::OK;
}
2023-06-22 02:17:50 -07:00
glcr::ErrorCode ThreadExit(ZThreadExitReq*) {
auto curr_thread = gScheduler->CurrentThread();
curr_thread->Exit();
panic("Returned from thread exit");
2023-06-26 15:01:55 -07:00
UNREACHABLE
}
2023-06-22 02:17:50 -07:00
glcr::ErrorCode ThreadWait(ZThreadWaitReq* req) {
auto& curr_proc = gScheduler->CurrentProcess();
auto cap = curr_proc.GetCapability(req->thread_cap);
RET_ERR(ValidateCapability<Thread>(cap, ZC_READ));
auto thread = cap->obj<Thread>();
thread->Wait();
return glcr::OK;
}