Skip to main content

Program

Struct Program 

Source
pub struct Program { /* private fields */ }
Expand description

Immutable verified classic-BPF program.

Construction performs all structural checks and fallibly copies the raw instructions. Evaluation allocates nothing, initializes A and X to zero, and executes at most len() instructions because every accepted jump is forward-only.

Implementations§

Source§

impl Program

Source

pub fn verify(instructions: &[Instruction]) -> Result<Self, VerifyError>

Verifies and fallibly takes an immutable copy of raw instructions.

Source

pub fn try_from_vec(instructions: Vec<Instruction>) -> Result<Self, VerifyError>

Verifies and takes ownership of an existing instruction vector.

This path performs no second instruction-buffer allocation or copy. It is intended for adapters that already copied an untrusted wire program into a fallibly allocated kernel vector. Validation still uses bounded, fallible temporary storage for all-path scratch analysis.

Source

pub fn instructions(&self) -> &[Instruction]

Returns the verified raw instructions.

Source

pub fn len(&self) -> usize

Returns the instruction count and maximum evaluation step count.

Source

pub fn is_empty(&self) -> bool

Returns whether the program contains no instructions.

Verified programs are never empty, so this always returns false.

Source

pub fn translate(&self) -> Result<CodeImage, TranslationError>

Translates this verified program into an immutable x86_64 code image.

Translation only produces bytes and metadata. It does not make pages executable, patch relocations, or invoke an external function. A publisher is responsible for resolving the returned relocations under its own W^X and lifetime policy.

Source

pub fn translate_with_profile( &self, profile: InputProfile, ) -> Result<CodeImage, TranslationError>

Translates using an explicit input ABI profile.

Source

pub fn evaluate<I: Input + ?Sized>(&self, input: &I) -> u32

Evaluates the program without allocation.

A failed input load, an indirect-offset overflow, or a run-time X divisor of zero terminates evaluation with zero, matching classic-BPF failure behavior. A and X start at zero for every call.

Trait Implementations§

Source§

impl Debug for Program

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.