[zion] Add a method for duplicating and scoping down VMMOs.
Use the AHCI section of the PCI config as an example POC of this. We can now pass a memory capability instead of just the physical address.
This commit is contained in:
parent
8f84f8c3ca
commit
48c6e5b3a4
12 changed files with 62 additions and 18 deletions
|
|
@ -107,6 +107,9 @@ SYS3(MemoryObjectCreatePhysical, uint64_t, paddr, uint64_t, size, z_cap_t*,
|
|||
SYS3(MemoryObjectCreateContiguous, uint64_t, size, z_cap_t*, vmmo_cap,
|
||||
uint64_t*, paddr);
|
||||
|
||||
SYS4(MemoryObjectDuplicate, z_cap_t, vmmo_cap, uint64_t, base_offset, uint64_t,
|
||||
length, z_cap_t*, new_vmmo_cap);
|
||||
|
||||
SYS2(ChannelCreate, z_cap_t*, channel1, z_cap_t*, channel2);
|
||||
SYS5(ChannelSend, z_cap_t, chan_cap, uint64_t, num_bytes, const void*, data,
|
||||
uint64_t, num_caps, z_cap_t*, caps);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ const uint64_t kZionMemoryObjectCreate = 0x30;
|
|||
const uint64_t kZionMemoryObjectCreatePhysical = 0x31;
|
||||
const uint64_t kZionMemoryObjectCreateContiguous = 0x32;
|
||||
|
||||
const uint64_t kZionMemoryObjectDuplicate = 0x38;
|
||||
|
||||
// IPC Calls
|
||||
const uint64_t kZionChannelCreate = 0x40;
|
||||
const uint64_t kZionChannelSend = 0x41;
|
||||
|
|
|
|||
|
|
@ -67,3 +67,13 @@ uint64_t MemoryObject::PageNumberToPhysAddr(uint64_t page_num) {
|
|||
}
|
||||
return *iter;
|
||||
}
|
||||
|
||||
glcr::ErrorOr<glcr::RefPtr<MemoryObject>> FixedMemoryObject::Duplicate(
|
||||
uint64_t offset, uint64_t length) {
|
||||
if (offset + length > size()) {
|
||||
return glcr::INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
return glcr::StaticCastRefPtr<MemoryObject>(
|
||||
glcr::MakeRefCounted<FixedMemoryObject>(physical_addr_ + offset, length));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/linked_list.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
|
||||
#include "object/kernel_object.h"
|
||||
|
||||
|
|
@ -28,6 +30,11 @@ class MemoryObject : public KernelObject {
|
|||
|
||||
void CopyBytesToObject(uint64_t source, uint64_t length);
|
||||
|
||||
virtual glcr::ErrorOr<glcr::RefPtr<MemoryObject>> Duplicate(uint64_t offset,
|
||||
uint64_t length) {
|
||||
return glcr::UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Hacky to avoid linked_list creation.
|
||||
MemoryObject(uint64_t size, bool) : size_(size) {}
|
||||
|
|
@ -47,6 +54,9 @@ class FixedMemoryObject : public MemoryObject {
|
|||
FixedMemoryObject(uint64_t physical_addr, uint64_t size)
|
||||
: MemoryObject(size, true), physical_addr_(physical_addr) {}
|
||||
|
||||
virtual glcr::ErrorOr<glcr::RefPtr<MemoryObject>> Duplicate(
|
||||
uint64_t offset, uint64_t length) override;
|
||||
|
||||
private:
|
||||
uint64_t physical_addr_;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,3 +29,16 @@ z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) {
|
|||
*req->paddr = paddr;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
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);
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@
|
|||
z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req);
|
||||
z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req);
|
||||
z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req);
|
||||
z_err_t MemoryObjectDuplicate(ZMemoryObjectDuplicateReq* req);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req) {
|
|||
CASE(MemoryObjectCreate);
|
||||
CASE(MemoryObjectCreatePhysical);
|
||||
CASE(MemoryObjectCreateContiguous);
|
||||
CASE(MemoryObjectDuplicate);
|
||||
// syscall/ipc.h
|
||||
CASE(ChannelCreate);
|
||||
CASE(ChannelSend);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue