[Mammoth] Add a helper method for duplicating memory capabilities.
This commit is contained in:
parent
8e827a5dfb
commit
deb2e708cd
|
@ -53,7 +53,8 @@ class OwnedMemoryRegion {
|
||||||
uint64_t vaddr() { return vaddr_; }
|
uint64_t vaddr() { return vaddr_; }
|
||||||
uint64_t size() { return size_; }
|
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; }
|
bool empty() { return vmmo_cap_ != 0; }
|
||||||
explicit operator bool() { return vmmo_cap_ != 0; }
|
explicit operator bool() { return vmmo_cap_ != 0; }
|
||||||
|
|
|
@ -72,3 +72,9 @@ OwnedMemoryRegion OwnedMemoryRegion::FromCapability(z_cap_t vmmo_cap) {
|
||||||
// FIXME: get the size here.
|
// FIXME: get the size here.
|
||||||
return OwnedMemoryRegion(vmmo_cap, vaddr, size);
|
return OwnedMemoryRegion(vmmo_cap, vaddr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
z_cap_t OwnedMemoryRegion::DuplicateCap() {
|
||||||
|
z_cap_t cap;
|
||||||
|
check(ZCapDuplicate(vmmo_cap_, kZionPerm_All, &cap));
|
||||||
|
return cap;
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
// 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
|
// duplicate the cap. In the future just get the cap from the read then pass
|
||||||
// it to the caller directly.
|
// it to the caller directly.
|
||||||
uint64_t mem_cap;
|
response.set_memory(region.DuplicateCap());
|
||||||
uint64_t cap = ZCapDuplicate(region.cap(), kZionPerm_All, &mem_cap);
|
|
||||||
response.set_memory(mem_cap);
|
|
||||||
// TODO: Consider folding this up into the actual read call.
|
// TODO: Consider folding this up into the actual read call.
|
||||||
ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num));
|
ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num));
|
||||||
// FIXME: This technically only sets the lower 32 bits.
|
// FIXME: This technically only sets the lower 32 bits.
|
||||||
|
|
Loading…
Reference in New Issue