Struct wasm_smith::Module

source ·
pub struct Module { /* private fields */ }
Expand description

A pseudo-random WebAssembly module.

Construct instances of this type (with default configuration) with the Arbitrary trait.

§Configuring Generated Modules

To configure the shape of generated module, create a Config and then call Module::new with it.

Implementations§

source§

impl Module

source

pub fn to_bytes(&self) -> Vec<u8>

Encode this Wasm module into bytes.

source§

impl Module

source

pub fn ensure_termination(&mut self, default_fuel: u32) -> Result<u32>

Ensure that all of this Wasm module’s functions will terminate when executed.

This adds a new mutable, exported global to the module to keep track of how much “fuel” is left. Fuel is decremented at the head of each loop and function. When fuel reaches zero, a trap is raised.

The index of the fuel global is returned, so that you may control how much fuel the module is given.

§Errors

Returns an error if any function body was generated with possibly-invalid bytes rather than being generated by wasm-smith. In such a situation this pass does not parse the input bytes and inject instructions, instead it returns an error.

source§

impl Module

source

pub fn config(&self) -> &Config

Returns a reference to the internal configuration.

source

pub fn new(config: Config, u: &mut Unstructured<'_>) -> Result<Self>

Creates a new Module with the specified config for configuration and Unstructured for the DNA of this module.

Trait Implementations§

source§

impl<'a> Arbitrary<'a> for Module

source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
source§

impl Debug for Module

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Module

§

impl !RefUnwindSafe for Module

§

impl !Send for Module

§

impl !Sync for Module

§

impl Unpin for Module

§

impl !UnwindSafe for Module

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.