wasmer_wasix/syscalls/journal/
mod.rs

1#[cfg(feature = "journal")]
2mod actions;
3mod clear_ethereal;
4mod do_checkpoint_from_outside;
5mod maybe_snapshot;
6mod maybe_snapshot_many;
7mod maybe_snapshot_once;
8#[cfg(feature = "journal")]
9mod play_event;
10mod restore_snapshot;
11mod wait_for_snapshot;
12
13#[cfg(feature = "journal")]
14use actions::*;
15use clear_ethereal::*;
16use wasmer_journal::JournalEntry;
17
18pub use do_checkpoint_from_outside::*;
19pub use maybe_snapshot::*;
20pub use maybe_snapshot_many::*;
21pub use maybe_snapshot_once::*;
22pub use restore_snapshot::*;
23pub use wait_for_snapshot::*;
24
25use crate::os::task::process::MemorySnapshotRegion;
26use std::{collections::BTreeMap, ops::Range};
27
28use super::*;
29
30pub struct JournalStdIoWrite<'a> {
31    pub offset: u64,
32    pub data: Cow<'a, [u8]>,
33    pub is_64bit: bool,
34}
35
36pub struct JournalSyscallPlayer<'a, 'c> {
37    pub ctx: FunctionEnvMut<'c, WasiEnv>,
38    pub bootstrapping: bool,
39
40    pub journal_module_hash: Option<Box<[u8]>>,
41    pub rewind: Option<RewindState>,
42    pub cur_module_hash: Box<[u8]>,
43    pub real_fd: HashSet<WasiFd>,
44    pub connected_sockets_are_dead: bool,
45
46    // We delay the spawning of threads until the end as its
47    // possible that the threads will be cancelled before all the
48    // events finished the streaming process
49    pub spawn_threads: BTreeMap<WasiThreadId, RewindState>,
50    pub staged_differ_memory: Vec<(Range<u64>, Cow<'a, [u8]>)>,
51    pub differ_memory: Vec<(Range<u64>, Cow<'a, [u8]>)>,
52
53    // We capture the stdout and stderr while we replay
54    pub stdout: Option<Vec<JournalStdIoWrite<'a>>>,
55    pub stderr: Option<Vec<JournalStdIoWrite<'a>>>,
56    pub stdout_fds: HashSet<u32>,
57    pub stderr_fds: HashSet<u32>,
58}
59
60impl<'c> JournalSyscallPlayer<'_, 'c> {
61    pub fn new(mut ctx: FunctionEnvMut<'c, WasiEnv>, bootstrapping: bool) -> Self {
62        let env = ctx.data();
63        let keep_stdio = !env.skip_stdio_during_bootstrap;
64        let cur_module_hash: Box<[u8]> = Box::from(env.process.module_hash.as_bytes());
65        JournalSyscallPlayer {
66            ctx,
67            bootstrapping,
68            cur_module_hash,
69            journal_module_hash: None,
70            rewind: None,
71            connected_sockets_are_dead: true,
72            spawn_threads: Default::default(),
73            staged_differ_memory: Default::default(),
74            differ_memory: Default::default(),
75            // We capture stdout and stderr while we replay
76            stdout_fds: [1 as WasiFd].into(),
77            stderr_fds: [2 as WasiFd].into(),
78            stdout: keep_stdio.then(Default::default),
79            stderr: keep_stdio.then(Default::default),
80            real_fd: Default::default(),
81        }
82    }
83}