[zion] Move capability validation to capability.h

This commit is contained in:
Drew Galbraith 2023-06-20 15:50:49 -07:00
parent 93cf8f2740
commit 172bf51db7
8 changed files with 42 additions and 47 deletions

View file

@ -1,7 +1,7 @@
#include "syscall/channel.h"
#include "capability/capability.h"
#include "scheduler/scheduler.h"
#include "syscall/syscall.h"
z_err_t ChannelCreate(ZChannelCreateReq* req) {
auto& proc = gScheduler->CurrentProcess();
@ -15,19 +15,17 @@ z_err_t ChannelCreate(ZChannelCreateReq* req) {
z_err_t ChannelSend(ZChannelSendReq* req) {
auto& proc = gScheduler->CurrentProcess();
auto chan_cap = proc.GetCapability(req->chan_cap);
RET_ERR(ValidateCap(chan_cap, ZC_WRITE));
RET_ERR(ValidateCapability<Channel>(chan_cap, ZC_WRITE));
auto chan = chan_cap->obj<Channel>();
RET_IF_NULL(chan);
return chan->Write(req->num_bytes, req->data, req->num_caps, req->caps);
}
z_err_t ChannelRecv(ZChannelRecvReq* req) {
auto& proc = gScheduler->CurrentProcess();
auto chan_cap = proc.GetCapability(req->chan_cap);
RET_ERR(ValidateCap(chan_cap, ZC_READ));
RET_ERR(ValidateCapability<Channel>(chan_cap, ZC_READ));
auto chan = chan_cap->obj<Channel>();
RET_IF_NULL(chan);
return chan->Read(req->num_bytes, req->data, req->num_caps, req->caps);
}