Skip to content

Commit

Permalink
feat: ensure Scanner is UnwindSafe
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed Sep 22, 2024
1 parent 4350230 commit 2bdb244
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion boreal/src/matcher/validator/dfa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::sync::Arc;

use regex_automata::hybrid::dfa::{Builder, Cache, DFA};
Expand All @@ -11,7 +12,7 @@ use crate::matcher::widener::widen_hir;
use crate::matcher::{MatchType, Modifiers};
use crate::regex::{regex_hir_to_string, Hir};

type PoolCreateFn = Box<dyn Fn() -> Cache + Send + Sync>;
type PoolCreateFn = Box<dyn Fn() -> Cache + Send + Sync + UnwindSafe + RefUnwindSafe>;

#[derive(Debug)]
pub(crate) struct DfaValidator {
Expand Down
2 changes: 1 addition & 1 deletion boreal/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub use self::cuckoo::{Cuckoo, CuckooData};
///
/// - As dynamic values, whose shape depend on the memory being scanned. This often includes
/// arrays such as `elf.sections`, or raw values such as `pe.machine`.
pub trait Module: Send + Sync {
pub trait Module: Send + Sync + UnwindSafe + RefUnwindSafe {
/// Name of the module, used in `import` clauses.
fn get_name(&self) -> &'static str;

Expand Down
6 changes: 5 additions & 1 deletion boreal/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,9 @@ impl std::fmt::Display for DefineSymbolError {
#[cfg(test)]
mod tests {
use crate::module::{EvalContext, ScanContext, StaticValue, Type, Value as ModuleValue};
use crate::test_helpers::{test_type_traits, test_type_traits_non_clonable};
use crate::test_helpers::{
test_type_traits, test_type_traits_non_clonable, test_type_unwind_safe,
};
use crate::Compiler;

use super::*;
Expand Down Expand Up @@ -1515,6 +1517,8 @@ mod tests {
Vec::new(),
BytesPool::default(),
));
test_type_unwind_safe::<Scanner>();

test_type_traits_non_clonable(ScanResult {
matched_rules: Vec::new(),
module_values: Vec::new(),
Expand Down
6 changes: 5 additions & 1 deletion boreal/src/test_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::panic::{RefUnwindSafe, UnwindSafe};

use boreal_parser::hex_string::parse_hex_string;
use boreal_parser::regex::parse_regex;

Expand All @@ -19,9 +21,11 @@ pub fn expr_to_hir(expr: &str) -> Hir {
pub fn test_type_traits<T: Clone + std::fmt::Debug + Send + Sync>(t: T) {
#[allow(clippy::redundant_clone)]
let _r = t.clone();
let _r = format!("{:?}", &t);
test_type_traits_non_clonable(t);
}

pub fn test_type_traits_non_clonable<T: std::fmt::Debug + Send + Sync>(t: T) {
let _r = format!("{:?}", &t);
}

pub fn test_type_unwind_safe<T: UnwindSafe + RefUnwindSafe>() {}

0 comments on commit 2bdb244

Please sign in to comment.