wasmer_wasix/syscalls/wasix/thread_id.rs
1use super::*;
2use crate::syscalls::*;
3
4/// ### `thread_id()`
5/// Returns the index of the current thread
6/// (threads indices are sequencial from zero)
7#[instrument(level = "trace", skip_all, fields(tid = field::Empty), ret)]
8pub fn thread_id<M: MemorySize>(
9 ctx: FunctionEnvMut<'_, WasiEnv>,
10 ret_tid: WasmPtr<Tid, M>,
11) -> Errno {
12 let env = ctx.data();
13 let tid: Tid = env.thread.tid().into();
14 Span::current().record("tid", tid);
15 let memory = unsafe { env.memory_view(&ctx) };
16 wasi_try_mem!(ret_tid.write(&memory, tid));
17 Errno::Success
18}