twizzler_abi/syscall/
object_stat.rsuse core::mem::MaybeUninit;
use num_enum::{FromPrimitive, IntoPrimitive};
use super::{convert_codes_to_result, justval, BackingType, LifetimeType, Syscall};
use crate::{arch::syscall::raw_syscall, object::ObjID};
#[derive(
Debug,
Copy,
Clone,
PartialEq,
PartialOrd,
Ord,
Eq,
Hash,
IntoPrimitive,
FromPrimitive,
thiserror::Error,
)]
#[repr(u64)]
pub enum ObjectStatError {
#[num_enum(default)]
#[error("unknown error")]
Unknown = 0,
#[error("invalid argument")]
InvalidArgument = 1,
#[error("invalid ID")]
InvalidID = 2,
}
impl core::error::Error for ObjectStatError {}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(C)]
pub struct ObjectInfo {
pub id: ObjID,
pub maps: usize,
pub ties_to: usize,
pub ties_from: usize,
pub life: LifetimeType,
pub backing: BackingType,
}
pub fn sys_object_stat(id: ObjID) -> Result<ObjectInfo, ObjectStatError> {
let (hi, lo) = id.split();
let mut obj_info = MaybeUninit::<ObjectInfo>::uninit();
let args = [
hi,
lo,
&mut obj_info as *mut MaybeUninit<ObjectInfo> as usize as u64,
];
let (code, val) = unsafe { raw_syscall(Syscall::ObjectStat, &args) };
convert_codes_to_result(
code,
val,
|c, _| c != 0,
|_, _| unsafe { obj_info.assume_init() },
justval,
)
}