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::types::{SyscallError, SyscallResult};
7
8impl SyscallHandler {
9 log_syscall!(statx, std::ffi::c_int);
10 pub fn statx(ctx: &mut SyscallContext) -> SyscallResult {
11 Self::legacy_syscall(cshadow::syscallhandler_statx, ctx)
12 }
13
14 log_syscall!(
15 fstat,
16 std::ffi::c_int,
17 std::ffi::c_uint,
18 *const linux_api::stat::stat,
19 );
20 pub fn fstat(
21 ctx: &mut SyscallContext,
22 fd: std::ffi::c_uint,
23 statbuf_ptr: ForeignPtr<linux_api::stat::stat>,
24 ) -> Result<(), SyscallError> {
25 let desc_table = ctx.objs.thread.descriptor_table_borrow(ctx.objs.host);
26 let file = match Self::get_descriptor(&desc_table, fd)?.file() {
27 CompatFile::New(file) => file.clone(),
28 CompatFile::Legacy(_) => {
30 drop(desc_table);
31 let rv: i32 = Self::legacy_syscall(cshadow::syscallhandler_fstat, ctx)?;
32 assert_eq!(rv, 0);
33 return Ok(());
34 }
35 };
36
37 let stat = file.inner_file().borrow().stat()?;
38
39 ctx.objs
40 .process
41 .memory_borrow_mut()
42 .write(statbuf_ptr, &stat)?;
43
44 Ok(())
45 }
46
47 log_syscall!(fstatfs, std::ffi::c_int);
48 pub fn fstatfs(ctx: &mut SyscallContext) -> SyscallResult {
49 Self::legacy_syscall(cshadow::syscallhandler_fstatfs, ctx)
50 }
51
52 log_syscall!(newfstatat, std::ffi::c_int);
53 pub fn newfstatat(ctx: &mut SyscallContext) -> SyscallResult {
54 Self::legacy_syscall(cshadow::syscallhandler_newfstatat, ctx)
55 }
56}