Add a rust user-space Capability struct.

This is a thin wrapper around a capability ptr that releases the
capability when it is done and prevents copying/cloning it.

To get a copy a caller must explicitly use duplicate.
This commit is contained in:
Drew Galbraith 2024-08-17 17:15:33 -07:00
parent 19a8ab41d4
commit 7e68c1b641
18 changed files with 215 additions and 152 deletions

View file

@ -1,6 +1,6 @@
use crate::OpenFileRequest;
use alloc::string::ToString;
use mammoth::zion::ZError;
use mammoth::{cap::Capability, zion::ZError};
pub struct File {
memory: mammoth::mem::MemoryRegion,
@ -14,7 +14,7 @@ impl File {
})?;
Ok(Self {
memory: mammoth::mem::MemoryRegion::from_cap(resp.memory)?,
memory: mammoth::mem::MemoryRegion::from_cap(Capability::take(resp.memory))?,
})
}

View file

@ -18,7 +18,7 @@ fn get_client() -> &'static mut VFSClient {
})
.expect("Failed to get VFS endpoint");
VFS_CLIENT = Some(VFSClient::new(endpoint_cap.endpoint));
VFS_CLIENT = Some(VFSClient::new(Capability::take(endpoint_cap.endpoint)));
}
VFS_CLIENT.as_mut().unwrap()
}