wasmer_wasix/journal/effector/syscalls/
fd_close.rs

1use super::*;
2
3impl JournalEffector {
4    pub fn save_fd_close(ctx: &mut FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> anyhow::Result<()> {
5        Self::save_event(ctx, JournalEntry::CloseFileDescriptorV1 { fd })
6    }
7
8    pub fn apply_fd_close(ctx: &mut FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> anyhow::Result<()> {
9        let env = ctx.data();
10        let (_, state) = unsafe { env.get_memory_and_wasi_state(&ctx, 0) };
11        // FIXME: the journal should use the same logic as the fd_close syscall,
12        // NOT invent its own!!
13        if let Err(err) = state.fs.close_fd(fd) {
14            bail!("journal restore error: failed to close descriptor (fd={fd}) - {err}");
15        }
16        Ok(())
17    }
18}