@@ -74,6 +74,9 @@ pub(crate) struct ScanContext<'r, 'd> {
7474 pub wasm_main_memory : Option < wasmtime:: Memory > ,
7575 /// WASM global variable that contains the value of `filesize`.
7676 pub wasm_filesize : Option < Global > ,
77+ /// WASM global variable that contains a boolean that indicates if
78+ /// pattern search was done.
79+ pub wasm_pattern_search_done : Option < Global > ,
7780 /// Map where keys are object handles and values are objects used during
7881 /// the evaluation of rule conditions. Handles are opaque integer values
7982 /// that can be passed to and received from WASM code. Each handle identify
@@ -357,7 +360,7 @@ impl ScanContext<'_, '_> {
357360 obj_ref
358361 }
359362
360- /// Get the value of the global variable `filesize`.
363+ /// Gets the value of the global variable `filesize`.
361364 pub ( crate ) fn get_filesize ( & mut self ) -> i64 {
362365 self . wasm_filesize . unwrap ( ) . get ( self . wasm_store_mut ( ) ) . i64 ( ) . unwrap ( )
363366 }
@@ -370,13 +373,22 @@ impl ScanContext<'_, '_> {
370373 . unwrap ( ) ;
371374 }
372375
376+ /// Sets the value of the flag that indicates if the pattern search
377+ /// phase was already executed.
378+ pub ( crate ) fn set_pattern_search_done ( & mut self , done : bool ) {
379+ self . wasm_pattern_search_done
380+ . unwrap ( )
381+ . set ( self . wasm_store_mut ( ) , Val :: I32 ( done as i32 ) )
382+ . unwrap ( ) ;
383+ }
384+
373385 /// Sets a timeout for scan operations.
374386 pub ( crate ) fn set_timeout ( & mut self , timeout : Duration ) -> & mut Self {
375387 self . scan_timeout = Some ( timeout) ;
376388 self
377389 }
378390
379- /// Invoke the main function, which evaluates the rules' conditions. It
391+ /// Invokes the main function, which evaluates the rules' conditions. It
380392 /// calls ScanContext::search_for_patterns (which does the Aho-Corasick
381393 /// scanning) only if necessary.
382394 ///
@@ -1032,6 +1044,9 @@ impl ScanContext<'_, '_> {
10321044 _ => unreachable ! ( ) ,
10331045 } ;
10341046
1047+ // Indicate that the pattern search phase was already done.
1048+ self . set_pattern_search_done ( true ) ;
1049+
10351050 #[ cfg( any( feature = "rules-profiling" , feature = "logging" ) ) ]
10361051 let scan_end = self . clock . raw ( ) ;
10371052
@@ -1789,6 +1804,7 @@ pub fn create_wasm_store_and_ctx<'r>(
17891804 wasm_main_memory : None ,
17901805 wasm_main_func : None ,
17911806 wasm_filesize : None ,
1807+ wasm_pattern_search_done : None ,
17921808 module_outputs : FxHashMap :: default ( ) ,
17931809 user_provided_module_outputs : FxHashMap :: default ( ) ,
17941810 pattern_matches : PatternMatches :: new ( ) ,
@@ -1915,6 +1931,7 @@ pub fn create_wasm_store_and_ctx<'r>(
19151931 ctx. wasm_main_memory = Some ( main_memory) ;
19161932 ctx. wasm_main_func = Some ( main_fn) ;
19171933 ctx. wasm_filesize = Some ( filesize) ;
1934+ ctx. wasm_pattern_search_done = Some ( pattern_search_done) ;
19181935
19191936 wasm_store
19201937}
0 commit comments