Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Align to review comments
  • Loading branch information
koute committed Nov 22, 2021
commit c1b974bb28d5c4a3a902bd66c180930b286891cc
20 changes: 12 additions & 8 deletions client/executor/wasmtime/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ impl<'a, 'b> Sandbox for HostContext<'a, 'b> {
.take()
.expect("sandbox store is only empty when borrowed");

// The `catch_unwind` is probably unnecessary here, but let's do it just
// in case so that we can properly unborrow the sandbox store.
// Catch any potential panics so that we can properly restore the sandbox store
// which we've destructively borrowed.
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
store.instantiate(
wasm,
Expand All @@ -292,12 +292,16 @@ impl<'a, 'b> Sandbox for HostContext<'a, 'b> {

self.host_state_mut().sandbox_store.0 = Some(store);

let instance_idx_or_err_code =
match result.expect("instantiating the sandbox does not panic") {
Ok(instance) => instance.register(&mut self.sandbox_store_mut(), dispatch_thunk),
Err(sandbox::InstantiationError::StartTrapped) => sandbox_primitives::ERR_EXECUTION,
Err(_) => sandbox_primitives::ERR_MODULE,
};
let result = match result {
Ok(result) => result,
Err(error) => std::panic::resume_unwind(error),
};

let instance_idx_or_err_code = match result {
Ok(instance) => instance.register(&mut self.sandbox_store_mut(), dispatch_thunk),
Err(sandbox::InstantiationError::StartTrapped) => sandbox_primitives::ERR_EXECUTION,
Err(_) => sandbox_primitives::ERR_MODULE,
};

Ok(instance_idx_or_err_code as u32)
}
Expand Down
6 changes: 0 additions & 6 deletions client/executor/wasmtime/src/instance_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ impl EntryPoint {
/// routines.
pub struct InstanceWrapper {
instance: Instance,

// The memory instance of the `instance`.
//
// It is important to make sure that we don't make any copies of this to make it easier to
// proof See `memory_as_slice` and `memory_as_slice_mut`.
memory: Memory,

store: Store,
}

Expand Down