From a0356072f23ddac70a8b8db4d1f4f40744120ae5 Mon Sep 17 00:00:00 2001 From: wucke13 Date: Wed, 3 Jul 2024 11:19:55 +0200 Subject: [PATCH] feat: allow state in HookSet This is quite useful for example when doing statement coverage. One could store a MPSC tx end inside a BranchHookSet in order to send the current program counter on every branching instruction. Stateless are still possible and should be zero cost, they can be implemented by just using an empty struct on which the HookSet trait is implemented. --- src/execution/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/execution/mod.rs b/src/execution/mod.rs index 660703213..9e3c0eba8 100644 --- a/src/execution/mod.rs +++ b/src/execution/mod.rs @@ -1,5 +1,3 @@ -use core::marker::PhantomData; - use alloc::vec::Vec; use value_stack::Stack; @@ -35,12 +33,12 @@ where wasm_bytecode: &'b [u8], types: Vec, store: Store, - hook_set: PhantomData, + pub hook_set: H, } impl<'b> RuntimeInstance<'b, EmptyHookSet> { pub fn new(validation_info: &'_ ValidationInfo<'b>) -> Result { - Self::new_with_hooks(validation_info) + Self::new_with_hooks(validation_info, EmptyHookSet) } } @@ -48,7 +46,7 @@ impl<'b, H> RuntimeInstance<'b, H> where H: HookSet, { - pub fn new_with_hooks(validation_info: &'_ ValidationInfo<'b>) -> Result { + pub fn new_with_hooks(validation_info: &'_ ValidationInfo<'b>, hook_set: H) -> Result { trace!("Starting instantiation of bytecode"); let store = Self::init_store(validation_info); @@ -57,7 +55,7 @@ where wasm_bytecode: validation_info.wasm, types: validation_info.types.clone(), store, - hook_set: PhantomData, + hook_set, }; if let Some(start) = validation_info.start {