Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 6ba14dd

Browse files
committed
Rename TrampolineState to EnvState.
1 parent c817233 commit 6ba14dd

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

core/executor/src/wasmtime/runtime.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::error::{Error, Result, WasmError};
2020
use crate::host_interface::SubstrateExternals;
2121
use crate::wasm_runtime::WasmRuntime;
2222
use crate::wasmtime::function_executor::FunctionExecutorState;
23-
use crate::wasmtime::trampoline::{TrampolineState, make_trampoline};
23+
use crate::wasmtime::trampoline::{EnvState, make_trampoline};
2424
use crate::wasmtime::util::{cranelift_ir_signature, read_memory_into, write_memory_from};
2525
use crate::{Externalities, RuntimeVersion};
2626

@@ -182,7 +182,7 @@ fn call_method(
182182
unsafe { mem::transmute::<_, &'static mut Compiler>(context.compiler_mut()) },
183183
get_heap_base(&instance)?,
184184
);
185-
reset_host_state(context, Some(executor_state))?;
185+
reset_env_state(context, Some(executor_state))?;
186186

187187
// Write the input data into guest memory.
188188
let (data_ptr, data_len) = inject_input_data(context, &mut instance, data)?;
@@ -194,7 +194,7 @@ fn call_method(
194194
.invoke(&mut instance, method, &args[..])
195195
.map_err(Error::Wasmtime)
196196
})?;
197-
let trap_error = reset_host_state(context, None)?;
197+
let trap_error = reset_env_state(context, None)?;
198198
let (output_ptr, output_len) = match outcome {
199199
ActionOutcome::Returned { values } => {
200200
if values.len() != 1 {
@@ -260,7 +260,7 @@ fn instantiate_env_module(global_exports: Rc<RefCell<HashMap<String, Option<Expo
260260
let imports = Imports::none();
261261
let data_initializers = Vec::new();
262262
let signatures = PrimaryMap::new();
263-
let host_state = TrampolineState::new::<SubstrateExternals>(code_memory);
263+
let env_state = EnvState::new::<SubstrateExternals>(code_memory);
264264

265265
let result = InstanceHandle::new(
266266
Rc::new(module),
@@ -270,7 +270,7 @@ fn instantiate_env_module(global_exports: Rc<RefCell<HashMap<String, Option<Expo
270270
&data_initializers,
271271
signatures.into_boxed_slice(),
272272
None,
273-
Box::new(host_state),
273+
Box::new(env_state),
274274
);
275275
result.map_err(|e| WasmError::WasmtimeSetup(SetupError::Instantiate(e)))
276276
}
@@ -305,30 +305,30 @@ fn grow_memory(instance: &mut InstanceHandle, pages: u32) -> Result<()> {
305305
.ok_or_else(|| "requested heap_pages would exceed maximum memory size".into())
306306
}
307307

308-
fn get_host_state(context: &mut Context) -> Result<&mut TrampolineState> {
308+
fn get_env_state(context: &mut Context) -> Result<&mut EnvState> {
309309
let env_instance = context.get_instance("env")
310310
.map_err(|err| format!("cannot find \"env\" module: {}", err))?;
311311
env_instance
312312
.host_state()
313-
.downcast_mut::<TrampolineState>()
313+
.downcast_mut::<EnvState>()
314314
.ok_or_else(|| "cannot get \"env\" module host state".into())
315315
}
316316

317-
fn reset_host_state(context: &mut Context, executor_state: Option<FunctionExecutorState>)
317+
fn reset_env_state(context: &mut Context, executor_state: Option<FunctionExecutorState>)
318318
-> Result<Option<Error>>
319319
{
320-
let trampoline_state = get_host_state(context)?;
321-
trampoline_state.executor_state = executor_state;
322-
Ok(trampoline_state.reset_trap())
320+
let env_state = get_env_state(context)?;
321+
env_state.executor_state = executor_state;
322+
Ok(env_state.take_trap())
323323
}
324324

325325
fn inject_input_data(
326326
context: &mut Context,
327327
instance: &mut InstanceHandle,
328328
data: &[u8],
329329
) -> Result<(Pointer<u8>, WordSize)> {
330-
let trampoline_state = get_host_state(context)?;
331-
let executor_state = trampoline_state.executor_state
330+
let env_state = get_env_state(context)?;
331+
let executor_state = env_state.executor_state
332332
.as_mut()
333333
.ok_or_else(|| "cannot get \"env\" module executor state")?;
334334

core/executor/src/wasmtime/trampoline.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::wasmtime::function_executor::{FunctionExecutorState, FunctionExecutor
3232

3333
/// The top-level host state of the "env" module. This state is used by the trampoline function to
3434
/// construct a `FunctionExecutor` which can execute the host call.
35-
pub struct TrampolineState {
35+
pub struct EnvState {
3636
externals: &'static [&'static dyn Function],
3737
trap: Option<Error>,
3838
/// The executor state stored across host calls during a single Wasm runtime call.
@@ -43,10 +43,10 @@ pub struct TrampolineState {
4343
code_memory: CodeMemory,
4444
}
4545

46-
impl TrampolineState {
47-
/// Construct a new `TrampolineState` which owns the given code memory.
46+
impl EnvState {
47+
/// Construct a new `EnvState` which owns the given code memory.
4848
pub fn new<HF: HostFunctions>(code_memory: CodeMemory) -> Self {
49-
TrampolineState {
49+
EnvState {
5050
externals: HF::functions(),
5151
trap: None,
5252
executor_state: None,
@@ -55,15 +55,15 @@ impl TrampolineState {
5555
}
5656

5757
/// Resets the trap error to None and returns the current value.
58-
pub fn reset_trap(&mut self) -> Option<Error> {
59-
mem::replace(&mut self.trap, None)
58+
pub fn take_trap(&mut self) -> Option<Error> {
59+
self.trap.take()
6060
}
6161
}
6262

6363
/// This is called by the dynamically generated trampoline taking the function index and reference
6464
/// to the call arguments on the stack as arguments. Returns 0 on success and 1 on an error.
6565
unsafe extern "C" fn stub_fn(vmctx: *mut VMContext, func_index: u32, values_vec: *mut i64) -> u32 {
66-
if let Some(state) = (*vmctx).host_state().downcast_mut::<TrampolineState>() {
66+
if let Some(state) = (*vmctx).host_state().downcast_mut::<EnvState>() {
6767
match stub_fn_inner(
6868
vmctx,
6969
state.externals,

0 commit comments

Comments
 (0)