use std::collections::{HashMap, HashSet};
use syscalls::Sysno;
use crate::{SeccompRule, RuleSet};
use super::YesReally;
#[must_use]
pub struct Threads {
allowed: HashSet<Sysno>,
}
impl Threads {
pub fn nothing() -> Threads {
Threads {
allowed: HashSet::new(),
}
}
pub fn allow_create(mut self) -> Threads {
self.allowed.extend([Sysno::clone, Sysno::clone3]);
self
}
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<SeccompRule>> {
HashMap::new()
}
fn name(&self) -> &'static str {
"Threads"
}
}
#[must_use]
pub struct ForkAndExec;
impl RuleSet for ForkAndExec {
fn simple_rules(&self) -> Vec<Sysno> {
let mut rules = vec![
Sysno::fork, Sysno::vfork,
Sysno::execve, Sysno::execveat,
Sysno::wait4, Sysno::waitid,
Sysno::clone, Sysno::clone3,
];
if cfg!(target_env = "musl") {
rules.extend([Sysno::pipe, Sysno::pipe2]);
}
rules
}
fn conditional_rules(&self) -> HashMap<Sysno, Vec<SeccompRule>> {
HashMap::new()
}
fn name(&self) -> &'static str {
"ForkAndExec"
}
}