1use std::pin::Pin;
2
3use bytes::Bytes;
4use futures::Future;
5use wasmer_wasix_types::{
6    wasi::Errno,
7    wasix::{ThreadStartType, WasiMemoryLayout},
8};
9
10use crate::os::task::thread::RewindResultType;
11
12#[doc(hidden)]
14pub type AsyncifyFuture = dyn Future<Output = Bytes> + Send + Sync + 'static;
15
16pub trait RewindPostProcess {
20    fn finish(&mut self, res: Result<(), Errno>) -> Bytes;
22}
23
24pub struct RewindState {
26    pub memory_stack: Bytes,
28    pub rewind_stack: Bytes,
30    pub store_data: Bytes,
32    pub start: ThreadStartType,
34    pub layout: WasiMemoryLayout,
36    pub is_64bit: bool,
38}
39
40pub type RewindStateOption = Option<(RewindState, RewindResultType)>;
41
42pub struct DeepSleepWork {
45    pub trigger: Pin<Box<AsyncifyFuture>>,
47    pub rewind: RewindState,
49}
50impl std::fmt::Debug for DeepSleepWork {
51    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52        write!(
53            f,
54            "deep-sleep-work(memory_stack_len={}, rewind_stack_len={}, store_size={})",
55            self.rewind.memory_stack.len(),
56            self.rewind.rewind_stack.len(),
57            self.rewind.store_data.len()
58        )
59    }
60}