[zion] POC for defining syscalls using macros
This commit is contained in:
parent
4fef54084f
commit
5fc7296b20
|
@ -4,7 +4,33 @@
|
|||
|
||||
#include "ztypes.h"
|
||||
|
||||
void ZProcessExit(uint64_t code);
|
||||
#define SYS1(name, num, t1, a1) \
|
||||
struct Z##name##Req { \
|
||||
t1 a1; \
|
||||
}; \
|
||||
[[nodiscard]] inline z_err_t Z##name(t1 a1) { \
|
||||
Z##name##Req req{ \
|
||||
.a1 = a1, \
|
||||
}; \
|
||||
return SysCall1(num, &req); \
|
||||
}
|
||||
|
||||
#define SYS2(name, num, t1, a1, t2, a2) \
|
||||
struct Z##name##Req { \
|
||||
t1 a1; \
|
||||
t2 a2; \
|
||||
}; \
|
||||
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2) { \
|
||||
Z##name##Req req{ \
|
||||
.a1 = a1, \
|
||||
.a2 = a2, \
|
||||
}; \
|
||||
return SysCall1(num, &req); \
|
||||
}
|
||||
|
||||
z_err_t SysCall1(uint64_t code, const void* req);
|
||||
|
||||
SYS1(ProcessExit, Z_PROCESS_EXIT, uint64_t, code);
|
||||
|
||||
[[nodiscard]] z_err_t ZProcessSpawn(z_cap_t proc_cap, z_cap_t bootstrap_cap,
|
||||
z_cap_t* new_proc_cap,
|
||||
|
@ -16,7 +42,7 @@ void ZProcessExit(uint64_t code);
|
|||
uint64_t entry, uint64_t arg1,
|
||||
uint64_t arg2);
|
||||
|
||||
[[nodiscard]] z_err_t ZThreadCreate(z_cap_t proc_cap, z_cap_t* thread_cap);
|
||||
SYS2(ThreadCreate, Z_THREAD_CREATE, z_cap_t, proc_cap, z_cap_t*, thread_cap);
|
||||
|
||||
[[nodiscard]] z_err_t ZThreadStart(z_cap_t thread_cap, uint64_t entry,
|
||||
uint64_t arg1, uint64_t arg2);
|
||||
|
|
|
@ -89,7 +89,7 @@ z_err_t ProcessSpawn(ZProcessSpawnReq* req, ZProcessSpawnResp* resp) {
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
z_err_t ThreadCreate(ZThreadCreateReq* req, ZThreadCreateResp* resp) {
|
||||
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));
|
||||
|
@ -97,8 +97,7 @@ z_err_t ThreadCreate(ZThreadCreateReq* req, ZThreadCreateResp* resp) {
|
|||
auto parent_proc = cap->obj<Process>();
|
||||
RET_IF_NULL(parent_proc);
|
||||
auto thread = parent_proc->CreateThread();
|
||||
resp->thread_cap = curr_proc.AddNewCapability(thread, ZC_WRITE);
|
||||
|
||||
*req->thread_cap = curr_proc.AddNewCapability(thread, ZC_WRITE);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
@ -267,7 +266,8 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
|||
switch (call_id) {
|
||||
case Z_PROCESS_EXIT:
|
||||
// FIXME: kill process here.
|
||||
dbgln("Exit code: %x", req);
|
||||
dbgln("Exiting: %m", req);
|
||||
dbgln("Exit code: %x", reinterpret_cast<ZProcessExitReq*>(req)->code);
|
||||
thread->Exit();
|
||||
panic("Returned from thread exit");
|
||||
break;
|
||||
|
@ -275,8 +275,7 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
|||
return ProcessSpawn(reinterpret_cast<ZProcessSpawnReq*>(req),
|
||||
reinterpret_cast<ZProcessSpawnResp*>(resp));
|
||||
case Z_THREAD_CREATE:
|
||||
return ThreadCreate(reinterpret_cast<ZThreadCreateReq*>(req),
|
||||
reinterpret_cast<ZThreadCreateResp*>(resp));
|
||||
return ThreadCreate(reinterpret_cast<ZThreadCreateReq*>(req));
|
||||
case Z_THREAD_START:
|
||||
return ThreadStart(reinterpret_cast<ZThreadStartReq*>(req));
|
||||
case Z_THREAD_EXIT:
|
||||
|
|
|
@ -8,6 +8,7 @@ _start:
|
|||
_exit:
|
||||
// EXIT syscall.
|
||||
mov $1, %rdi
|
||||
// Return code as a param.
|
||||
mov %rax, %rsi
|
||||
// Return code as a "struct" on the stack.
|
||||
push %rax
|
||||
mov %rsp, %rsi
|
||||
syscall
|
||||
|
|
|
@ -19,10 +19,6 @@ z_err_t SysCall1(uint64_t number, const void* first) {
|
|||
return SysCall2(number, first, 0);
|
||||
}
|
||||
|
||||
void ZProcessExit(uint64_t code) {
|
||||
SysCall1(Z_PROCESS_EXIT, reinterpret_cast<void*>(code));
|
||||
}
|
||||
|
||||
z_err_t ZProcessSpawn(z_cap_t proc_cap, z_cap_t bootstrap_cap,
|
||||
z_cap_t* new_proc_cap, z_cap_t* new_vmas_cap,
|
||||
z_cap_t* new_bootstrap_cap) {
|
||||
|
@ -38,16 +34,6 @@ z_err_t ZProcessSpawn(z_cap_t proc_cap, z_cap_t bootstrap_cap,
|
|||
return ret;
|
||||
}
|
||||
|
||||
z_err_t ZThreadCreate(z_cap_t proc_cap, z_cap_t* thread_cap) {
|
||||
ZThreadCreateReq req{
|
||||
.proc_cap = proc_cap,
|
||||
};
|
||||
ZThreadCreateResp resp;
|
||||
z_err_t ret = SysCall2(Z_THREAD_CREATE, &req, &resp);
|
||||
*thread_cap = resp.thread_cap;
|
||||
return ret;
|
||||
}
|
||||
|
||||
z_err_t ZThreadStart(z_cap_t thread_cap, uint64_t entry, uint64_t arg1,
|
||||
uint64_t arg2) {
|
||||
ZThreadStartReq req{
|
||||
|
|
|
@ -15,14 +15,6 @@ struct ZProcessSpawnResp {
|
|||
z_cap_t bootstrap_cap;
|
||||
};
|
||||
|
||||
struct ZThreadCreateReq {
|
||||
z_cap_t proc_cap;
|
||||
};
|
||||
|
||||
struct ZThreadCreateResp {
|
||||
z_cap_t thread_cap;
|
||||
};
|
||||
|
||||
struct ZThreadStartReq {
|
||||
z_cap_t thread_cap;
|
||||
uint64_t entry;
|
||||
|
|
Loading…
Reference in New Issue