polkavm_common::program

Struct ProgramBlob

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

A partially deserialized PolkaVM program.

Implementations§

Source§

impl ProgramBlob

Source

pub fn blob_length(raw_blob: &[u8]) -> Option<BlobLen>

Parses the blob length information from the given raw_blob bytes.

Returns None if raw_blob doesn’t contain enough bytes to read the length.

Source

pub fn parse(bytes: ArcBytes) -> Result<Self, ProgramParseError>

Parses the given bytes into a program blob.

Source

pub fn from_parts(parts: ProgramParts) -> Result<Self, ProgramParseError>

Creates a program blob from parts.

Source

pub fn is_64_bit(&self) -> bool

Returns whether the blob contains a 64-bit program.

Source

pub fn unique_hash(&self, include_debug: bool) -> Hash

Calculates an unique hash of the program blob.

Source

pub fn ro_data(&self) -> &[u8]

Returns the contents of the read-only data section.

This only covers the initial non-zero portion of the section; use ro_data_size to get the full size.

Source

pub fn ro_data_size(&self) -> u32

Returns the size of the read-only data section.

This can be larger than the length of ro_data, in which case the rest of the space is assumed to be filled with zeros.

Source

pub fn rw_data(&self) -> &[u8]

Returns the contents of the read-write data section.

This only covers the initial non-zero portion of the section; use rw_data_size to get the full size.

Source

pub fn rw_data_size(&self) -> u32

Returns the size of the read-write data section.

This can be larger than the length of rw_data, in which case the rest of the space is assumed to be filled with zeros.

Source

pub fn stack_size(&self) -> u32

Returns the initial size of the stack.

Source

pub fn code(&self) -> &[u8]

Returns the program code in its raw form.

Source

pub fn bitmask(&self) -> &[u8]

Returns the code bitmask in its raw form.

Source

pub fn imports(&self) -> Imports<'_>

Source

pub fn exports(&self) -> impl Iterator<Item = ProgramExport<&[u8]>> + Clone

Returns an iterator over program exports.

Source

pub fn visit<T>(&self, dispatch_table: T, visitor: &mut T::State)
where T: OpcodeVisitor<ReturnTy = ()>,

Visits every instrution in the program.

Source

pub fn instructions<I>(&self, instruction_set: I) -> Instructions<'_, I>
where I: InstructionSet,

Returns an iterator over all of the instructions in the program.

WARNING: this is unbounded and has O(n) complexity; just creating this iterator can iterate over the whole program, even if next is never called!

Source

pub fn instructions_bounded_at<I>( &self, instruction_set: I, offset: ProgramCounter, ) -> Instructions<'_, I>
where I: InstructionSet,

Returns an interator over instructions starting at a given offset.

This iterator is bounded and has O(1) complexity.

Source

pub fn is_jump_target_valid<I>( &self, instruction_set: I, target: ProgramCounter, ) -> bool
where I: InstructionSet,

Returns whether the given program counter is a valid target for a jump.

Source

pub fn jump_table(&self) -> JumpTable<'_>

Returns a jump table.

Source

pub fn get_debug_string(&self, offset: u32) -> Result<&str, ProgramParseError>

Returns the debug string for the given relative offset.

Source

pub fn get_debug_line_program_at( &self, program_counter: ProgramCounter, ) -> Result<Option<LineProgram<'_>>, ProgramParseError>

Returns the line program for the given instruction.

Trait Implementations§

Source§

impl Clone for ProgramBlob

Source§

fn clone(&self) -> ProgramBlob

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ProgramBlob

Source§

fn default() -> ProgramBlob

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.