use std::collections::{HashMap, HashSet};
use syscalls::Sysno;
use crate::{Rule, RuleSet};
use super::YesReally;
pub struct Threads {
allowed: HashSet<Sysno>,
}
impl Threads {
#[must_use]
pub fn nothing() -> Threads {
Threads {
allowed: HashSet::new(),
}
}
#[must_use]
pub fn allow_create(mut self) -> Threads {
self.allowed.extend([Sysno::clone, Sysno::clone3]);
self
}
#[must_use]
pub fn allow_sleep(mut self) -> YesReally<Threads> {
self.allowed
.extend([Sysno::clock_nanosleep, Sysno::nanosleep]);
YesReally::new(self)
}
}
impl RuleSet for Threads {
fn simple_rules(&self) -> Vec<Sysno> {
self.allowed.iter().copied().collect()
}
fn conditional_rules(&self) -> HashMap<Sysno, Vec<Rule>> {
HashMap::new()
}
fn name(&self) -> &'static str {
"Threads"
}
}
pub struct ForkAndExec;
impl RuleSet for ForkAndExec {
fn simple_rules(&self) -> Vec<Sysno> {
vec![
Sysno::fork, Sysno::vfork,
Sysno::execve, Sysno::execveat,
Sysno::wait4, Sysno::waitid,
Sysno::clone, Sysno::clone3,
]
}
fn conditional_rules(&self) -> HashMap<Sysno, Vec<Rule>> {
HashMap::new()
}
fn name(&self) -> &'static str {
"ForkAndExec"
}
}