wasmer_wasix/syscalls/wasix/
proc_id.rs

1use super::*;
2use crate::syscalls::*;
3
4/// ### `proc_id()`
5/// Returns the handle of the current process
6#[instrument(level = "trace", skip_all, fields(pid = field::Empty), ret)]
7pub fn proc_id<M: MemorySize>(ctx: FunctionEnvMut<'_, WasiEnv>, ret_pid: WasmPtr<Pid, M>) -> Errno {
8    let env = ctx.data();
9    let memory = unsafe { env.memory_view(&ctx) };
10
11    let pid = env.process.pid();
12    Span::current().record("pid", pid.raw());
13
14    wasi_try_mem!(ret_pid.write(&memory, pid.raw() as Pid));
15    Errno::Success
16}