Context

Struct Context 

Source
#[repr(C)]
pub struct Context {
Show 14 fields pub regs: [u32; 32], pub pc: u32, pub next_pc: u32, pub mem: ForkableMemory, pub trace_buf: MmapOffset, pub ecall_handler: extern "C" fn(NonNull<Context>), pub ebreak_handler: extern "C" fn(NonNull<Context>), pub undefined_handler: extern "C" fn(NonNull<Context>, u32), pub trace_handler: extern "C" fn(NonNull<Context>), pub trampoline: extern "C" fn(NonNull<Context>) -> JitFn, pub addition: NonNull<dyn Addition>, pub compiler: Box<dyn Compiler>, pub compile_cfg: CompileConfig, pub exit_code: Option<u32>, /* private fields */
}
Expand description

The Context for the zkVMc runtime.

Fields§

§regs: [u32; 32]

Registers.

§pc: u32

Program Counter.

§next_pc: u32

Next Program Counter.

§mem: ForkableMemory

Linear memory between VM and JIT code.

§trace_buf: MmapOffset

Trace buffer for tracing the instructions.

§ecall_handler: extern "C" fn(NonNull<Context>)

Handler function for the ecall instruction.

§ebreak_handler: extern "C" fn(NonNull<Context>)

Handler function for the ebreak instruction.

§undefined_handler: extern "C" fn(NonNull<Context>, u32)

Handler function for an undefined instruction.

§trace_handler: extern "C" fn(NonNull<Context>)

Handler function for the execution traces.

§trampoline: extern "C" fn(NonNull<Context>) -> JitFn

Function called by compiled code or VM to lookup or translate the next compiled code block.

§addition: NonNull<dyn Addition>

Additional context.

§compiler: Box<dyn Compiler>

Compile the code block at pc and return the compiled function.

§compile_cfg: CompileConfig§exit_code: Option<u32>

Exit code of the program.

Implementations§

Source§

impl Context

Source

pub fn new( compiler: Option<Box<dyn Compiler>>, entry: u32, image: FxHashMap<u32, &[u8]>, addition: NonNull<dyn Addition>, cfg: Option<CompileConfig>, ecall_handler: Option<extern "C" fn(NonNull<Context>)>, ebreak_handler: Option<extern "C" fn(NonNull<Context>)>, undefined_handler: Option<extern "C" fn(NonNull<Context>, u32)>, interrupt_handler: Option<extern "C" fn(NonNull<Context>)>, ) -> Context

Source

pub fn update_pc(&mut self)

Source

pub fn write_bytes(&mut self, addr: u32, bytes: &[u8])

Source

pub fn write_word(&mut self, addr: u32, word: u32)

Source

pub fn write_words(&mut self, addr: u32, words: &[u32])

Source

pub fn read_bytes(&self, addr: u32, len: usize) -> &[u8]

Source

pub fn read_word(&self, addr: u32) -> u32

Source

pub fn read_words(&self, addr: u32, len: usize) -> &[u32]

Source

pub fn as_addition<T>(&self) -> &T

Source

pub fn as_addition_mut<T>(&mut self) -> &mut T

Trait Implementations§

Source§

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Reset for Context

Source§

fn reset(&mut self)

Auto Trait Implementations§

§

impl Freeze for Context

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl !Unpin for Context

§

impl !UnwindSafe for Context

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 = 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.