wasmtime_environ/
tunables.rs

1use serde::{Deserialize, Serialize};
2
3/// Tunable parameters for WebAssembly compilation.
4#[derive(Clone, Hash, Serialize, Deserialize)]
5pub struct Tunables {
6    /// For static heaps, the size in wasm pages of the heap protected by bounds checking.
7    pub static_memory_bound: u64,
8
9    /// The size in bytes of the offset guard for static heaps.
10    pub static_memory_offset_guard_size: u64,
11
12    /// The size in bytes of the offset guard for dynamic heaps.
13    pub dynamic_memory_offset_guard_size: u64,
14
15    /// The size, in bytes, of reserved memory at the end of a "dynamic" memory,
16    /// before the guard page, that memory can grow into. This is intended to
17    /// amortize the cost of `memory.grow` in the same manner that `Vec<T>` has
18    /// space not in use to grow into.
19    pub dynamic_memory_growth_reserve: u64,
20
21    /// Whether or not to generate native DWARF debug information.
22    pub generate_native_debuginfo: bool,
23
24    /// Whether or not to retain DWARF sections in compiled modules.
25    pub parse_wasm_debuginfo: bool,
26
27    /// Whether or not fuel is enabled for generated code, meaning that fuel
28    /// will be consumed every time a wasm instruction is executed.
29    pub consume_fuel: bool,
30
31    /// Whether or not we use epoch-based interruption.
32    pub epoch_interruption: bool,
33
34    /// Whether or not to treat the static memory bound as the maximum for unbounded heaps.
35    pub static_memory_bound_is_maximum: bool,
36
37    /// Whether or not linear memory allocations will have a guard region at the
38    /// beginning of the allocation in addition to the end.
39    pub guard_before_linear_memory: bool,
40
41    /// Indicates whether an address map from compiled native code back to wasm
42    /// offsets in the original file is generated.
43    pub generate_address_map: bool,
44
45    /// Flag for the component module whether adapter modules have debug
46    /// assertions baked into them.
47    pub debug_adapter_modules: bool,
48
49    /// Whether or not lowerings for relaxed simd instructions are forced to
50    /// be deterministic.
51    pub relaxed_simd_deterministic: bool,
52}
53
54impl Default for Tunables {
55    fn default() -> Self {
56        let (static_memory_bound, static_memory_offset_guard_size) =
57            if cfg!(target_pointer_width = "64") {
58                // 64-bit has tons of address space to static memories can have 4gb
59                // address space reservations liberally by default, allowing us to
60                // help eliminate bounds checks.
61                //
62                // Coupled with a 2 GiB address space guard it lets us translate
63                // wasm offsets into x86 offsets as aggressively as we can.
64                (0x1_0000, 0x8000_0000)
65            } else if cfg!(target_pointer_width = "32") {
66                // For 32-bit we scale way down to 10MB of reserved memory. This
67                // impacts performance severely but allows us to have more than a
68                // few instances running around.
69                ((10 * (1 << 20)) / crate::WASM_PAGE_SIZE as u64, 0x1_0000)
70            } else {
71                panic!("unsupported target_pointer_width");
72            };
73        Self {
74            static_memory_bound,
75            static_memory_offset_guard_size,
76
77            // Size in bytes of the offset guard for dynamic memories.
78            //
79            // Allocate a small guard to optimize common cases but without
80            // wasting too much memory.
81            dynamic_memory_offset_guard_size: 0x1_0000,
82
83            // We've got lots of address space on 64-bit so use a larger
84            // grow-into-this area, but on 32-bit we aren't as lucky.
85            #[cfg(target_pointer_width = "64")]
86            dynamic_memory_growth_reserve: 2 << 30, // 2GB
87            #[cfg(target_pointer_width = "32")]
88            dynamic_memory_growth_reserve: 1 << 20, // 1MB
89
90            generate_native_debuginfo: false,
91            parse_wasm_debuginfo: true,
92            consume_fuel: false,
93            epoch_interruption: false,
94            static_memory_bound_is_maximum: false,
95            guard_before_linear_memory: true,
96            generate_address_map: true,
97            debug_adapter_modules: false,
98            relaxed_simd_deterministic: false,
99        }
100    }
101}