wasmer_wasix/syscalls/wasi/proc_exit.rs
1use super::*;
2use crate::syscalls::*;
3
4/// ### `proc_exit()`
5/// Terminate the process normally. An exit code of 0 indicates successful
6/// termination of the program. The meanings of other values is dependent on
7/// the environment.
8/// Inputs:
9/// - `ExitCode`
10/// Exit code to return to the operating system
11#[instrument(level = "trace", skip_all)]
12pub fn proc_exit<M: MemorySize>(
13 mut ctx: FunctionEnvMut<'_, WasiEnv>,
14 code: ExitCode,
15) -> Result<(), WasiError> {
16 let in_asyncify_based_vfork = ctx
17 .data()
18 .vfork
19 .as_ref()
20 .map(|v| v.asyncify.is_some())
21 .unwrap_or(false);
22
23 proc_exit2::<M>(ctx, code)?;
24
25 // proc_exit2 returns in two cases:
26 // 1. We are in an asyncify-based vfork, in which case on_called is set and magic will happen
27 // 2. We are in a setjmp/longjmp vfork, in which case we need to error out as returning from proc_exit is not allowed
28
29 if in_asyncify_based_vfork {
30 return Ok(());
31 }
32
33 tracing::error!(
34 "Calling proc_exit in a vfork is undefined behaviour. Call _exit or _proc_exit2 instead."
35 );
36 Err(WasiError::Exit(ExitCode::from(129)))
37}