shadow_rs/host/syscall/handler/
stat.rs

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