Stream: git-wasmtime

Topic: wasmtime / issue #7329 Access mode difference ?


view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2023 at 08:35):

orangeC23 added the bug label to Issue #7329.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2023 at 08:35):

orangeC23 opened issue #7329:

Steps to Reproduce

(1) The cfile is :

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

int main() {
    const char* file_name = "Data/mydir";
    int open_style= O_APPEND;
    int fd = get_fd(file_name, open_style);
    fd_prestat_dir_nameDyommnP0MC(fd);
    return 0;
}

int fd_prestat_dir_nameDyommnP0MC (int fd) {
    return fd_prestat_dir_name(fd);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_prestat_dir_name(int fd) {
    printf("Enter fd_prestat_dir_name\n");

    int flags = fcntl(fd, F_GETFL);

    if (flags == -1) {
        perror("Error getting file descriptor flags");
        return 1;
    }

    printf("flags: %d\n", flags);

    if (flags & O_RDONLY){
        printf("Access Mode: O_RDONLY\n");
    }
    if (flags & O_WRONLY){
        printf("Access Mode: O_WRONLY\n");
    }
    if (flags & O_RDWR){
        printf("Access Mode: O_RDWR\n");
    }
    if (flags & O_APPEND){
        printf("Access Mode: O_APPEND\n");
    }
    if (flags & O_NONBLOCK){
        printf("Access Mode: O_NONBLOCK\n");
    }
    if (flags & O_SYNC){
        printf("Access Mode: O_SYNC\n");
    }
    if (flags & O_DSYNC){
        printf("Access Mode: O_DSYNC\n");
    }
    if (flags & O_RSYNC){
        printf("Access Mode: O_RSYNC\n");
    }


    printf("Leave fd_prestat_dir_name\n");
    return fd;
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data test1.wasm
The permission of Data/mydir is 0700, user1 create the Data/mydir directory before and user1 execute the Wasm file.

Expected Results

Using gcc test1.c -o test1 and ./test1 to execute get the following result:

Enter fd_prestat_dir_name
flags: 33792
Access Mode: O_APPEND
Leave fd_prestat_dir_name

Actual Results

wasmtime prints:

Failed to open the file: Invalid argument
Enter fd_prestat_dir_name
flags: 268435457
Access Mode: O_WRONLY
Access Mode: O_RDWR
Access Mode: O_APPEND
Leave fd_prestat_dir_name

I'm not sure whether wasmtime and native ubuntu get different could be a bug or only difference ? Could you please provide some suggestion about the difference? Thanks a lot!

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2023 at 15:36):

alexcrichton commented on issue #7329:

Yes this is expected. WASI is not POSIX-as-is since it's portable to other environments such as the web and Windows. Differences are to be expected. If you have a specific question feel free to follow up with that though!

Also FWIW it seems like your reproduction case is going through some form of transform between what you have locally and this issue because the source above does not compile for me locally at least:

../foo.c:10:14: error: call to undeclared function 'get_fd'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    int fd = get_fd(file_name, open_style);
             ^
../foo.c:11:5: error: call to undeclared function 'fd_prestat_dir_nameDyommnP0MC'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    fd_prestat_dir_nameDyommnP0MC(fd);
    ^
../foo.c:16:12: error: call to undeclared function 'fd_prestat_dir_name'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    return fd_prestat_dir_name(fd);
           ^
3 errors generated.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2023 at 15:36):

alexcrichton closed issue #7329:

Steps to Reproduce

(1) The cfile is :

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

int main() {
    const char* file_name = "Data/mydir";
    int open_style= O_APPEND;
    int fd = get_fd(file_name, open_style);
    fd_prestat_dir_nameDyommnP0MC(fd);
    return 0;
}

int fd_prestat_dir_nameDyommnP0MC (int fd) {
    return fd_prestat_dir_name(fd);
}

int get_fd(const char* file_name, int open_style){
    // Open a file for reading
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int fd_prestat_dir_name(int fd) {
    printf("Enter fd_prestat_dir_name\n");

    int flags = fcntl(fd, F_GETFL);

    if (flags == -1) {
        perror("Error getting file descriptor flags");
        return 1;
    }

    printf("flags: %d\n", flags);

    if (flags & O_RDONLY){
        printf("Access Mode: O_RDONLY\n");
    }
    if (flags & O_WRONLY){
        printf("Access Mode: O_WRONLY\n");
    }
    if (flags & O_RDWR){
        printf("Access Mode: O_RDWR\n");
    }
    if (flags & O_APPEND){
        printf("Access Mode: O_APPEND\n");
    }
    if (flags & O_NONBLOCK){
        printf("Access Mode: O_NONBLOCK\n");
    }
    if (flags & O_SYNC){
        printf("Access Mode: O_SYNC\n");
    }
    if (flags & O_DSYNC){
        printf("Access Mode: O_DSYNC\n");
    }
    if (flags & O_RSYNC){
        printf("Access Mode: O_RSYNC\n");
    }


    printf("Leave fd_prestat_dir_name\n");
    return fd;
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot test1.c -o test1.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data test1.wasm
The permission of Data/mydir is 0700, user1 create the Data/mydir directory before and user1 execute the Wasm file.

Expected Results

Using gcc test1.c -o test1 and ./test1 to execute get the following result:

Enter fd_prestat_dir_name
flags: 33792
Access Mode: O_APPEND
Leave fd_prestat_dir_name

Actual Results

wasmtime prints:

Failed to open the file: Invalid argument
Enter fd_prestat_dir_name
flags: 268435457
Access Mode: O_WRONLY
Access Mode: O_RDWR
Access Mode: O_APPEND
Leave fd_prestat_dir_name

I'm not sure whether wasmtime and native ubuntu get different could be a bug or only difference ? Could you please provide some suggestion about the difference? Thanks a lot!

Versions and Environment

wasmtime 13.0.0
Operating system: Ubuntu 20.04

Architecture: x86_64


Last updated: Dec 23 2024 at 13:07 UTC