Struct wasm_smith::Config
source · pub struct Config {Show 58 fields
pub available_imports: Option<Vec<u8>>,
pub exports: Option<Vec<u8>>,
pub allow_start_export: bool,
pub allowed_instructions: InstructionKinds,
pub bulk_memory_enabled: bool,
pub canonicalize_nans: bool,
pub disallow_traps: bool,
pub exceptions_enabled: bool,
pub export_everything: bool,
pub gc_enabled: bool,
pub generate_custom_sections: bool,
pub max_aliases: usize,
pub max_components: usize,
pub max_data_segments: usize,
pub max_element_segments: usize,
pub max_elements: usize,
pub max_exports: usize,
pub max_funcs: usize,
pub max_globals: usize,
pub max_imports: usize,
pub max_instances: usize,
pub max_instructions: usize,
pub max_memories: usize,
pub max_memory32_pages: u64,
pub max_memory64_pages: u64,
pub max_modules: usize,
pub max_nesting_depth: usize,
pub max_table_elements: u32,
pub max_tables: usize,
pub max_tags: usize,
pub max_type_size: u32,
pub max_types: usize,
pub max_values: usize,
pub memory64_enabled: bool,
pub memory_max_size_required: bool,
pub memory_offset_choices: MemoryOffsetChoices,
pub min_data_segments: usize,
pub min_element_segments: usize,
pub min_elements: usize,
pub min_exports: usize,
pub min_funcs: usize,
pub min_globals: usize,
pub min_imports: usize,
pub min_memories: u32,
pub min_tables: u32,
pub min_tags: usize,
pub min_types: usize,
pub min_uleb_size: u8,
pub multi_value_enabled: bool,
pub reference_types_enabled: bool,
pub relaxed_simd_enabled: bool,
pub saturating_float_to_int_enabled: bool,
pub sign_extension_ops_enabled: bool,
pub simd_enabled: bool,
pub tail_call_enabled: bool,
pub table_max_size_required: bool,
pub threads_enabled: bool,
pub allow_invalid_funcs: bool,
}
Expand description
Configuration for a generated module.
Don’t care to configure your generated modules? Just use
Module::arbitrary
, which internally uses the default
configuration.
Want control over the shape of the module that gets generated? Create a
Config
and then pass it to Module::new
.
§Swarm Testing
You can use the Arbitrary for Config
implementation for swarm
testing. This will dynamically – but still deterministically – choose
configuration options for you.
Note that we pick only maximums, not minimums, here because it is more
complex to describe the domain of valid configs when minima are involved
(min <= max
for each variable) and minima are mostly used to ensure
certain elements are present, but do not widen the range of generated
Wasm modules.
Fields§
§available_imports: Option<Vec<u8>>
The imports that may be used when generating the module.
Defaults to None
which means that any arbitrary import can be
generated.
To only allow specific imports, set this field to a WebAssembly module which describes the imports allowed.
Note that Self::min_imports
is ignored when
available_imports
are enabled.
The provided value must be a valid binary encoding of a
WebAssembly module. wasm-smith
will panic if the module cannot
be parsed.
§Example
An implementation of this method could use the wat
crate to
provide a human-readable and maintainable description:
Some(wat::parse_str(r#"
(module
(import "env" "ping" (func (param i32)))
(import "env" "pong" (func (result i32)))
(import "env" "memory" (memory 1))
(import "env" "table" (table 1))
(import "env" "tag" (tag (param i32)))
)
"#))
exports: Option<Vec<u8>>
If provided, the generated module will have exports with exactly the same names and types as those in the provided WebAssembly module. The implementation (e.g. function bodies, global initializers) of each export in the generated module will be random and unrelated to the implementation in the provided module. Only globals and functions are supported.
Defaults to None
which means arbitrary exports will be
generated.
To specify which exports the generated modules should have, set this field to a WebAssembly module which describes the desired exports. To generate modules with varying exports that meet some constraints, consider randomly generating the value for this field.
The provided value must be a valid binary encoding of a
WebAssembly module. wasm-smith
will panic if the module cannot
be parsed.
§Module Limits
All types, functions, globals, and exports that are needed to
provide the required exports will be generated, even if it
causes the resulting module to exceed the limits defined in
Self::max_type_size
, Self::max_types
,
Self::max_funcs
, Self::max_globals
, or
Self::max_exports
.
§Example
As for Self::available_imports
, the wat
crate can be used
to provide an human-readable description of the desired exports:
Some(wat::parse_str(r#"
(module
(func (export "foo") (param i32) (result i64) unreachable)
(global (export "bar") f32 f32.const 0)
)
"#));
allow_start_export: bool
Determines whether a start
export may be included. Defaults to true
.
allowed_instructions: InstructionKinds
The kinds of instructions allowed in the generated wasm programs. Defaults to all.
The categories of instructions match the categories used by the WebAssembly specification; e.g., numeric, vector, control, memory, etc.
Note that modifying this setting is separate from the proposal
flags; that is, if simd_enabled() == true
but
allowed_instruction()
does not include vector instructions, the
generated programs will not include these instructions but could
contain vector types.
bulk_memory_enabled: bool
Determines whether the bulk memory proposal is enabled for generating instructions.
Defaults to false
.
canonicalize_nans: bool
Returns whether NaN values are canonicalized after all f32/f64 operation. Defaults to false.
This can be useful when a generated wasm module is executed in multiple runtimes which may produce different NaN values. This ensures that the generated module will always use the same NaN representation for all instructions which have visible side effects, for example writing floats to memory or float-to-int bitcast instructions.
disallow_traps: bool
Returns whether we should avoid generating code that will possibly trap.
For some trapping instructions, this will emit extra instructions to ensure they don’t trap, while some instructions will simply be excluded. In cases where we would run into a trap, we instead choose some arbitrary non-trapping behavior. For example, if we detect that a Load instruction would attempt to access out-of-bounds memory, we instead pretend the load succeeded and push 0 onto the stack.
One type of trap that we can’t currently avoid is
StackOverflow. Even when disallow_traps
is set to true, wasm-smith
will eventually generate a program that infinitely recurses, causing
the call stack to be exhausted.
Defaults to false
.
exceptions_enabled: bool
Determines whether the exception-handling proposal is enabled for generating instructions.
Defaults to false
.
export_everything: bool
Export all WebAssembly objects in the module. Defaults to false.
This overrides Config::min_exports
and Config::max_exports
.
gc_enabled: bool
Determines whether the GC proposal is enabled when generating a Wasm module.
Defaults to false
.
generate_custom_sections: bool
Returns whether we should generate custom sections or not. Defaults to false.
max_aliases: usize
Returns the maximal size of the alias
section. Defaults to 1000.
max_components: usize
The maximum number of components to use. Defaults to 10.
This includes imported components.
Note that this is only relevant for components.
max_data_segments: usize
The maximum number of data segments to generate. Defaults to 100.
max_element_segments: usize
The maximum number of element segments to generate. Defaults to 100.
max_elements: usize
The maximum number of elements within a segment to generate. Defaults to 100.
max_exports: usize
The maximum number of exports to generate. Defaults to 100.
max_funcs: usize
The maximum number of functions to generate. Defaults to 100. This includes imported functions.
max_globals: usize
The maximum number of globals to generate. Defaults to 100. This includes imported globals.
max_imports: usize
The maximum number of imports to generate. Defaults to 100.
max_instances: usize
The maximum number of instances to use. Defaults to 10.
This includes imported instances.
Note that this is only relevant for components.
max_instructions: usize
The maximum number of instructions to generate in a function body. Defaults to 100.
Note that some additional end
s, else
s, and unreachable
s may be
appended to the function body to finish block scopes.
max_memories: usize
The maximum number of memories to use. Defaults to 1.
This includes imported memories.
Note that more than one memory is in the realm of the multi-memory wasm proposal.
max_memory32_pages: u64
The maximum, in 64k Wasm pages, of any 32-bit memory’s initial or maximum size.
Defaults to 2^16.
max_memory64_pages: u64
The maximum, in 64k Wasm pages, of any 64-bit memory’s initial or maximum size.
Defaults to 2^48.
max_modules: usize
The maximum number of modules to use. Defaults to 10.
This includes imported modules.
Note that this is only relevant for components.
max_nesting_depth: usize
Returns the maximal nesting depth of modules with the component model proposal. Defaults to 10.
max_table_elements: u32
The maximum, elements, of any table’s initial or maximum size. Defaults to 1 million.
max_tables: usize
The maximum number of tables to use. Defaults to 1.
This includes imported tables.
Note that more than one table is in the realm of the reference types proposal.
The maximum number of tags to generate. Defaults to 100.
max_type_size: u32
Returns the maximal effective size of any type generated by wasm-smith.
Note that this number is roughly in units of “how many types would be needed to represent the recursive type”. A function with 8 parameters and 2 results would take 11 types (one for the type, 10 for params/results). A module type with 2 imports and 3 exports would take 6 (module + imports + exports) plus the size of each import/export type. This is a somewhat rough measurement that is not intended to be very precise.
Defaults to 1000.
max_types: usize
The maximum number of types to generate. Defaults to 100.
max_values: usize
The maximum number of values to use. Defaults to 10.
This includes imported values.
Note that this is irrelevant unless value model support is enabled.
memory64_enabled: bool
Returns whether 64-bit memories are allowed. Defaults to false.
Note that this is the gate for the memory64 proposal to WebAssembly.
memory_max_size_required: bool
Whether every Wasm memory must have a maximum size
specified. Defaults to false
.
memory_offset_choices: MemoryOffsetChoices
Control the probability of generating memory offsets that are in bounds vs. potentially out of bounds.
See the MemoryOffsetChoices
struct for details.
min_data_segments: usize
The minimum number of data segments to generate. Defaults to 0.
min_element_segments: usize
The minimum number of element segments to generate. Defaults to 0.
min_elements: usize
The minimum number of elements within a segment to generate. Defaults to 0.
min_exports: usize
The minimum number of exports to generate. Defaults to 0.
min_funcs: usize
The minimum number of functions to generate. Defaults to 0.
This includes imported functions.
min_globals: usize
The minimum number of globals to generate. Defaults to 0.
This includes imported globals.
min_imports: usize
The minimum number of imports to generate. Defaults to 0.
Note that if the sum of the maximum function1, table, global and memory counts is less than the minimum number of imports, then it will not be possible to satisfy all constraints (because imports count against the limits for those element kinds). In that case, we strictly follow the max-constraints, and can fail to satisfy this minimum number.
the maximum number of functions is also limited by the number of function types arbitrarily chosen; strictly speaking, then, the maximum number of imports that can be created due to max-constraints is
sum(min(num_func_types, max_funcs), max_tables, max_globals, max_memories)
. ↩
min_memories: u32
The minimum number of memories to use. Defaults to 0.
This includes imported memories.
min_tables: u32
The minimum number of tables to use. Defaults to 0.
This includes imported tables.
The minimum number of tags to generate. Defaults to 0.
min_types: usize
The minimum number of types to generate. Defaults to 0.
min_uleb_size: u8
The minimum size, in bytes, of all leb-encoded integers. Defaults to 1.
This is useful for ensuring that all leb-encoded integers are decoded as such rather than as simply one byte. This will forcibly extend leb integers with an over-long encoding in some locations if the size would otherwise be smaller than number returned here.
multi_value_enabled: bool
Determines whether the multi-value results are enabled.
Defaults to true
.
reference_types_enabled: bool
Determines whether the reference types proposal is enabled for generating instructions.
Defaults to false
.
relaxed_simd_enabled: bool
Determines whether the Relaxed SIMD proposal is enabled for generating instructions.
Defaults to false
.
saturating_float_to_int_enabled: bool
Determines whether the nontrapping-float-to-int-conversions propsal is enabled.
Defaults to true
.
sign_extension_ops_enabled: bool
Determines whether the sign-extension-ops propsal is enabled.
Defaults to true
.
simd_enabled: bool
Determines whether the SIMD proposal is enabled for generating instructions.
Defaults to false
.
tail_call_enabled: bool
Determines whether the tail calls proposal is enabled for generating instructions.
Defaults to false
.
table_max_size_required: bool
Whether every Wasm table must have a maximum size
specified. Defaults to false
.
threads_enabled: bool
Determines whether the threads proposal is enabled.
The threads proposal involves shared linear memory, new atomic
instructions, and new wait
and notify
instructions.
Defaults to false
.
allow_invalid_funcs: bool
Indicates whether wasm-smith is allowed to generate invalid function bodies.
When enabled this option will enable taking raw bytes from the input byte stream and using them as a wasm function body. This means that the output module is not guaranteed to be valid but can help tickle various parts of validation/compilation in some circumstances as well.
Defaults to false
.
Trait Implementations§
source§impl<'a> Arbitrary<'a> for Config
impl<'a> Arbitrary<'a> for Config
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self
from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read more