diff --git a/common/state/src/plugin/exports.rs b/common/state/src/plugin/exports.rs index 983cdcca42..9b96af34f0 100644 --- a/common/state/src/plugin/exports.rs +++ b/common/state/src/plugin/exports.rs @@ -28,7 +28,7 @@ fn print_impl( .map_err(|error| { tracing::error!( "Logging message from plugin {} failed with {:?}!", - env.name, + env.name(), error ); wasmer_wasix_types::wasi::Errno::Memviolation @@ -38,12 +38,12 @@ fn print_impl( .map_err(|error| { tracing::error!( "Logging message from plugin {} failed with {}!", - env.name, + env.name(), error ); wasmer_wasix_types::wasi::Errno::Inval }) - .map(|msg| tracing::info!("[{}]: {}", env.name, msg)) + .map(|msg| tracing::info!("[{}]: {}", env.name(), msg)) }) } diff --git a/common/state/src/plugin/module.rs b/common/state/src/plugin/module.rs index f087050f85..e466b4a76f 100644 --- a/common/state/src/plugin/module.rs +++ b/common/state/src/plugin/module.rs @@ -65,7 +65,7 @@ impl PluginModule { len: ::Offset, ) -> ::Offset { let out = match env.data().read_serialized(&env.as_store_ref(), ptr, len) { - Ok(data) => retrieve_action(&env.data().ecs, data), + Ok(data) => retrieve_action(&env.data().ecs(), data), Err(e) => Err(RetrieveError::BincodeError(e.to_string())), }; diff --git a/common/state/src/plugin/wasm_env.rs b/common/state/src/plugin/wasm_env.rs index 8ed95c7dd3..94df40beb8 100644 --- a/common/state/src/plugin/wasm_env.rs +++ b/common/state/src/plugin/wasm_env.rs @@ -11,14 +11,14 @@ use super::{ #[derive(Clone)] pub struct HostFunctionEnvironment { - pub ecs: Arc, /* This represent the pointer to the ECS object (set to - * i32::MAX if to ECS is - * availible) */ - pub memory: Option, // This object represent the WASM Memory - pub allocator: Option< + ecs: Arc, /* This represent the pointer to the ECS object (set to + * i32::MAX if to ECS is + * availible) */ + memory: Option, // This object represent the WASM Memory + allocator: Option< TypedFunction<::Offset, WasmPtr>, >, /* Linked to: wasm_prepare_buffer */ - pub name: String, // This represent the plugin name + name: String, // This represent the plugin name } pub struct HostFunctionEnvironmentInit { @@ -40,6 +40,7 @@ impl core::fmt::Display for HostFunctionException { impl std::error::Error for HostFunctionException {} impl HostFunctionEnvironment { + /// Create a new environment for functions providing functionality to WASM pub fn new(name: String, ecs: Arc) -> Self { Self { ecs, @@ -50,24 +51,24 @@ impl HostFunctionEnvironment { } #[inline] - pub fn ecs(&self) -> &Arc { &self.ecs } + pub(crate) fn ecs(&self) -> &Arc { &self.ecs } #[inline] - pub fn memory(&self) -> &Memory { self.memory.as_ref().unwrap() } + pub(crate) fn memory(&self) -> &Memory { self.memory.as_ref().unwrap() } #[inline] - pub fn allocator( + pub(crate) fn allocator( &self, ) -> &TypedFunction<::Offset, WasmPtr> { self.allocator.as_ref().unwrap() } #[inline] - pub fn name(&self) -> &str { &self.name } + pub(crate) fn name(&self) -> &str { &self.name } /// This function is a safe interface to WASM memory that serializes and /// writes an object to linear memory returning a pointer - pub fn write_serialized_with_length( + pub(crate) fn write_serialized_with_length( &self, store: &mut StoreMut, object: &T, @@ -77,7 +78,7 @@ impl HostFunctionEnvironment { /// This function is a safe interface to WASM memory that reads memory from /// pointer and length returning an object - pub fn read_serialized( + pub(crate) fn read_serialized( &self, store: &StoreRef, position: WasmPtr, @@ -88,7 +89,7 @@ impl HostFunctionEnvironment { /// This function is a safe interface to WASM memory that reads memory from /// a pointer and a length and returns some bytes - pub fn read_bytes( + pub(crate) fn read_bytes( &self, store: &StoreRef, ptr: WasmPtr, @@ -97,6 +98,8 @@ impl HostFunctionEnvironment { memory_manager::read_bytes(self.memory(), store, ptr, len) } + /// This function creates the argument for init_with_instance() from + /// exported symbol lookup pub fn args_from_instance( store: &Store, instance: &Instance, @@ -108,6 +111,7 @@ impl HostFunctionEnvironment { Ok(HostFunctionEnvironmentInit { memory, allocator }) } + /// Initialize the wasm exports in the environment pub fn init_with_instance(&mut self, args: HostFunctionEnvironmentInit) { self.memory = Some(args.memory); self.allocator = Some(args.allocator);