wasmer_wasix/syscalls/journal/actions/
set_thread.rs

1use super::*;
2
3impl<'a> JournalSyscallPlayer<'a, '_> {
4    #[allow(clippy::result_large_err)]
5    pub(crate) unsafe fn action_set_thread(
6        &mut self,
7        id: u32,
8        call_stack: Cow<'a, [u8]>,
9        memory_stack: Cow<'a, [u8]>,
10        store_data: Cow<'a, [u8]>,
11        is_64bit: bool,
12        start: ThreadStartType,
13        layout: WasiMemoryLayout,
14        differ_ethereal: Option<&mut Vec<JournalEntry<'a>>>,
15    ) -> Result<(), WasiRuntimeError> {
16        if Some(&self.cur_module_hash) != self.journal_module_hash.as_ref() {
17            tracing::trace!(%id, "Skipping journal entry - SetThread call_stack={} bytes memory_stack={} bytes store_data={} bytes", call_stack.len(), memory_stack.len(), store_data.len());
18            return Ok(());
19        }
20
21        let state = RewindState {
22            memory_stack: memory_stack.to_vec().into(),
23            rewind_stack: call_stack.to_vec().into(),
24            store_data: store_data.to_vec().into(),
25            start,
26            layout: layout.clone(),
27            is_64bit,
28        };
29
30        if Into::<WasiThreadId>::into(id) == self.ctx.data().tid() {
31            tracing::trace!(%id, "Differ(end) journal - SetThread(main) call_stack={} bytes memory_stack={} bytes store_data={} bytes", call_stack.len(), memory_stack.len(), store_data.len());
32            self.rewind.replace(state);
33        } else if let Some(differ_ethereal) = differ_ethereal {
34            tracing::trace!(%id, "Differ(ether) journal - SetThread call_stack={} bytes memory_stack={} bytes store_data={} bytes", call_stack.len(), memory_stack.len(), store_data.len());
35            differ_ethereal.push(JournalEntry::SetThreadV1 {
36                id,
37                call_stack,
38                memory_stack,
39                store_data,
40                start,
41                layout,
42                is_64bit,
43            });
44        } else if self.bootstrapping {
45            tracing::trace!(%id, "Differ(end) journal - SetThread({id}) call_stack={} bytes memory_stack={} bytes store_data={} bytes", call_stack.len(), memory_stack.len(), store_data.len());
46            self.spawn_threads.insert(id.into(), state);
47        } else {
48            return Err(WasiRuntimeError::Runtime(RuntimeError::user(
49                anyhow::format_err!(
50                    "Snapshot restoration does not currently support live updates of running threads."
51                )
52                .into(),
53            )));
54        }
55        Ok(())
56    }
57}