Skip to content

Commit

Permalink
chore(sandbox): use sp-wasm-interface-common instead of sp-wasm-inter…
Browse files Browse the repository at this point in the history
…face (#3603)
  • Loading branch information
clearloop authored Dec 22, 2023
1 parent a650c80 commit 22e28d8
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 174 deletions.
308 changes: 154 additions & 154 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ sp-transaction-storage-proof = { version = "4.0.0-dev", git = "https://github.co
sp-trie = { version = "7.0.0", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes", default-features = false }
sp-version = { version = "5.0.0", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes", default-features = false }
sp-wasm-interface = { version = "7.0.0", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes", default-features = false }
sp-wasm-interface-common = { version = "7.0.0", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes", default-features = false }
substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes" }
substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes" }
substrate-rpc-client = { version = "0.10.0-dev", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes" }
Expand Down
4 changes: 2 additions & 2 deletions sandbox/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ targets = ["x86_64-unknown-linux-gnu"]
codec.workspace = true
sp-core.workspace = true
sp-std.workspace = true
sp-wasm-interface = { workspace = true, default-features = false }
sp-wasm-interface-common = { workspace = true, default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"sp-core/std",
"sp-std/std",
"sp-wasm-interface/std",
"sp-wasm-interface-common/std",
]
2 changes: 1 addition & 1 deletion sandbox/env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use alloc::string::String;
use codec::{Decode, Encode};
use sp_core::RuntimeDebug;
use sp_std::vec::Vec;
use sp_wasm_interface::ReturnValue;
use sp_wasm_interface_common::ReturnValue;

#[derive(Clone, Copy, Debug)]
pub enum Instantiate {
Expand Down
2 changes: 1 addition & 1 deletion sandbox/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sandbox-wasmer.workspace = true
sandbox-wasmer-types.workspace = true
wasmi = { git = "https://github.com/gear-tech/wasmi", branch = "v0.13.2-sign-ext", features = ["virtual_memory"] }
sp-allocator = { workspace = true, features = ["std"] }
sp-wasm-interface = { workspace = true, features = ["std"] }
sp-wasm-interface-common = { workspace = true, features = ["std"] }
gear-sandbox-env = { workspace = true, features = ["std"] }
wasmer-cache = { workspace = true, optional = true }
tempfile.workspace = true
Expand Down
24 changes: 11 additions & 13 deletions sandbox/host/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{collections::HashMap, pin::Pin, rc::Rc};
use codec::Decode;
use env::Instantiate;
use gear_sandbox_env as sandbox_env;
use sp_wasm_interface::{Pointer, WordSize};
use sp_wasm_interface_common::{Pointer, Value, WordSize};

use crate::{
error::{self, Result},
Expand All @@ -50,6 +50,8 @@ use self::{

pub use gear_sandbox_env as env;

type SandboxResult<T> = core::result::Result<T, String>;

/// Index of a function inside the supervisor.
///
/// This is a typically an index in the default table of the supervisor, however
Expand Down Expand Up @@ -143,11 +145,7 @@ pub trait SandboxContext {
) -> Result<i64>;

/// Read memory from `address` into a vector.
fn read_memory_into(
&self,
address: Pointer<u8>,
dest: &mut [u8],
) -> sp_wasm_interface::Result<()>;
fn read_memory_into(&self, address: Pointer<u8>, dest: &mut [u8]) -> SandboxResult<()>;

/// Read memory into the given `dest` buffer from `address`.
fn read_memory(&self, address: Pointer<u8>, size: WordSize) -> Result<Vec<u8>> {
Expand All @@ -157,13 +155,13 @@ pub trait SandboxContext {
}

/// Write the given data at `address` into the memory.
fn write_memory(&mut self, address: Pointer<u8>, data: &[u8]) -> sp_wasm_interface::Result<()>;
fn write_memory(&mut self, address: Pointer<u8>, data: &[u8]) -> SandboxResult<()>;

/// Allocate a memory instance of `size` bytes.
fn allocate_memory(&mut self, size: WordSize) -> sp_wasm_interface::Result<Pointer<u8>>;
fn allocate_memory(&mut self, size: WordSize) -> SandboxResult<Pointer<u8>>;

/// Deallocate a given memory instance.
fn deallocate_memory(&mut self, ptr: Pointer<u8>) -> sp_wasm_interface::Result<()>;
fn deallocate_memory(&mut self, ptr: Pointer<u8>) -> SandboxResult<()>;
}

/// Implementation of [`Externals`] that allows execution of guest module with
Expand Down Expand Up @@ -211,9 +209,9 @@ impl SandboxInstance {
pub fn invoke(
&self,
export_name: &str,
args: &[sp_wasm_interface::Value],
args: &[Value],
sandbox_context: &mut dyn SandboxContext,
) -> std::result::Result<Option<sp_wasm_interface::Value>, error::Error> {
) -> std::result::Result<Option<Value>, error::Error> {
match &self.backend_instance {
BackendInstance::Wasmi(wasmi_instance) => {
wasmi_invoke(self, wasmi_instance, export_name, args, sandbox_context)
Expand All @@ -228,7 +226,7 @@ impl SandboxInstance {
/// Get the value from a global with the given `name`.
///
/// Returns `Some(_)` if the global could be found.
pub fn get_global_val(&self, name: &str) -> Option<sp_wasm_interface::Value> {
pub fn get_global_val(&self, name: &str) -> Option<Value> {
match &self.backend_instance {
BackendInstance::Wasmi(wasmi_instance) => wasmi_get_global(wasmi_instance, name),

Expand All @@ -242,7 +240,7 @@ impl SandboxInstance {
pub fn set_global_val(
&self,
name: &str,
value: sp_wasm_interface::Value,
value: Value,
) -> std::result::Result<Option<()>, error::Error> {
match &self.backend_instance {
BackendInstance::Wasmi(wasmi_instance) => wasmi_set_global(wasmi_instance, name, value),
Expand Down
2 changes: 1 addition & 1 deletion sandbox/host/src/sandbox/wasmer_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sandbox_wasmer_types::TrapCode;

use codec::{Decode, Encode};
use gear_sandbox_env::{HostError, Instantiate, WasmReturnValue, GLOBAL_NAME_GAS};
use sp_wasm_interface::{util, Pointer, ReturnValue, Value, WordSize};
use sp_wasm_interface_common::{util, Pointer, ReturnValue, Value, WordSize};

use crate::{
error::{Error, Result},
Expand Down
2 changes: 1 addition & 1 deletion sandbox/host/src/sandbox/wasmi_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::fmt;

use codec::{Decode, Encode};
use gear_sandbox_env::HostError;
use sp_wasm_interface::{util, Pointer, ReturnValue, Value, WordSize};
use sp_wasm_interface_common::{util, Pointer, ReturnValue, Value, WordSize};
use wasmi::{
memory_units::Pages, ImportResolver, MemoryInstance, Module, ModuleInstance, RuntimeArgs,
RuntimeValue, Trap, TrapCode,
Expand Down
2 changes: 1 addition & 1 deletion sandbox/host/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Utilities used by all backends

use crate::error::Result;
use sp_wasm_interface::Pointer;
use sp_wasm_interface_common::Pointer;

/// Provides safe memory access interface using an external buffer
pub trait MemoryTransfer {
Expand Down

0 comments on commit 22e28d8

Please sign in to comment.