Stream: git-wasmtime

Topic: wasmtime / issue #8819 Read file bytes difference.


view this post on Zulip Wasmtime GitHub notifications bot (Jun 17 2024 at 11:23):

Userzxcvbvnm added the bug label to Issue #8819.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 17 2024 at 11:23):

Userzxcvbvnm opened issue #8819:

Test Case

The c test case is:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.h>

int get_fd(const char *filename, int flags) {
    int fd = open(filename, flags);

    if (fd == -1) {
        printf("Get file descriptor of file %s failed!\n", filename);
        return -1;
    } else {
        printf("Get file descriptor of file %s succeed!\n", filename);
        return fd;
    }
}

void closebyfd(int fd) {
    if (close(fd) == -1) {
        printf("Close the file %d by descriptor failed!\n", fd);
    }
}

void fd_read_00036_Ep05V(int fd) {
    printf("Enter function fd_read_00036_Ep05V\n");

    char buf1[47];
    char buf2[47];
    struct iovec iov[2];
    ssize_t num_read;

    iov[0].iov_base = buf1;
    iov[0].iov_len = 47;
    iov[1].iov_base = buf2;
    iov[1].iov_len = 47;

    num_read = readv(fd, iov, 2);

    if (num_read == -1) {
        printf("Error reading from file descriptor\n");
    } else {
        printf("Read %ld bytes using readv\n", num_read);
    }
}

int main() {
    int fd = get_fd("subdir_1/subdir_4/subfile_2", O_RDWR);
    if (fd == -1) {
        return 1;
    }

    fd_read_00036_Ep05V(fd);

    closebyfd(fd);

    return 0;
}

Steps to Reproduce

(1)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

(2)Running wasm:
(Before run the Wasm file, file subdir_1/subdir_4/subfile_2 exists, and the file size is 84 bytes.)
wasmtime run --dir=. test.wasm

Expected Results

Print:

Get file descriptor of file subdir_1/subdir_4/subfile_2 succeed!
Enter function fd_read_00036_Ep05V
Read 84 bytes using readv

This is what WAMR and WasmEdge do.

Actual Results

wasmtime prints:

Get file descriptor of file subdir_1/subdir_4/subfile_2 succeed!
Enter function fd_read_00036_Ep05V
Read 47 bytes using readv

wasmtime only use one buffer although two are given.

Versions and Environment

Wasmtime version or commit: 19.0.2
Operating system: Ubuntu 20.04
Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Jun 17 2024 at 16:48):

pchickey closed issue #8819:

Test Case

The c test case is:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.h>

int get_fd(const char *filename, int flags) {
    int fd = open(filename, flags);

    if (fd == -1) {
        printf("Get file descriptor of file %s failed!\n", filename);
        return -1;
    } else {
        printf("Get file descriptor of file %s succeed!\n", filename);
        return fd;
    }
}

void closebyfd(int fd) {
    if (close(fd) == -1) {
        printf("Close the file %d by descriptor failed!\n", fd);
    }
}

void fd_read_00036_Ep05V(int fd) {
    printf("Enter function fd_read_00036_Ep05V\n");

    char buf1[47];
    char buf2[47];
    struct iovec iov[2];
    ssize_t num_read;

    iov[0].iov_base = buf1;
    iov[0].iov_len = 47;
    iov[1].iov_base = buf2;
    iov[1].iov_len = 47;

    num_read = readv(fd, iov, 2);

    if (num_read == -1) {
        printf("Error reading from file descriptor\n");
    } else {
        printf("Read %ld bytes using readv\n", num_read);
    }
}

int main() {
    int fd = get_fd("subdir_1/subdir_4/subfile_2", O_RDWR);
    if (fd == -1) {
        return 1;
    }

    fd_read_00036_Ep05V(fd);

    closebyfd(fd);

    return 0;
}

Steps to Reproduce

(1)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

(2)Running wasm:
(Before run the Wasm file, file subdir_1/subdir_4/subfile_2 exists, and the file size is 84 bytes.)
wasmtime run --dir=. test.wasm

Expected Results

Print:

Get file descriptor of file subdir_1/subdir_4/subfile_2 succeed!
Enter function fd_read_00036_Ep05V
Read 84 bytes using readv

This is what WAMR and WasmEdge do.

Actual Results

wasmtime prints:

Get file descriptor of file subdir_1/subdir_4/subfile_2 succeed!
Enter function fd_read_00036_Ep05V
Read 47 bytes using readv

wasmtime only use one buffer although two are given.

Versions and Environment

Wasmtime version or commit: 19.0.2
Operating system: Ubuntu 20.04
Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Jun 17 2024 at 16:48):

pchickey commented on issue #8819:

In the vectored read/write calls, using only one the first buffer when two are given is acceptable behavior.


Last updated: Dec 23 2024 at 12:05 UTC