pub struct Config { /* private fields */ }
Expand description
Configuration for the transformation pass in this module.
Created primarily through new
and then executed through run
.
Implementations§
Source§impl Config
impl Config
Sourcepub fn is_enabled(&self, module: &Module) -> bool
pub fn is_enabled(&self, module: &Module) -> bool
Is threaded Wasm enabled?
Sourcepub fn maximum_memory(&mut self, max: u32) -> &mut Config
pub fn maximum_memory(&mut self, max: u32) -> &mut Config
Specify the maximum amount of memory the Wasm module can ever have.
We’ll be specifying that the memory for this Wasm module is shared, and all shared memories must have their maximum limit specified (whereas by default Rust/LLVM/LLD don’t specify a maximum).
The default for this option is 16MB, and this can be used to change the maximum memory we’ll be specifying.
The max
argument is in units of bytes.
If the maximum memory is already specified this setting won’t have any affect.
Sourcepub fn thread_stack_size(&mut self, size: u32) -> &mut Config
pub fn thread_stack_size(&mut self, size: u32) -> &mut Config
Specify the stack size for all threads spawned.
The stack size is typically set by rustc as an argument to LLD and defaults to 1MB for the main thread. All threads spawned by the main thread, however, need to allocate their own stack!
This configuration option indicates how large the stack of each child
thread will be. This will be allocated as part of the start
function
and will be stored in LLVM’s global stack pointer.
Sourcepub fn run(&self, module: &mut Module) -> Result<Option<ThreadCount>, Error>
pub fn run(&self, module: &mut Module) -> Result<Option<ThreadCount>, Error>
Execute the transformation on the parsed Wasm module specified.
This function will prepare Module
to be run on multiple threads,
performing steps such as:
- All data segments are switched to “passive” data segments to ensure they’re only initialized once (coming later)
- If memory is exported from this module, it is instead switched to being imported (with the same parameters).
- The imported memory is required to be
shared
, ensuring it’s backed by aSharedArrayBuffer
on the web. - A
global
for a thread ID is injected. - Four bytes in linear memory are reserved for the counter of thread IDs.
- A
start
function is injected (or prepended if one already exists) which initializes memory for the first thread and otherwise allocates thread ids for all threads. - Some stack space is prepared for each thread after the first one.
More and/or less may happen here over time, stay tuned!