twizzler_abi/syscall/
object_stat.rs

1use core::mem::MaybeUninit;
2
3use twizzler_rt_abi::Result;
4
5use super::{convert_codes_to_result, twzerr, BackingType, LifetimeType, Syscall};
6use crate::{arch::syscall::raw_syscall, object::ObjID};
7
8/// Information about an object, according to the local kernel.
9#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
10#[repr(C)]
11pub struct ObjectInfo {
12    /// The ID of this object.
13    pub id: ObjID,
14    /// The number of mappings in which this object participates.
15    pub maps: usize,
16    /// The number of ties to this object.
17    pub ties_to: usize,
18    /// The number of ties from this object.
19    pub ties_from: usize,
20    /// The lifetime type of this object.
21    pub life: LifetimeType,
22    /// The backing type of this object.
23    pub backing: BackingType,
24    /// The number of pages allocated to this object.
25    pub pages: usize,
26}
27
28/// Read information about a given object.
29pub fn sys_object_stat(id: ObjID) -> Result<ObjectInfo> {
30    let [hi, lo] = id.parts();
31    let mut obj_info = MaybeUninit::<ObjectInfo>::uninit();
32    let args = [
33        hi,
34        lo,
35        &mut obj_info as *mut MaybeUninit<ObjectInfo> as usize as u64,
36    ];
37    let (code, val) = unsafe { raw_syscall(Syscall::ObjectStat, &args) };
38    convert_codes_to_result(
39        code,
40        val,
41        |c, _| c != 0,
42        |_, _| unsafe { obj_info.assume_init() },
43        twzerr,
44    )
45}