|
1 | | -use arbitrary::Arbitrary; |
2 | | -use wasmi::{core::ValType, Val}; |
| 1 | +#![allow(dead_code)] |
3 | 2 |
|
4 | | -/// The configuration used to produce Wasmi compatible fuzzing Wasm modules. |
5 | | -#[derive(Debug, Arbitrary)] |
6 | | -pub struct ExecConfig; |
| 3 | +use arbitrary::{Arbitrary, Unstructured}; |
| 4 | +use wasmi::{core::ValType, Val}; |
7 | 5 |
|
8 | | -impl wasm_smith::Config for ExecConfig { |
9 | | - fn export_everything(&self) -> bool { |
10 | | - true |
11 | | - } |
12 | | - fn allow_start_export(&self) -> bool { |
13 | | - false |
14 | | - } |
15 | | - fn reference_types_enabled(&self) -> bool { |
16 | | - false |
17 | | - } |
18 | | - fn max_imports(&self) -> usize { |
19 | | - 0 |
20 | | - } |
21 | | - fn max_memory_pages(&self, is_64: bool) -> u64 { |
22 | | - match is_64 { |
23 | | - true => { |
24 | | - // Note: wasmi does not support 64-bit memory, yet. |
25 | | - 0 |
26 | | - } |
27 | | - false => 1_000, |
28 | | - } |
29 | | - } |
30 | | - fn max_data_segments(&self) -> usize { |
31 | | - 10_000 |
32 | | - } |
33 | | - fn max_element_segments(&self) -> usize { |
34 | | - 10_000 |
35 | | - } |
36 | | - fn max_exports(&self) -> usize { |
37 | | - 10_000 |
38 | | - } |
39 | | - fn max_elements(&self) -> usize { |
40 | | - 10_000 |
41 | | - } |
42 | | - fn min_funcs(&self) -> usize { |
43 | | - 1 |
44 | | - } |
45 | | - fn max_funcs(&self) -> usize { |
46 | | - 10_000 |
47 | | - } |
48 | | - fn max_globals(&self) -> usize { |
49 | | - 10_000 |
50 | | - } |
51 | | - fn max_table_elements(&self) -> u32 { |
52 | | - 10_000 |
53 | | - } |
54 | | - fn max_values(&self) -> usize { |
55 | | - 10_000 |
56 | | - } |
57 | | - fn max_instructions(&self) -> usize { |
58 | | - 100_000 |
| 6 | +pub fn exec_config() -> wasm_smith::Config { |
| 7 | + wasm_smith::Config { |
| 8 | + export_everything: true, |
| 9 | + allow_start_export: false, |
| 10 | + reference_types_enabled: false, |
| 11 | + max_imports: 0, |
| 12 | + max_memory32_bytes: (1 << 16) * 1_000, |
| 13 | + // Note: wasmi does not support 64-bit memory, yet. |
| 14 | + memory64_enabled: false, |
| 15 | + max_data_segments: 10_000, |
| 16 | + max_element_segments: 10_000, |
| 17 | + max_exports: 10_000, |
| 18 | + max_elements: 10_000, |
| 19 | + min_funcs: 1, |
| 20 | + max_funcs: 10_000, |
| 21 | + max_globals: 10_000, |
| 22 | + max_table_elements: 10_000, |
| 23 | + max_values: 10_000, |
| 24 | + max_instructions: 100_000, |
| 25 | + exceptions_enabled: false, |
| 26 | + simd_enabled: false, |
| 27 | + threads_enabled: false, |
| 28 | + gc_enabled: false, |
| 29 | + tail_call_enabled: false, |
| 30 | + ..Default::default() |
59 | 31 | } |
60 | 32 | } |
61 | 33 |
|
| 34 | +pub fn arbitrary_exec_module(seed: &[u8]) -> arbitrary::Result<wasm_smith::Module> { |
| 35 | + let mut unstructured = Unstructured::new(seed); |
| 36 | + wasm_smith::Module::new(exec_config(), &mut unstructured) |
| 37 | +} |
| 38 | + |
| 39 | +pub fn arbitrary_translate_module(seed: &[u8]) -> arbitrary::Result<wasm_smith::Module> { |
| 40 | + let mut unstructured = Unstructured::new(seed); |
| 41 | + |
| 42 | + let config = wasm_smith::Config::arbitrary(&mut unstructured); |
| 43 | + |
| 44 | + config.map(|mut config| { |
| 45 | + config.gc_enabled = false; |
| 46 | + config.exceptions_enabled = false; |
| 47 | + config.simd_enabled = false; |
| 48 | + config.threads_enabled = false; |
| 49 | + |
| 50 | + wasm_smith::Module::new(config, &mut unstructured) |
| 51 | + })? |
| 52 | +} |
| 53 | + |
62 | 54 | /// Converts a [`ValType`] into a [`Val`] with default initialization of 1. |
63 | 55 | /// |
64 | 56 | /// # ToDo |
|
0 commit comments