[zion] Move thread syscalls to the new format.
This commit is contained in:
parent
c6dd0bbb0f
commit
f755cd38fe
9 changed files with 65 additions and 65 deletions
|
|
@ -14,15 +14,9 @@
|
|||
#include "scheduler/process_manager.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
#include "syscall/process.h"
|
||||
#include "syscall/thread.h"
|
||||
#include "usr/zcall_internal.h"
|
||||
|
||||
#define RET_IF_NULL(expr) \
|
||||
{ \
|
||||
if (!expr) { \
|
||||
return Z_ERR_CAP_TYPE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define EFER 0xC0000080
|
||||
#define STAR 0xC0000081
|
||||
#define LSTAR 0xC0000082
|
||||
|
|
@ -66,30 +60,6 @@ z_err_t ValidateCap(const RefPtr<Capability>& cap, uint64_t permissions) {
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
z_err_t ThreadCreate(ZThreadCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->proc_cap);
|
||||
RET_ERR(ValidateCap(cap, ZC_PROC_SPAWN_THREAD));
|
||||
|
||||
auto parent_proc = cap->obj<Process>();
|
||||
RET_IF_NULL(parent_proc);
|
||||
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);
|
||||
RET_ERR(ValidateCap(cap, ZC_WRITE));
|
||||
|
||||
auto thread = cap->obj<Thread>();
|
||||
RET_IF_NULL(thread);
|
||||
// FIXME: validate entry point is in user space.
|
||||
thread->Start(req->entry, req->arg1, req->arg2);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
z_err_t AddressSpaceMap(ZAddressSpaceMapReq* req, ZAddressSpaceMapResp* resp) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto vmas_cap = curr_proc.GetCapability(req->vmas_cap);
|
||||
|
|
@ -248,14 +218,10 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
|||
// syscall/process.h
|
||||
CASE(ProcessExit);
|
||||
CASE(ProcessSpawn);
|
||||
// syscall/thread.h
|
||||
CASE(ThreadCreate);
|
||||
case Z_THREAD_START:
|
||||
return ThreadStart(reinterpret_cast<ZThreadStartReq*>(req));
|
||||
case Z_THREAD_EXIT:
|
||||
thread->Exit();
|
||||
panic("Returned from thread exit");
|
||||
break;
|
||||
|
||||
CASE(ThreadStart);
|
||||
CASE(ThreadExit);
|
||||
case Z_ADDRESS_SPACE_MAP:
|
||||
return AddressSpaceMap(reinterpret_cast<ZAddressSpaceMapReq*>(req),
|
||||
reinterpret_cast<ZAddressSpaceMapResp*>(resp));
|
||||
|
|
|
|||
|
|
@ -7,3 +7,10 @@ void InitSyscall();
|
|||
|
||||
// FIXME: This probably belongs in capability.h
|
||||
z_err_t ValidateCap(const RefPtr<Capability>& cap, uint64_t permissions);
|
||||
|
||||
#define RET_IF_NULL(expr) \
|
||||
{ \
|
||||
if (!expr) { \
|
||||
return Z_ERR_CAP_TYPE; \
|
||||
} \
|
||||
}
|
||||
|
|
|
|||
34
zion/syscall/thread.cpp
Normal file
34
zion/syscall/thread.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "syscall/thread.h"
|
||||
|
||||
#include "scheduler/scheduler.h"
|
||||
#include "syscall/syscall.h"
|
||||
|
||||
z_err_t ThreadCreate(ZThreadCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->proc_cap);
|
||||
RET_ERR(ValidateCap(cap, ZC_PROC_SPAWN_THREAD));
|
||||
|
||||
auto parent_proc = cap->obj<Process>();
|
||||
RET_IF_NULL(parent_proc);
|
||||
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);
|
||||
RET_ERR(ValidateCap(cap, ZC_WRITE));
|
||||
|
||||
auto thread = cap->obj<Thread>();
|
||||
RET_IF_NULL(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");
|
||||
}
|
||||
7
zion/syscall/thread.h
Normal file
7
zion/syscall/thread.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "include/zcall.h"
|
||||
|
||||
z_err_t ThreadCreate(ZThreadCreateReq* req);
|
||||
z_err_t ThreadStart(ZThreadStartReq* req);
|
||||
z_err_t ThreadExit(ZThreadExitReq*);
|
||||
Loading…
Add table
Add a link
Reference in a new issue