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

A difference between windows and linux? #7633

Closed
Userzxcvbvnm opened this issue Dec 5, 2023 · 1 comment · Fixed by #7638
Closed

A difference between windows and linux? #7633

Userzxcvbvnm opened this issue Dec 5, 2023 · 1 comment · Fixed by #7638
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@Userzxcvbvnm
Copy link

Userzxcvbvnm commented Dec 5, 2023

Test Case

The test.c file is uploaded as
test-c.txt

The test.wasm file is uploaded as
test-wasm.txt

Steps to Reproduce

We create a normal file Data/hello.txt and write some initial content into the file.
using command wasmtime run --dir=./Data test.wasm to execute the wasm file.

Actual Results

In linux, wasmtime do not write any bytes into the file and prints:

Successfully get the file fd.
Current offset: 0
Wrote 0 bytes to the file.
File Size: 30 bytes
Leave snapshot.

In windows, wasmtime writes null characters (\u0000) into the file and prints:

Successfully get the file fd.
Current offset: 0
Wrote 0 bytes to the file.
File Size: 50 bytes
Leave snapshot.

There is a difference between executing the wasm file in windows and linux.
Maybe in linux, this could be a bug?

Versions and Environment

Ubuntu 20.04 (amd64)
Windows 10 (x86_64)
wasmtime 13.0.0

@Userzxcvbvnm Userzxcvbvnm added the bug Incorrect behavior in the current implementation that needs fixing label Dec 5, 2023
@pchickey
Copy link
Contributor

pchickey commented Dec 5, 2023

Thanks for the report. In the future, can you add to your reports the traces given when WASMTIME_LOG=wasmtime_wasi=trace is set in your host environment?

alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Dec 5, 2023
This commit comes from bytecodealliance#7633 where Windows and Unix would behave
differently when writing at a particular file offset. Notably Unix
semantics [indicate]:

> Before any action described below is taken, and if nbyte is zero
> and the file is a regular file, the write() function may detect
> and return errors as described below. In the absence of errors,
> or if error detection is not performed, the write() function
> shall return zero and have no other results. If nbyte is zero and
> the file is not a regular file, the results are unspecified.

These semantics are a bit easier to emulate on Windows so the host
implementation now discards any attempt to perform I/O if a zero-sized
write is detected.

[indicate]: https://man7.org/linux/man-pages/man3/write.3p.html

Closes bytecodealliance#7633
alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Feb 14, 2024
This commit comes from bytecodealliance#7633 where Windows and Unix would behave
differently when writing at a particular file offset. Notably Unix
semantics [indicate]:

> Before any action described below is taken, and if nbyte is zero
> and the file is a regular file, the write() function may detect
> and return errors as described below. In the absence of errors,
> or if error detection is not performed, the write() function
> shall return zero and have no other results. If nbyte is zero and
> the file is not a regular file, the results are unspecified.

These semantics are a bit easier to emulate on Windows so the host
implementation now discards any attempt to perform I/O if a zero-sized
write is detected.

[indicate]: https://man7.org/linux/man-pages/man3/write.3p.html

Closes bytecodealliance#7633
github-merge-queue bot pushed a commit that referenced this issue Feb 14, 2024
* Discard 0-sized writes to files

This commit comes from #7633 where Windows and Unix would behave
differently when writing at a particular file offset. Notably Unix
semantics [indicate]:

> Before any action described below is taken, and if nbyte is zero
> and the file is a regular file, the write() function may detect
> and return errors as described below. In the absence of errors,
> or if error detection is not performed, the write() function
> shall return zero and have no other results. If nbyte is zero and
> the file is not a regular file, the results are unspecified.

These semantics are a bit easier to emulate on Windows so the host
implementation now discards any attempt to perform I/O if a zero-sized
write is detected.

[indicate]: https://man7.org/linux/man-pages/man3/write.3p.html

Closes #7633

* Discard empty writes in wasi-common as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants