#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
pub use gear_sandbox_host::sandbox::{SandboxBackend, env::Instantiate};
use sp_runtime_interface::{Pointer, runtime_interface};
use sp_wasm_interface::HostPointer;
#[cfg(feature = "std")]
pub mod detail;
#[cfg(feature = "std")]
pub use detail::init;
#[runtime_interface(wasm_only)]
pub trait Sandbox {
fn instantiate(
&mut self,
dispatch_thunk_id: u32,
wasm_code: &[u8],
raw_env_def: &[u8],
state_ptr: Pointer<u8>,
) -> u32 {
detail::instantiate(
*self,
dispatch_thunk_id,
wasm_code,
raw_env_def,
state_ptr,
Instantiate::Version1,
)
}
#[version(2)]
fn instantiate(
&mut self,
dispatch_thunk_id: u32,
wasm_code: &[u8],
raw_env_def: &[u8],
state_ptr: Pointer<u8>,
) -> u32 {
detail::instantiate(
*self,
dispatch_thunk_id,
wasm_code,
raw_env_def,
state_ptr,
Instantiate::Version2,
)
}
fn invoke(
&mut self,
instance_idx: u32,
function: &str,
args: &[u8],
return_val_ptr: Pointer<u8>,
return_val_len: u32,
state_ptr: Pointer<u8>,
) -> u32 {
detail::invoke(
*self,
instance_idx,
function,
args,
return_val_ptr,
return_val_len,
state_ptr,
)
}
fn memory_new(&mut self, initial: u32, maximum: u32) -> u32 {
detail::memory_new(*self, initial, maximum)
}
fn memory_get(
&mut self,
memory_idx: u32,
offset: u32,
buf_ptr: Pointer<u8>,
buf_len: u32,
) -> u32 {
detail::memory_get(*self, memory_idx, offset, buf_ptr, buf_len)
}
fn memory_set(
&mut self,
memory_idx: u32,
offset: u32,
val_ptr: Pointer<u8>,
val_len: u32,
) -> u32 {
detail::memory_set(*self, memory_idx, offset, val_ptr, val_len)
}
fn memory_teardown(&mut self, memory_idx: u32) {
detail::memory_teardown(*self, memory_idx)
}
fn instance_teardown(&mut self, instance_idx: u32) {
detail::instance_teardown(*self, instance_idx)
}
fn get_global_val(
&mut self,
instance_idx: u32,
name: &str,
) -> Option<sp_wasm_interface::Value> {
detail::get_global_val(*self, instance_idx, name)
}
fn set_global_val(
&mut self,
instance_idx: u32,
name: &str,
value: sp_wasm_interface::Value,
) -> u32 {
detail::set_global_val(*self, instance_idx, name, value)
}
fn memory_grow(&mut self, memory_idx: u32, size: u32) -> u32 {
detail::memory_grow(*self, memory_idx, size)
}
fn memory_size(&mut self, memory_idx: u32) -> u32 {
detail::memory_size(*self, memory_idx)
}
fn get_buff(&mut self, memory_idx: u32) -> HostPointer {
detail::get_buff(*self, memory_idx)
}
fn get_instance_ptr(&mut self, instance_id: u32) -> HostPointer {
detail::get_instance_ptr(*self, instance_id)
}
}