Stream: git-wasmtime

Topic: wasmtime / issue #6713 fd_fdstat_set_flags fail ?


view this post on Zulip Wasmtime GitHub notifications bot (Jul 11 2023 at 08:45):

orangeC23 opened issue #6713:

Test Case

The rust file is :

use std::fs::File;
use std::os::fd::{AsRawFd, FromRawFd};
use std::fs::OpenOptions;

fn main() {
    // let file = File::open("Data/hello.txt").expect("Can not open.");
    let file = std::fs::OpenOptions::new()
        .open("Data/hello.txt")
        .expect("Failed to open file");

    let file_descriptor = file.as_raw_fd();
    println!("File descriptor {}", file_descriptor);

    unsafe{
        let p1:wasi::Fd = file_descriptor as u32;
        let p2:wasi::Fdflags = wasi::FDFLAGS_SYNC;

        println!("Set:{:?}", wasi::fd_fdstat_set_flags(p1, p2));
        println!("Get:{:?}", wasi::fd_fdstat_get(p1));
    }
}

Steps to Reproduce

  1. Use cargo build --target wasm32-wasi to compile the rust file into WASM binaries allocate.wasm.
  2. execute command wasmer run --dir=Data test.wasm
    wasmer successfully execute the WASM binaries and print:
File descriptor 5
Set:Ok(())
Get:Ok(Fdstat { fs_filetype: Filetype { code: 4, name: "REGULAR_FILE", message: "The file descriptor or file refers to a regular file inode." }, fs_flags: 16, fs_rights_base: 536870911, fs_rights_inheriting: 262651580 })
  1. execute command wasmtime run --dir=Data test.wasm
    wasmtime fails and print:

File descriptor 4
Set:Err(Errno { code: 28, name: "INVAL", message: "Invalid argument." })
Get:Ok(Fdstat { fs_filetype: Filetype { code: 4, name: "REGULAR_FILE", message: "The file descriptor or file refers to a regular file inode." }, fs_flags: 0, fs_rights_base: 0, fs_rights_inheriting: 0 })

view this post on Zulip Wasmtime GitHub notifications bot (Jul 11 2023 at 12:53):

alexcrichton commented on issue #6713:

Thanks for the report, but this is expected. Newer versions of this function specify that the function can only set the nonblocking flag. I believe the reason for this is that it's not possible to implement this function for all flags on all platforms, which is why more recent versions of WASI specify that only one flag is supported.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 11 2023 at 12:53):

alexcrichton closed issue #6713:

Test Case

The rust file is :

use std::fs::File;
use std::os::fd::{AsRawFd, FromRawFd};
use std::fs::OpenOptions;

fn main() {
    // let file = File::open("Data/hello.txt").expect("Can not open.");
    let file = std::fs::OpenOptions::new()
        .open("Data/hello.txt")
        .expect("Failed to open file");

    let file_descriptor = file.as_raw_fd();
    println!("File descriptor {}", file_descriptor);

    unsafe{
        let p1:wasi::Fd = file_descriptor as u32;
        let p2:wasi::Fdflags = wasi::FDFLAGS_SYNC;

        println!("Set:{:?}", wasi::fd_fdstat_set_flags(p1, p2));
        println!("Get:{:?}", wasi::fd_fdstat_get(p1));
    }
}

Steps to Reproduce

  1. Use cargo build --target wasm32-wasi to compile the rust file into WASM binaries allocate.wasm.
  2. execute command wasmer run --dir=Data test.wasm
    wasmer successfully execute the WASM binaries and print:
File descriptor 5
Set:Ok(())
Get:Ok(Fdstat { fs_filetype: Filetype { code: 4, name: "REGULAR_FILE", message: "The file descriptor or file refers to a regular file inode." }, fs_flags: 16, fs_rights_base: 536870911, fs_rights_inheriting: 262651580 })
  1. execute command wasmtime run --dir=Data test.wasm
    wasmtime fails and print:

File descriptor 4
Set:Err(Errno { code: 28, name: "INVAL", message: "Invalid argument." })
Get:Ok(Fdstat { fs_filetype: Filetype { code: 4, name: "REGULAR_FILE", message: "The file descriptor or file refers to a regular file inode." }, fs_flags: 0, fs_rights_base: 0, fs_rights_inheriting: 0 })


Last updated: Dec 23 2024 at 12:05 UTC