#[cfg(not(target_os = "linux"))]
use crate::error::Error;
use crate::identity::{Kernel, RawPid};
#[cfg_attr(windows, path = "enumerate/windows.rs")]
#[cfg_attr(target_os = "linux", path = "enumerate/linux.rs")]
#[cfg_attr(target_os = "macos", path = "enumerate/macos.rs")]
mod backend;
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]
compile_error!("cosca::containment::enumerate is implemented only for Windows, Linux, and macOS");
pub(crate) use backend::process_parents;
pub(crate) struct Table {
pub(crate) parents: Vec<(RawPid, RawPid)>,
#[cfg(target_os = "linux")]
view: crate::identity::ProcDir,
}
#[cfg(target_os = "linux")]
pub(crate) use backend::process_table;
#[cfg(not(target_os = "linux"))]
pub(crate) fn process_table(kernel: &dyn Kernel) -> Result<Table, Error> {
Ok(Table {
parents: backend::process_parents(kernel)?,
})
}
#[cfg(unix)]
impl Table {
pub(crate) fn exit_begun(
&self,
kernel: &dyn Kernel,
root: crate::identity::ProcessId,
) -> (crate::identity::Resolved<bool>, crate::identity::UnknownCause) {
#[cfg(target_os = "linux")]
{
root.exit_begun_in(kernel, &self.view)
}
#[cfg(not(target_os = "linux"))]
{
root.exit_begun_with(kernel)
}
}
}
#[cfg(target_os = "macos")]
pub(crate) fn snapshot() -> (Vec<RawPid>, Vec<(RawPid, RawPid)>, usize) {
backend::snapshot()
}
#[cfg(all(test, target_os = "macos"))]
pub(crate) fn force_blind_snapshots(count: usize) {
backend::force_blind_snapshots(count)
}
#[cfg(all(test, target_os = "macos"))]
#[track_caller]
pub(crate) fn assert_blind_snapshots_consumed() {
backend::assert_blind_snapshots_consumed()
}
#[cfg(all(test, any(target_os = "macos", windows)))]
pub(crate) use backend::fault as backend_fault;