wasmer_wasix/journal/effector/syscalls/
fd_close.rs1use super::*;
2use crate::syscalls::flush_captured_handle;
3
4impl JournalEffector {
5 pub fn save_fd_close(ctx: &mut FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> anyhow::Result<()> {
6 Self::save_event(ctx, JournalEntry::CloseFileDescriptorV1 { fd })
7 }
8
9 pub fn apply_fd_close(ctx: &mut FunctionEnvMut<'_, WasiEnv>, fd: Fd) -> anyhow::Result<()> {
10 let env = ctx.data();
11 let (_, state) = unsafe { env.get_memory_and_wasi_state(&ctx, 0) };
12 let outcome = state.fs.close_fd_and_capture_flush(fd);
13
14 if outcome.skipped_preopen {
15 return Ok(());
16 }
17
18 if !outcome.removed {
19 bail!(
20 "journal restore error: failed to close descriptor (fd={fd}) - {}",
21 Errno::Badf
22 );
23 }
24
25 flush_captured_handle(env, outcome.flush_target).map_err(|err| {
26 anyhow::anyhow!(
27 "journal restore error: failed to flush before closing descriptor (fd={fd}) - {err:?}"
28 )
29 })?;
30
31 Ok(())
32 }
33}