abbec opened Issue #2515:
I am using this program to test:
#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <wasi/api.h> int main(int argc, char **argv) { __wasi_fdstat_t statbuf; printf("__wasi_fd_fdstat_get for stdout: %d\n", __wasi_fd_fdstat_get(fileno(stdout), &statbuf)); printf("rights for stdout: %llu\n", statbuf.fs_rights_base); printf("type for stdout: %d\n", statbuf.fs_filetype); printf("has filestat_get rights for stdout: %s\n", (statbuf.fs_rights_base & __WASI_RIGHTS_FD_FILESTAT_GET) != 0 ? "yes" : "no"); __wasi_filestat_t filestat; int filestat_res = __wasi_fd_filestat_get(fileno(stdout), &filestat); printf("__wasi_fd_filestat_get for stdout: %d\n", filestat_res); if (filestat_res != 0) { printf(" E: __wasi_fd_filestat_get returned error: %d\n", filestat_res); } struct stat sb; int f = fstat(fileno(stdout), &sb); printf("fstat for stdout (fd: %d): %d\n", fileno(stdout), f); if (f < 0) { perror(" E: fstat returned error"); } return 0; }
Running it with wasmtime I get:
$ wasmtime fstat.wasm __wasi_fd_fdstat_get for stdout: 0 rights for stdout: 136314954 type for stdout: 2 has filestat_get rights for stdout: yes __wasi_fd_filestat_get for stdout: 8 E: __wasi_fd_filestat_get returned error: 8 fstat for stdout (fd: 1): -1 E: fstat returned error: Bad file descriptor
and running the same with Wasmer, I instead get:
$ wasmer fstat.wasm __wasi_fd_fdstat_get for stdout: 0 rights for stdout: 136315089 type for stdout: 2 has filestat_get rights for stdout: yes __wasi_fd_filestat_get for stdout: 0 fstat for stdout (fd: 1): 0
Expected outcome
Should be able to
fstat
stdout
, right? We are trying to port a program that does that to WASI and we are running in to this.
abbec labeled Issue #2515:
I am using this program to test:
#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <wasi/api.h> int main(int argc, char **argv) { __wasi_fdstat_t statbuf; printf("__wasi_fd_fdstat_get for stdout: %d\n", __wasi_fd_fdstat_get(fileno(stdout), &statbuf)); printf("rights for stdout: %llu\n", statbuf.fs_rights_base); printf("type for stdout: %d\n", statbuf.fs_filetype); printf("has filestat_get rights for stdout: %s\n", (statbuf.fs_rights_base & __WASI_RIGHTS_FD_FILESTAT_GET) != 0 ? "yes" : "no"); __wasi_filestat_t filestat; int filestat_res = __wasi_fd_filestat_get(fileno(stdout), &filestat); printf("__wasi_fd_filestat_get for stdout: %d\n", filestat_res); if (filestat_res != 0) { printf(" E: __wasi_fd_filestat_get returned error: %d\n", filestat_res); } struct stat sb; int f = fstat(fileno(stdout), &sb); printf("fstat for stdout (fd: %d): %d\n", fileno(stdout), f); if (f < 0) { perror(" E: fstat returned error"); } return 0; }
Running it with wasmtime I get:
$ wasmtime fstat.wasm __wasi_fd_fdstat_get for stdout: 0 rights for stdout: 136314954 type for stdout: 2 has filestat_get rights for stdout: yes __wasi_fd_filestat_get for stdout: 8 E: __wasi_fd_filestat_get returned error: 8 fstat for stdout (fd: 1): -1 E: fstat returned error: Bad file descriptor
and running the same with Wasmer, I instead get:
$ wasmer fstat.wasm __wasi_fd_fdstat_get for stdout: 0 rights for stdout: 136315089 type for stdout: 2 has filestat_get rights for stdout: yes __wasi_fd_filestat_get for stdout: 0 fstat for stdout (fd: 1): 0
Expected outcome
Should be able to
fstat
stdout
, right? We are trying to port a program that does that to WASI and we are running in to this.
abbec commented on Issue #2515:
It seems to always hit this path: https://github.com/bytecodealliance/wasmtime/blob/5c1d728e3ae8ee7aa329e294999a2c3086b21676/crates/wasi-common/src/handle.rs#L123
abbec commented on Issue #2515:
Seems like
Stdin
,Stdout
andStderr
are missing implementations forfilestat_get
in https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-common/src/sys/stdio.rs?
pchickey closed Issue #2515:
I am using this program to test:
#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <wasi/api.h> int main(int argc, char **argv) { __wasi_fdstat_t statbuf; printf("__wasi_fd_fdstat_get for stdout: %d\n", __wasi_fd_fdstat_get(fileno(stdout), &statbuf)); printf("rights for stdout: %llu\n", statbuf.fs_rights_base); printf("type for stdout: %d\n", statbuf.fs_filetype); printf("has filestat_get rights for stdout: %s\n", (statbuf.fs_rights_base & __WASI_RIGHTS_FD_FILESTAT_GET) != 0 ? "yes" : "no"); __wasi_filestat_t filestat; int filestat_res = __wasi_fd_filestat_get(fileno(stdout), &filestat); printf("__wasi_fd_filestat_get for stdout: %d\n", filestat_res); if (filestat_res != 0) { printf(" E: __wasi_fd_filestat_get returned error: %d\n", filestat_res); } struct stat sb; int f = fstat(fileno(stdout), &sb); printf("fstat for stdout (fd: %d): %d\n", fileno(stdout), f); if (f < 0) { perror(" E: fstat returned error"); } return 0; }
Running it with wasmtime I get:
$ wasmtime fstat.wasm __wasi_fd_fdstat_get for stdout: 0 rights for stdout: 136314954 type for stdout: 2 has filestat_get rights for stdout: yes __wasi_fd_filestat_get for stdout: 8 E: __wasi_fd_filestat_get returned error: 8 fstat for stdout (fd: 1): -1 E: fstat returned error: Bad file descriptor
and running the same with Wasmer, I instead get:
$ wasmer fstat.wasm __wasi_fd_fdstat_get for stdout: 0 rights for stdout: 136315089 type for stdout: 2 has filestat_get rights for stdout: yes __wasi_fd_filestat_get for stdout: 0 fstat for stdout (fd: 1): 0
Expected outcome
Should be able to
fstat
stdout
, right? We are trying to port a program that does that to WASI and we are running in to this.
pchickey commented on Issue #2515:
Thanks for this report and the fix.
I'm currently working on a total rewrite of wasi-common in #2487. To make sure I don't introduce a regression on this issue, would you mind adding a unit test that stdio files give a reasonable filestat over in
crates/test-programs/wasi-tests/src/bin
?
sakarias88 commented on Issue #2515:
@pchickey
Sounds good. We will look into it.
Last updated: Nov 22 2024 at 17:03 UTC