twizzler_object/meta.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
use std::{mem::size_of, ptr::NonNull};
use twizzler_abi::{
marker::{BaseTag, BaseVersion},
meta::{MetaExt, MetaFlags, MetaInfo, Nonce},
object::ObjID,
};
use crate::Object;
#[derive(Debug, Clone, Copy)]
#[repr(C)]
struct FotName {
name: u64,
resolver: u64,
}
#[repr(C)]
union FotRef {
id: ObjID,
name: FotName,
}
/// An entry in the FOT.
#[repr(C)]
pub struct FotEntry {
outgoing: FotRef,
flags: u32,
info: u32,
refs: u32,
resv: u32,
}
impl<T> Object<T> {
/// Get a mutable reference to the object's meta info struct.
///
/// # Safety
/// See this crate's base documentation ([Isolation Safety](crate)).
pub unsafe fn meta(&self) -> NonNull<MetaInfo> {
let end = self.slot.vaddr_meta();
((end + twizzler_abi::object::NULLPAGE_SIZE / 2) as *mut MetaInfo)
.as_mut()
.unwrap_unchecked()
.into()
}
/// Get a mutable reference to the object's first meta extension entry.
///
/// # Safety
/// See this crate's base documentation ([Isolation Safety](crate)).
pub unsafe fn metaext(&self) -> NonNull<MetaExt> {
let end = self.slot.vaddr_meta();
((end + twizzler_abi::object::NULLPAGE_SIZE / 2 + size_of::<MetaInfo>()) as *mut MetaExt)
.as_mut()
.unwrap_unchecked()
.into()
}
/// Get the nonce of the object.
pub fn meta_nonce(&self) -> Nonce {
unsafe { self.meta().as_mut().nonce }
}
/// Get the public key ID of the object.
pub fn meta_kuid(&self) -> ObjID {
unsafe { self.meta().as_mut().kuid }
}
/// Get the meta flags of the object.
pub fn meta_flags(&self) -> MetaFlags {
unsafe { self.meta().as_mut().flags }
}
/// Get the base tag of the object.
pub fn meta_tag(&self) -> BaseTag {
unsafe { self.meta().as_mut().tag }
}
/// Get the base version of the object.
pub fn meta_version(&self) -> BaseVersion {
unsafe { self.meta().as_mut().version }
}
/// Get a mutable pointer to one of the object's FOT entries.
///
/// # Safety
/// See this crate's base documentation ([Isolation Safety](crate)). Additionally, the caller
/// must ensure the index does not exceed the number of FOT entries in the object.
pub unsafe fn get_fote_unguarded(&self, idx: usize) -> *mut FotEntry {
self.slot.get_fote_unguarded(idx)
}
}