Closed yagehu closed 7 months ago
Hi, I tested the result of the gcc native (gcc -O3 -o test main, and then ./test), it also creates a 169-byte file. It is confusing whether we should comply with wasi specification or not, if yes, we may change the behavior of C application. And I found that eventually the libc pwritev
(or pwrite
) was called with offset 0, but it is strange that it didn't write the data from offset 0.
@wenyongh Definitely a fair point. man 2 pwrite
identifies this as a Linux bug. It was first raised by Micharl Kerrisk. However, you can also argue WASI aims to be platform independent. The Wasmtime team has probably fixed it by using cap-std. I leave it up to you WAMR folks to decide if you wontfix it or not. I'm just reporting this deviation from the specification.
I did some digging and found that Wasmtime solves it in preview1 by managing the append flag and hiding it from the underlying syscall. It has nothing to do with cap-std, which simply forwards the call to Rust std.
such a "fix" would break an important use case of O_APPEND, which is multiple writers to a single file.
I did some digging and found that Wasmtime solves it in preview1 by managing the append flag and hiding it from the underlying syscall. It has nothing to do with cap-std, which simply forwards the call to Rust std. Notably, here and here.
such a "fix" would break an important use case of O_APPEND, which is multiple writers to a single file.
I don't think it would break the use case if implemented correctly considering you don't have multiple processes in WASI.
I did some digging and found that Wasmtime solves it in preview1 by managing the append flag and hiding it from the underlying syscall. It has nothing to do with cap-std, which simply forwards the call to Rust std. Notably, here and here.
such a "fix" would break an important use case of O_APPEND, which is multiple writers to a single file.
I don't think it would break the use case if implemented correctly considering you don't have multiple processes in WASI.
"multiple writers" can include a host process which is not related to wamr.
Since this is a Linux behavior, it would be hard to fix without emulating the WASI fs layer. Closing as wontfix.
This is a subtle platform-specific WAIS bug. Run the following file compiled with wasi-sdk. It creates a file
tmp/a
and performs this sequence of actions:tmp/a
.fdflags::append
flag viafcntl()
.tmp/a
withfd_pwrite
.The resulting file should be 102 bytes because
fd_pwrite
should write from offset 0 regardless of the append flag per specification (WASI specifiesfd_pwrite
to be similar to POSIXpwritev
which specifies this behavior).Wasmtime behaves correctly, producing a 102-byte file. WAMR produces a 169-byte file.