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
impl Program
Sourcepub fn verify(instructions: &[Instruction]) -> Result<Self, VerifyError>
pub fn verify(instructions: &[Instruction]) -> Result<Self, VerifyError>
Verifies and fallibly takes an immutable copy of raw instructions.
Sourcepub fn try_from_vec(instructions: Vec<Instruction>) -> Result<Self, VerifyError>
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.
Sourcepub fn instructions(&self) -> &[Instruction]
pub fn instructions(&self) -> &[Instruction]
Returns the verified raw instructions.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the program contains no instructions.
Verified programs are never empty, so this always returns false.
Sourcepub fn translate(&self) -> Result<CodeImage, TranslationError>
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.
Sourcepub fn translate_with_profile(
&self,
profile: InputProfile,
) -> Result<CodeImage, TranslationError>
pub fn translate_with_profile( &self, profile: InputProfile, ) -> Result<CodeImage, TranslationError>
Translates using an explicit input ABI profile.