Skip to content

Support fstat on pipes #3319

@stevenengler

Description

@stevenengler

Shadow's fstat syscall handler is in C, which only supports RegularFiles. This means that fstat in shadow currently returns EBADF for pipes. Shadow should properly handle pipe fds in the fstat syscall handler. This is used by Python when the subprocess module executes programs.

strace python3 -c 'import subprocess; subprocess.run(["ls", "-l", "/dev/null"], capture_output=True)'
pipe2([3, 4], O_CLOEXEC)                = 0
pipe2([5, 6], O_CLOEXEC)                = 0
fstat(3, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0

To implement:

  1. Fill in the correct syscall arguments in SyscallHandler::fstat in src/main/host/syscall/handler/file.rs.
  2. Figure out what the struct stat equivalent is in the linux kernel, and create bindings for it in linux-api library.
  3. Figure out what values to return for each field in struct stat.
  4. Add fstat syscall tests with pipes.

Note: The SYS_fstat syscall calls the kernel's sys_newfstat on x86-64, not sys_fstat: arch/x86/entry/syscalls/syscall_64.tbl#L16, which should be fs/stat.c#L475.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Help WantedWell suited for community contributionsType: EnhancementNew functionality or improved design

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions