[zion] Move to default permissions being supplied by KernelObjects
This commit is contained in:
parent
48c6e5b3a4
commit
1364fbed9f
16 changed files with 91 additions and 54 deletions
|
|
@ -7,8 +7,8 @@ z_err_t AddressSpaceMap(ZAddressSpaceMapReq* req) {
|
|||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto vmas_cap = curr_proc.GetCapability(req->vmas_cap);
|
||||
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
||||
RET_ERR(ValidateCapability<AddressSpace>(vmas_cap, ZC_WRITE));
|
||||
RET_ERR(ValidateCapability<MemoryObject>(vmmo_cap, ZC_WRITE));
|
||||
RET_ERR(ValidateCapability<AddressSpace>(vmas_cap, kZionPerm_Write));
|
||||
RET_ERR(ValidateCapability<MemoryObject>(vmmo_cap, kZionPerm_Write));
|
||||
|
||||
auto vmas = vmas_cap->obj<AddressSpace>();
|
||||
auto vmmo = vmmo_cap->obj<MemoryObject>();
|
||||
|
|
|
|||
|
|
@ -9,16 +9,15 @@
|
|||
z_err_t ChannelCreate(ZChannelCreateReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto chan_pair = Channel::CreateChannelPair();
|
||||
*req->channel1 = proc.AddNewCapability(chan_pair.first(), ZC_WRITE | ZC_READ);
|
||||
*req->channel2 =
|
||||
proc.AddNewCapability(chan_pair.second(), ZC_WRITE | ZC_READ);
|
||||
*req->channel1 = proc.AddNewCapability(chan_pair.first());
|
||||
*req->channel2 = proc.AddNewCapability(chan_pair.second());
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t ChannelSend(ZChannelSendReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto chan_cap = proc.GetCapability(req->chan_cap);
|
||||
RET_ERR(ValidateCapability<Channel>(chan_cap, ZC_WRITE));
|
||||
RET_ERR(ValidateCapability<Channel>(chan_cap, kZionPerm_Write));
|
||||
|
||||
auto chan = chan_cap->obj<Channel>();
|
||||
return chan->Send(req->num_bytes, req->data, req->num_caps, req->caps);
|
||||
|
|
@ -27,7 +26,7 @@ z_err_t ChannelSend(ZChannelSendReq* req) {
|
|||
z_err_t ChannelRecv(ZChannelRecvReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto chan_cap = proc.GetCapability(req->chan_cap);
|
||||
RET_ERR(ValidateCapability<Channel>(chan_cap, ZC_READ));
|
||||
RET_ERR(ValidateCapability<Channel>(chan_cap, kZionPerm_Read));
|
||||
|
||||
auto chan = chan_cap->obj<Channel>();
|
||||
return chan->Recv(req->num_bytes, req->data, req->num_caps, req->caps);
|
||||
|
|
@ -36,14 +35,14 @@ z_err_t ChannelRecv(ZChannelRecvReq* req) {
|
|||
z_err_t PortCreate(ZPortCreateReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto port = glcr::MakeRefCounted<Port>();
|
||||
*req->port_cap = proc.AddNewCapability(port, ZC_WRITE | ZC_READ);
|
||||
*req->port_cap = proc.AddNewCapability(port);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t PortSend(ZPortSendReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto port_cap = proc.GetCapability(req->port_cap);
|
||||
RET_ERR(ValidateCapability<Port>(port_cap, ZC_WRITE));
|
||||
RET_ERR(ValidateCapability<Port>(port_cap, kZionPerm_Write));
|
||||
|
||||
auto port = port_cap->obj<Port>();
|
||||
return port->Send(req->num_bytes, req->data, req->num_caps, req->caps);
|
||||
|
|
@ -52,7 +51,7 @@ z_err_t PortSend(ZPortSendReq* req) {
|
|||
z_err_t PortRecv(ZPortRecvReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto port_cap = proc.GetCapability(req->port_cap);
|
||||
RET_ERR(ValidateCapability<Port>(port_cap, ZC_READ));
|
||||
RET_ERR(ValidateCapability<Port>(port_cap, kZionPerm_Read));
|
||||
|
||||
auto port = port_cap->obj<Port>();
|
||||
ZMessage message{
|
||||
|
|
@ -67,7 +66,7 @@ z_err_t PortRecv(ZPortRecvReq* req) {
|
|||
z_err_t PortPoll(ZPortPollReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto port_cap = proc.GetCapability(req->port_cap);
|
||||
RET_ERR(ValidateCapability<Port>(port_cap, ZC_READ));
|
||||
RET_ERR(ValidateCapability<Port>(port_cap, kZionPerm_Read));
|
||||
|
||||
auto port = port_cap->obj<Port>();
|
||||
// FIXME: Race condition here where this call could block if the last message
|
||||
|
|
@ -85,15 +84,14 @@ z_err_t IrqRegister(ZIrqRegisterReq* req) {
|
|||
return glcr::UNIMPLEMENTED;
|
||||
}
|
||||
glcr::RefPtr<Port> port = glcr::MakeRefCounted<Port>();
|
||||
*req->port_cap = proc.AddNewCapability(port, ZC_READ | ZC_WRITE);
|
||||
*req->port_cap = proc.AddNewCapability(port);
|
||||
RegisterPciPort(port);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode EndpointCreate(ZEndpointCreateReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
*req->endpoint_cap =
|
||||
proc.AddNewCapability(Endpoint::Create(), ZC_READ | ZC_WRITE);
|
||||
*req->endpoint_cap = proc.AddNewCapability(Endpoint::Create());
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
|
@ -101,12 +99,13 @@ glcr::ErrorCode EndpointSend(ZEndpointSendReq* req) {
|
|||
auto& proc = gScheduler->CurrentProcess();
|
||||
|
||||
auto endpoint_cap = proc.GetCapability(req->endpoint_cap);
|
||||
ValidateCapability<Endpoint>(endpoint_cap, ZC_WRITE);
|
||||
ValidateCapability<Endpoint>(endpoint_cap, kZionPerm_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);
|
||||
*req->reply_port_cap = proc.AddNewCapability(reply_port, kZionPerm_Read);
|
||||
uint64_t reply_port_cap_to_send =
|
||||
proc.AddNewCapability(reply_port, kZionPerm_Write);
|
||||
return endpoint->Send(req->num_bytes, req->data, 1, &reply_port_cap_to_send);
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +113,7 @@ glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
|
|||
auto& proc = gScheduler->CurrentProcess();
|
||||
|
||||
auto endpoint_cap = proc.GetCapability(req->endpoint_cap);
|
||||
ValidateCapability<Endpoint>(endpoint_cap, ZC_READ);
|
||||
ValidateCapability<Endpoint>(endpoint_cap, kZionPerm_Read);
|
||||
auto endpoint = endpoint_cap->obj<Endpoint>();
|
||||
|
||||
uint64_t num_caps = 1;
|
||||
|
|
@ -129,7 +128,7 @@ glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
|
|||
glcr::ErrorCode ReplyPortSend(ZReplyPortSendReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto reply_port_cap = proc.GetCapability(req->reply_port_cap);
|
||||
ValidateCapability<ReplyPort>(reply_port_cap, ZC_WRITE);
|
||||
ValidateCapability<ReplyPort>(reply_port_cap, kZionPerm_Read);
|
||||
auto reply_port = reply_port_cap->obj<ReplyPort>();
|
||||
|
||||
return reply_port->Send(req->num_bytes, req->data, req->num_caps, req->caps);
|
||||
|
|
@ -138,7 +137,7 @@ glcr::ErrorCode ReplyPortRecv(ZReplyPortRecvReq* req) {
|
|||
auto& proc = gScheduler->CurrentProcess();
|
||||
|
||||
auto reply_port_cap = proc.GetCapability(req->reply_port_cap);
|
||||
ValidateCapability<ReplyPort>(reply_port_cap, ZC_READ);
|
||||
ValidateCapability<ReplyPort>(reply_port_cap, kZionPerm_Read);
|
||||
auto reply_port = reply_port_cap->obj<ReplyPort>();
|
||||
|
||||
return reply_port->Recv(req->num_bytes, req->data, req->num_caps, req->caps);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
glcr::MakeRefCounted<MemoryObject>(req->size), ZC_WRITE);
|
||||
*req->vmmo_cap =
|
||||
curr_proc.AddNewCapability(glcr::MakeRefCounted<MemoryObject>(req->size));
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
|
@ -15,8 +15,8 @@ z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req) {
|
|||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
uint64_t paddr = req->paddr;
|
||||
auto vmmo_ref = glcr::MakeRefCounted<FixedMemoryObject>(paddr, req->size);
|
||||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
StaticCastRefPtr<MemoryObject>(vmmo_ref), ZC_WRITE);
|
||||
*req->vmmo_cap =
|
||||
curr_proc.AddNewCapability(StaticCastRefPtr<MemoryObject>(vmmo_ref));
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
|
@ -24,8 +24,8 @@ z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) {
|
|||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
uint64_t paddr = phys_mem::AllocateContinuous(((req->size - 1) / 0x1000) + 1);
|
||||
auto vmmo_ref = glcr::MakeRefCounted<FixedMemoryObject>(paddr, req->size);
|
||||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
StaticCastRefPtr<MemoryObject>(vmmo_ref), ZC_WRITE);
|
||||
*req->vmmo_cap =
|
||||
curr_proc.AddNewCapability(StaticCastRefPtr<MemoryObject>(vmmo_ref));
|
||||
*req->paddr = paddr;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
@ -34,11 +34,11 @@ z_err_t MemoryObjectDuplicate(ZMemoryObjectDuplicateReq* req) {
|
|||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
||||
// FIXME: Check a duplication permission here.
|
||||
RET_ERR(ValidateCapability<MemoryObject>(vmmo_cap, ZC_WRITE));
|
||||
RET_ERR(ValidateCapability<MemoryObject>(vmmo_cap, kZionPerm_Write));
|
||||
|
||||
ASSIGN_OR_RETURN(
|
||||
glcr::RefPtr<MemoryObject> new_vmmo,
|
||||
vmmo_cap->obj<MemoryObject>()->Duplicate(req->base_offset, req->length));
|
||||
*req->new_vmmo_cap = curr_proc.AddNewCapability(new_vmmo, ZC_WRITE | ZC_READ);
|
||||
*req->new_vmmo_cap = curr_proc.AddNewCapability(new_vmmo);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,13 @@ z_err_t ProcessExit(ZProcessExitReq* req) {
|
|||
z_err_t ProcessSpawn(ZProcessSpawnReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->proc_cap);
|
||||
RET_ERR(ValidateCapability<Process>(cap, ZC_PROC_SPAWN_PROC));
|
||||
RET_ERR(ValidateCapability<Process>(cap, kZionPerm_SpawnProcess));
|
||||
|
||||
glcr::RefPtr<Process> proc = Process::Create();
|
||||
gProcMan->InsertProcess(proc);
|
||||
|
||||
*req->new_proc_cap = curr_proc.AddNewCapability(
|
||||
proc, ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD | ZC_WRITE);
|
||||
*req->new_vmas_cap = curr_proc.AddNewCapability(proc->vmas(), ZC_WRITE);
|
||||
*req->new_proc_cap = curr_proc.AddNewCapability(proc);
|
||||
*req->new_vmas_cap = curr_proc.AddNewCapability(proc->vmas());
|
||||
|
||||
if (req->bootstrap_cap != 0) {
|
||||
auto cap = curr_proc.ReleaseCapability(req->bootstrap_cap);
|
||||
|
|
|
|||
|
|
@ -7,18 +7,18 @@
|
|||
glcr::ErrorCode ThreadCreate(ZThreadCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->proc_cap);
|
||||
RET_ERR(ValidateCapability<Process>(cap, ZC_PROC_SPAWN_THREAD));
|
||||
RET_ERR(ValidateCapability<Process>(cap, kZionPerm_SpawnThread));
|
||||
|
||||
auto parent_proc = cap->obj<Process>();
|
||||
auto thread = parent_proc->CreateThread();
|
||||
*req->thread_cap = curr_proc.AddNewCapability(thread, ZC_WRITE | ZC_READ);
|
||||
*req->thread_cap = curr_proc.AddNewCapability(thread);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode ThreadStart(ZThreadStartReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->thread_cap);
|
||||
RET_ERR(ValidateCapability<Thread>(cap, ZC_WRITE));
|
||||
RET_ERR(ValidateCapability<Thread>(cap, kZionPerm_Write));
|
||||
|
||||
auto thread = cap->obj<Thread>();
|
||||
// FIXME: validate entry point is in user space.
|
||||
|
|
@ -36,7 +36,7 @@ glcr::ErrorCode ThreadExit(ZThreadExitReq*) {
|
|||
glcr::ErrorCode ThreadWait(ZThreadWaitReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->thread_cap);
|
||||
RET_ERR(ValidateCapability<Thread>(cap, ZC_READ));
|
||||
RET_ERR(ValidateCapability<Thread>(cap, kZionPerm_Read));
|
||||
auto thread = cap->obj<Thread>();
|
||||
thread->Wait();
|
||||
return glcr::OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue