Skip to content

Commit

Permalink
refactor: document changes
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Jan 20, 2025
1 parent 4969488 commit 1f7c59b
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,29 @@ lazy_static! {
config.native_unwind_info(false);

config.cranelift_opt_level(wasmtime::OptLevel::SpeedAndSize);
config.memory_reservation(0x1000000); // 16MB
config.epoch_interruption(true);

// 16MB should be enough for each WASM module. Each module needs a
// fixed amount of memory that is only a few KB long, plus a variable
// amount that depends on the number of rules and patterns (1 bit per
// rule and 1 bit per pattern). With 16MB there's enough space for
// millions of rules and patterns. By default, this is 4GB in 64-bits
// systems, which causes a reservation of 4GB of virtual address space
// (not physical RAM) per module (and therefore per Scanner). In some
// scenarios where virtual address space is limited (i.e: Docker
// instances) this is problematic. See:
// https://github.com/VirusTotal/yara-x/issues/292
config.memory_reservation(0x1000000);

// WASM memory won't grow, there's no need to allocate space for
// future grow.
config.memory_reservation_for_growth(0);
config.guard_before_linear_memory(false);

// As the memory can't grow, it won't move. By explicitly indicating
// this, modules can be compiled with static knowledge the base pointer
// of linear memory never changes to enable optimizations.
config.memory_may_move(false);
config.epoch_interruption(true);

config
};
pub(crate) static ref ENGINE: Engine = Engine::new(&CONFIG).unwrap();
Expand Down

0 comments on commit 1f7c59b

Please sign in to comment.