Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access mode difference ? #4270

Open
orangeC23 opened this issue Oct 23, 2023 · 1 comment
Open

Access mode difference ? #4270

orangeC23 opened this issue Oct 23, 2023 · 1 comment
Labels
priority-medium Medium priority issue
Milestone

Comments

@orangeC23
Copy link

Steps to reproduce

(1)The c file 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_RDONLY;
    int fd = get_fd(file_name, open_style);
    fd_prestat_dir_name6MppH24h5k(fd);
    snapshot(fd);
    return 0;
}

int fd_prestat_dir_name6MppH24h5k (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;
}

int snapshot(int myfd){   
    printf("Enter snapshot\n");
    
    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    

    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}

(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 test.c -o test.wasm
(3)exeute open.wasm
wasmer run --dir=./Data test.wasm
The permission of Data/mydir is 0700, user1 create the Data/mydir file and user1 execute the Wasm file.

Expected behavior

wasmtime, wazero, wamr, wasmedge print:

Enter fd_prestat_dir_name
flags: 67108864
Access Mode: O_RDONLY
Access Mode: O_RDWR
Leave fd_prestat_dir_name
Enter snapshot
File Size: 4096 bytes 
Error getting current offset: Bad file descriptor
Current offset: -1 
Leave snapshot

Actual behavior

wasmer prints:

Enter fd_prestat_dir_name
flags: 335544320
Access Mode: O_RDONLY
Access Mode: O_WRONLY
Access Mode: O_RDWR
Leave fd_prestat_dir_name
Enter snapshot
File Size: 4096 bytes 
Current offset: 0 
Leave snapshot

I'm not sure whether the difference between wasmer and other runtimes could pose a bug or only difference? Could you please provide some suggestion? Thanks a lot !

version

wasmer 4.2.2

ubuntu 20.04

@Arshia001
Copy link
Member

probably related to #4259 and #4265.

@Arshia001 Arshia001 added the priority-medium Medium priority issue label Oct 24, 2023
@Arshia001 Arshia001 added this to the v4.3 milestone Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

2 participants