Skip to main content

shadow_rs/host/syscall/handler/
stat.rs

1use shadow_shim_helper_rs::syscall_types::ForeignPtr;
2
3use crate::cshadow;
4use crate::host::syscall::handler::{SyscallContext, SyscallHandler};
5use crate::host::syscall::type_formatting::SyscallStringArg;
6use crate::host::syscall::types::{SyscallError, SyscallResult};
7
8impl SyscallHandler {
9    log_syscall!(
10        statx,
11        /* rv */ std::ffi::c_int,
12        /* dfd */ std::ffi::c_int,
13        /* filename */ SyscallStringArg,
14        /* flags */ std::ffi::c_int,
15        /* statxbuf */ *const std::ffi::c_void,
16    );
17    pub fn statx(ctx: &mut SyscallContext) -> SyscallResult {
18        Self::legacy_syscall(cshadow::syscallhandler_statx, ctx)
19    }
20
21    log_syscall!(
22        fstat,
23        /* rv */ std::ffi::c_int,
24        /* fd */ std::ffi::c_uint,
25        /* statbuf */ *const linux_api::stat::stat,
26    );
27    pub fn fstat(
28        ctx: &mut SyscallContext,
29        fd: std::ffi::c_uint,
30        statbuf_ptr: ForeignPtr<linux_api::stat::stat>,
31    ) -> Result<(), SyscallError> {
32        let desc_table = ctx.objs.thread.descriptor_table_borrow(ctx.objs.host);
33        let file = Self::get_descriptor(&desc_table, fd)?.file();
34        let stat = file.stat()?;
35
36        ctx.objs
37            .process
38            .memory_borrow_mut()
39            .write(statbuf_ptr, &stat)?;
40
41        Ok(())
42    }
43
44    log_syscall!(fstatfs, /* rv */ std::ffi::c_int);
45    pub fn fstatfs(ctx: &mut SyscallContext) -> SyscallResult {
46        Self::legacy_syscall(cshadow::syscallhandler_fstatfs, ctx)
47    }
48
49    log_syscall!(
50        newfstatat,
51        /* rv */ std::ffi::c_int,
52        /* dirfd */ std::ffi::c_int,
53        /* path */ SyscallStringArg,
54        /* statbuf */ *const linux_api::stat::stat,
55        /* flag */ std::ffi::c_int,
56    );
57    pub fn newfstatat(ctx: &mut SyscallContext) -> SyscallResult {
58        Self::legacy_syscall(cshadow::syscallhandler_newfstatat, ctx)
59    }
60}