dharitri_vm_executor/
instance.rs

1use crate::{BreakpointValue, ExecutorError};
2
3pub struct CompilationOptions {
4    pub gas_limit: u64,
5    pub unmetered_locals: usize,
6    pub max_memory_grow: usize,
7    pub max_memory_grow_delta: usize,
8    pub opcode_trace: bool,
9    pub metering: bool,
10    pub runtime_breakpoints: bool,
11}
12
13/// The argument type for dealing with executor memory pointers.
14pub type MemPtr = isize;
15
16/// The argument type for dealing with lengths of slices of the executor memory.
17pub type MemLength = isize;
18
19pub trait Instance {
20    /// Calls an exported function of a WebAssembly instance by `name`.
21    fn call(&self, func_name: &str) -> Result<(), String>;
22
23    /// Checks that all public module functions (SC endpoints) have no arguments or results.
24    fn check_signatures(&self) -> bool;
25
26    /// Checks whether SC has an endpoint with given name.
27    fn has_function(&self, func_name: &str) -> bool;
28
29    /// Required to be able to extract all SC endpoint names.
30    fn get_exported_function_names(&self) -> Vec<String>;
31
32    /// Sets the number of points(gas) limit for the given instance.
33    fn set_points_limit(&self, limit: u64) -> Result<(), String>;
34
35    /// Sets the number of points(gas) for the given instance.
36    fn set_points_used(&self, points: u64) -> Result<(), String>;
37
38    /// Returns the number of points(gas) used by the given instance.
39    fn get_points_used(&self) -> Result<u64, String>;
40
41    /// Gets the size in bytes of the memory data.
42    fn memory_length(&self) -> Result<u64, String>;
43
44    /// Gets a pointer to the beginning of the contiguous memory data bytes.
45    fn memory_ptr(&self) -> Result<*mut u8, String>;
46
47    /// Loads data from executor memory.
48    fn memory_load(&self, mem_ptr: MemPtr, mem_length: MemLength) -> Result<&[u8], ExecutorError>;
49
50    /// Loads data from executor memory.
51    fn memory_store(&self, mem_ptr: MemPtr, data: &[u8]) -> Result<(), ExecutorError>;
52
53    /// Grows a memory by the given number of pages (of 65Kb each).
54    fn memory_grow(&self, by_num_pages: u32) -> Result<u32, ExecutorError>;
55
56    /// Sets the runtime breakpoint value for the given instance.
57    fn set_breakpoint_value(&self, value: BreakpointValue) -> Result<(), String>;
58
59    /// Returns the runtime breakpoint value from the given instance.
60    fn get_breakpoint_value(&self) -> Result<BreakpointValue, String>;
61
62    /// Resets an instance, cleaning memories and globals.
63    fn reset(&self) -> Result<(), String>;
64
65    /// Caches an instance.
66    fn cache(&self) -> Result<Vec<u8>, String>;
67}