[zion] Add a port create syscall

This commit is contained in:
Drew Galbraith 2023-06-17 00:31:02 -07:00
parent 09ac87e6f5
commit 378ced6b6c
4 changed files with 20 additions and 0 deletions

View File

@ -90,6 +90,7 @@ void ZThreadExit();
uint64_t* actual_bytes,
uint64_t* actual_caps);
[[nodiscard]] z_err_t ZPortCreate(uint64_t* port_cap);
[[nodiscard]] z_err_t ZPortRecv(uint64_t port_cap, uint64_t num_bytes,
uint8_t* bytes, uint64_t num_caps,
uint64_t* caps, uint64_t* type,

View File

@ -198,6 +198,12 @@ z_err_t ChannelRecv(ZChannelRecvReq* req) {
return chan->Read(req->message);
}
z_err_t PortCreate(ZPortCreateResp* resp) {
auto& proc = gScheduler->CurrentProcess();
auto port = MakeRefCounted<Port>();
return proc.AddNewCapability(port, ZC_WRITE | ZC_READ);
}
z_err_t PortRecv(ZPortRecvReq* req) {
auto& proc = gScheduler->CurrentProcess();
auto port_cap = proc.GetCapability(req->port_cap);
@ -275,6 +281,8 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
return ChannelSend(reinterpret_cast<ZChannelSendReq*>(req));
case Z_CHANNEL_RECV:
return ChannelRecv(reinterpret_cast<ZChannelRecvReq*>(req));
case Z_PORT_CREATE:
return PortCreate(reinterpret_cast<ZPortCreateResp*>(resp));
case Z_PORT_RECV:
return PortRecv(reinterpret_cast<ZPortRecvReq*>(req));
case Z_PORT_POLL:

View File

@ -163,6 +163,13 @@ z_err_t ZChannelRecv(uint64_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
return ret;
}
z_err_t ZPortCreate(uint64_t* port_cap) {
ZPortCreateResp resp;
z_err_t ret = SysCall2(Z_PORT_CREATE, 0, &resp);
*port_cap = resp.port_cap;
return ret;
}
z_err_t ZPortRecv(uint64_t port_cap, uint64_t num_bytes, uint8_t* bytes,
uint64_t num_caps, uint64_t* caps, uint64_t* type,
uint64_t* actual_bytes, uint64_t* actual_caps) {

View File

@ -86,6 +86,10 @@ struct ZChannelRecvReq {
ZMessage message;
};
struct ZPortCreateResp {
uint64_t port_cap;
};
struct ZPortRecvReq {
uint64_t port_cap;
ZMessage message;