[−][src]Struct seccomp_tiny::ProgramBuffer
Fixed size buffer for building seccomp BPF programs
Conceptually this is like a Vecno_std
and
take advantage of the small maximum length of a BPF program, this type features a fixed
size array that can hold the maximum (4096) instructions.
use sc::nr; use seccomp_tiny::{ProgramBuffer, abi, bpf::ret}; let mut p = ProgramBuffer::new(); p.if_any_eq(&[ nr::ARCH_PRCTL, nr::PRCTL, nr::WAITID, nr::PTRACE, nr::KILL, ], &[ ret(abi::SECCOMP_RET_ALLOW) ]); p.inst(ret(abi::SECCOMP_RET_TRACE)); println!("{:?}", p);
Implementations
impl ProgramBuffer
[src]
pub fn new() -> Self
[src]
Construct a new empty ProgramBuffer
pub fn instructions(&self) -> &[SockFilter]
[src]
Returns a slice referring to all SockFilter instructions added to the buffer
pub fn activate(&self)
[src]
Activate the seccomp program, panic on error.
This is equivalent to:
let prog = abi::SockFilterProg::new(buffer.instructions()); let result = seccomp_tiny::activate(&prog); if let Err(code) = result { panic!("... {}", code); }
pub fn block(&mut self, block: &[SockFilter])
[src]
Copy a slice of SockFilter instructions to the end of the buffer
Panics on buffer full.
pub fn inst(&mut self, instruction: SockFilter)
[src]
Copy a SockFilter instruction to the end of the buffer
Panics on buffer full.
pub fn if_eq(&mut self, k: usize, block: &[SockFilter])
[src]
Build a conditional instruction block
This copies a group of SockFilter instructions to the end of the buffer,
gated by a conditional jump such that the block runs if the accumulator
matches the value k
.
Panics if the buffer is full, or the block we are adding is larger than the reach of a single jump (256 instructions).
pub fn if_any_eq(&mut self, k_list: &[usize], block: &[SockFilter])
[src]
Build a conditional block that checks multiple values
This is similar to making repeated calls to if_eq(), however the block
of code is only included once. This generates a series of conditional
jump instructions which test each value in k_list
, and another jump
which skips the block if none of the values have matched.
Panics if the buffer is full, or if either the list of values or the instruction block are too large to jump past at once (256 instructions each).
Trait Implementations
impl Clone for ProgramBuffer
[src]
fn clone(&self) -> ProgramBuffer
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for ProgramBuffer
[src]
fn fmt(&self, f: &mut Formatter<'_>) -> Result
[src]
Format a ProgramBuffer as a list of instructions, one per line.
impl Eq for ProgramBuffer
[src]
impl PartialEq<ProgramBuffer> for ProgramBuffer
[src]
fn eq(&self, other: &ProgramBuffer) -> bool
[src]
fn ne(&self, other: &ProgramBuffer) -> bool
[src]
impl StructuralEq for ProgramBuffer
[src]
impl StructuralPartialEq for ProgramBuffer
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,