dharitri_vm_executor/
instance.rs

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