From deb2e708cd007a02ffc0f9dd5b65ff55daed38cb Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sun, 19 Nov 2023 20:35:55 -0800 Subject: [PATCH] [Mammoth] Add a helper method for duplicating memory capabilities. --- lib/mammoth/include/mammoth/memory_region.h | 3 ++- lib/mammoth/src/memory_region.cpp | 6 ++++++ sys/victoriafalls/victoriafalls_server.cpp | 4 +--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/mammoth/include/mammoth/memory_region.h b/lib/mammoth/include/mammoth/memory_region.h index de87d6e..c8c1521 100644 --- a/lib/mammoth/include/mammoth/memory_region.h +++ b/lib/mammoth/include/mammoth/memory_region.h @@ -53,7 +53,8 @@ class OwnedMemoryRegion { uint64_t vaddr() { return vaddr_; } uint64_t size() { return size_; } - uint64_t cap() { return vmmo_cap_; } + z_cap_t cap() { return vmmo_cap_; } + z_cap_t DuplicateCap(); bool empty() { return vmmo_cap_ != 0; } explicit operator bool() { return vmmo_cap_ != 0; } diff --git a/lib/mammoth/src/memory_region.cpp b/lib/mammoth/src/memory_region.cpp index e070b03..e4177f8 100644 --- a/lib/mammoth/src/memory_region.cpp +++ b/lib/mammoth/src/memory_region.cpp @@ -72,3 +72,9 @@ OwnedMemoryRegion OwnedMemoryRegion::FromCapability(z_cap_t vmmo_cap) { // FIXME: get the size here. return OwnedMemoryRegion(vmmo_cap, vaddr, size); } + +z_cap_t OwnedMemoryRegion::DuplicateCap() { + z_cap_t cap; + check(ZCapDuplicate(vmmo_cap_, kZionPerm_All, &cap)); + return cap; +} diff --git a/sys/victoriafalls/victoriafalls_server.cpp b/sys/victoriafalls/victoriafalls_server.cpp index 788998c..bf16f2b 100644 --- a/sys/victoriafalls/victoriafalls_server.cpp +++ b/sys/victoriafalls/victoriafalls_server.cpp @@ -56,9 +56,7 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request, // FIXME: There isn't really a reason we need to map the file into memory then // duplicate the cap. In the future just get the cap from the read then pass // it to the caller directly. - uint64_t mem_cap; - uint64_t cap = ZCapDuplicate(region.cap(), kZionPerm_All, &mem_cap); - response.set_memory(mem_cap); + response.set_memory(region.DuplicateCap()); // TODO: Consider folding this up into the actual read call. ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num)); // FIXME: This technically only sets the lower 32 bits.