Endpoint syscalls implemented

This commit is contained in:
Drew Galbraith 2023-06-21 23:14:42 -07:00
parent 69501bfe01
commit c064af5fa7
27 changed files with 391 additions and 42 deletions

35
zion/syscall/endpoint.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "syscall/endpoint.h"
#include "object/endpoint.h"
#include "object/reply_port.h"
#include "scheduler/scheduler.h"
glcr::ErrorCode EndpointCreate(ZEndpointCreateReq* req) {
auto& proc = gScheduler->CurrentProcess();
*req->endpoint_cap =
proc.AddNewCapability(Endpoint::Create(), ZC_READ | ZC_WRITE);
return glcr::OK;
}
glcr::ErrorCode EndpointSend(ZEndpointSendReq* req) {
auto& proc = gScheduler->CurrentProcess();
auto endpoint_cap = proc.GetCapability(req->endpoint_cap);
ValidateCapability<Endpoint>(endpoint_cap, ZC_WRITE);
auto endpoint = endpoint_cap->obj<Endpoint>();
auto reply_port = ReplyPort::Create();
*req->reply_port_cap = proc.AddNewCapability(reply_port, ZC_READ);
uint64_t reply_port_cap_to_send = proc.AddNewCapability(reply_port, ZC_WRITE);
return endpoint->Write(req->num_bytes, req->data, reply_port_cap_to_send);
}
glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
auto& proc = gScheduler->CurrentProcess();
auto endpoint_cap = proc.GetCapability(req->endpoint_cap);
ValidateCapability<Endpoint>(endpoint_cap, ZC_READ);
auto endpoint = endpoint_cap->obj<Endpoint>();
return endpoint->Read(req->num_bytes, req->data, req->reply_port_cap);
}