Path: blob/main/crates/fuzzing/src/generators/pooling_config.rs
1693 views
//! Generate instance limits for the pooling allocation strategy.12use arbitrary::{Arbitrary, Unstructured};3use wasmtime::Enabled;45/// Configuration for `wasmtime::PoolingAllocationStrategy`.6#[derive(Debug, Clone, Eq, PartialEq, Hash)]7#[expect(missing_docs, reason = "self-describing field names")]8pub struct PoolingAllocationConfig {9pub total_component_instances: u32,10pub total_core_instances: u32,11pub total_memories: u32,12pub total_tables: u32,13pub total_stacks: u32,1415pub max_memory_size: usize,16pub table_elements: usize,1718pub component_instance_size: usize,19pub max_memories_per_component: u32,20pub max_tables_per_component: u32,2122pub core_instance_size: usize,23pub max_memories_per_module: u32,24pub max_tables_per_module: u32,2526pub table_keep_resident: usize,27pub linear_memory_keep_resident: usize,2829pub decommit_batch_size: usize,30pub max_unused_warm_slots: u32,3132pub async_stack_keep_resident: usize,3334pub memory_protection_keys: Enabled,35pub max_memory_protection_keys: usize,3637pub pagemap_scan: Enabled,38}3940impl PoolingAllocationConfig {41/// Convert the generated limits to Wasmtime limits.42pub fn configure(&self, cfg: &mut wasmtime_cli_flags::CommonOptions) {43cfg.opts.pooling_total_component_instances = Some(self.total_component_instances);44cfg.opts.pooling_total_core_instances = Some(self.total_core_instances);45cfg.opts.pooling_total_memories = Some(self.total_memories);46cfg.opts.pooling_total_tables = Some(self.total_tables);47cfg.opts.pooling_total_stacks = Some(self.total_stacks);4849cfg.opts.pooling_max_memory_size = Some(self.max_memory_size);50cfg.opts.pooling_table_elements = Some(self.table_elements);5152cfg.opts.pooling_max_component_instance_size = Some(self.component_instance_size);53cfg.opts.pooling_max_memories_per_component = Some(self.max_memories_per_component);54cfg.opts.pooling_max_tables_per_component = Some(self.max_tables_per_component);5556cfg.opts.pooling_max_core_instance_size = Some(self.core_instance_size);57cfg.opts.pooling_max_memories_per_module = Some(self.max_memories_per_module);58cfg.opts.pooling_max_tables_per_module = Some(self.max_tables_per_module);5960cfg.opts.pooling_table_keep_resident = Some(self.table_keep_resident);61cfg.opts.pooling_memory_keep_resident = Some(self.linear_memory_keep_resident);6263cfg.opts.pooling_decommit_batch_size = Some(self.decommit_batch_size);64cfg.opts.pooling_max_unused_warm_slots = Some(self.max_unused_warm_slots);6566cfg.opts.pooling_async_stack_keep_resident = Some(self.async_stack_keep_resident);6768cfg.opts.pooling_memory_protection_keys = Some(self.memory_protection_keys);69cfg.opts.pooling_max_memory_protection_keys = Some(self.max_memory_protection_keys);7071cfg.opts.pooling_pagemap_scan = Some(self.pagemap_scan);72}73}7475impl<'a> Arbitrary<'a> for PoolingAllocationConfig {76fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {77const MAX_COUNT: u32 = 100;78const MAX_TABLES: u32 = 100;79const MAX_MEMORIES: u32 = 100;80const MAX_ELEMENTS: usize = 1000;81const MAX_MEMORY_SIZE: usize = 10 * (1 << 20); // 10 MiB82const MAX_SIZE: usize = 1 << 20; // 1 MiB83const MAX_INSTANCE_MEMORIES: u32 = 10;84const MAX_INSTANCE_TABLES: u32 = 10;8586let total_memories = u.int_in_range(1..=MAX_MEMORIES)?;8788Ok(Self {89total_component_instances: u.int_in_range(1..=MAX_COUNT)?,90total_core_instances: u.int_in_range(1..=MAX_COUNT)?,91total_memories,92total_tables: u.int_in_range(1..=MAX_TABLES)?,93total_stacks: u.int_in_range(1..=MAX_COUNT)?,9495max_memory_size: u.int_in_range(0..=MAX_MEMORY_SIZE)?,96table_elements: u.int_in_range(0..=MAX_ELEMENTS)?,9798component_instance_size: u.int_in_range(0..=MAX_SIZE)?,99max_memories_per_component: u.int_in_range(1..=MAX_INSTANCE_MEMORIES)?,100max_tables_per_component: u.int_in_range(1..=MAX_INSTANCE_TABLES)?,101102core_instance_size: u.int_in_range(0..=MAX_SIZE)?,103max_memories_per_module: u.int_in_range(1..=MAX_INSTANCE_MEMORIES)?,104max_tables_per_module: u.int_in_range(1..=MAX_INSTANCE_TABLES)?,105106table_keep_resident: u.int_in_range(0..=1 << 20)?,107linear_memory_keep_resident: u.int_in_range(0..=1 << 20)?,108109decommit_batch_size: u.int_in_range(1..=1000)?,110max_unused_warm_slots: u.int_in_range(0..=total_memories + 10)?,111112async_stack_keep_resident: u.int_in_range(0..=1 << 20)?,113114memory_protection_keys: *u.choose(&[Enabled::Auto, Enabled::No])?,115max_memory_protection_keys: u.int_in_range(1..=20)?,116117pagemap_scan: *u.choose(&[Enabled::Auto, Enabled::No])?,118})119}120}121122123