wasmer_wasix/journal/effector/
thread_exit.rs

1use wasmer_wasix_types::wasi::Signal;
2
3use super::*;
4
5impl JournalEffector {
6    pub fn save_thread_exit(
7        env: &WasiEnv,
8        id: WasiThreadId,
9        exit_code: Option<ExitCode>,
10    ) -> anyhow::Result<()> {
11        env.active_journal()?
12            .write(JournalEntry::CloseThreadV1 {
13                id: id.raw(),
14                exit_code,
15            })
16            .map_err(map_snapshot_err)?;
17        Ok(())
18    }
19
20    pub fn apply_thread_exit(
21        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
22        tid: WasiThreadId,
23        exit_code: Option<ExitCode>,
24    ) -> anyhow::Result<()> {
25        let env = ctx.data();
26        if let Some(thread) = env.process.get_thread(&tid) {
27            if let Some(code) = exit_code {
28                thread.set_status_finished(Ok(code));
29            }
30            thread.signal(Signal::Sigkill);
31        }
32        Ok(())
33    }
34}