wasmer_wasix/syscalls/wasi/thread_spawn.rs
1use super::*;
2use crate::syscalls::*;
3
4use wasmer::Memory;
5use wasmer_wasix_types::wasi::ThreadStart;
6
7/// ### `thread_spawn()`
8/// Creates a new thread by spawning that shares the same
9/// memory address space, file handles and main event loops.
10///
11/// ## Parameters
12///
13/// * `start_ptr` - Pointer to the structure that describes the thread to be launched
14///
15/// ## Return
16///
17/// Returns the thread index of the newly created thread
18/// (indices always start from the same value as `pid` and increments in steps)
19#[instrument(level = "trace", skip_all, ret)]
20pub fn thread_spawn<M: MemorySize>(
21 mut ctx: FunctionEnvMut<'_, WasiEnv>,
22 start_ptr: WasmPtr<ThreadStart<M>, M>,
23) -> i32 {
24 thread_spawn_internal_from_wasi(&mut ctx, start_ptr)
25 .map(|tid| tid as i32)
26 .map_err(|errno| errno as i32)
27 .unwrap_or_else(|err| -err)
28}