Skip to content

Commit

Permalink
feat(RuleSet): impl RuleSet for syscalls::Sysno to avoid definining t…
Browse files Browse the repository at this point in the history
…ypes for single syscalls
  • Loading branch information
sivizius authored and boustrophedon committed Nov 14, 2023
1 parent c0289d9 commit a59b0ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ impl<T: ?Sized + RuleSet> RuleSet for &T {
}
}

impl RuleSet for syscalls::Sysno {
fn simple_rules(&self) -> Vec<syscalls::Sysno> {
Vec::from([*self])
}

fn conditional_rules(&self) -> HashMap<syscalls::Sysno, Vec<SeccompRule>> {
HashMap::new()
}

fn name(&self) -> &'static str {
self.name()
}
}

#[must_use]
/// A struct representing a set of rules to be loaded into a seccomp filter and applied to the
/// current thread, or all threads in the current process.
Expand Down
21 changes: 21 additions & 0 deletions tests/sysno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use extrasafe::SafetyContext;
use syscalls::Sysno;

#[test]
#[should_panic]
fn hello_void() {
SafetyContext::new().apply_to_current_thread().unwrap();

println!("Hello, World!");
}

#[test]
fn hello_world() {
SafetyContext::new()
.enable(Sysno::write)
.unwrap()
.apply_to_current_thread()
.unwrap();

println!("Hello, World!");
}

0 comments on commit a59b0ea

Please sign in to comment.