Commit Graph

238 Commits

Author SHA1 Message Date
Nick Fitzgerald
5ad82de3c5 Bump Wasmtime to 0.22.0; Cranelift to 0.69.0 2021-01-07 14:51:12 -08:00
Sakarias Johansson
22ad43b430 Add filestat_get for stdout, stdin and stderr
This makes fstat work for stdout, stdin and stderr as expected.
This seemed like the only reasonable functions to implement from the
filestat_* set, for stdout, stdin and stderr.

Fixes #2515
2020-12-16 14:33:42 +01:00
whitequark
fc4eeae896 Alias yanix::file::OFlags::RSYNC to SYNC on Android.
Android defines O_RSYNC to be the same as O_SYNC:

35bb46188c/libc/include/fcntl.h (L57)
2020-12-14 22:03:43 -08:00
whitequark
1ec1834d6e Treat Android like Linux in wasi_common::sys::unix.
Just like it happens in `yanix::sys`.
2020-12-14 22:03:43 -08:00
whitequark
476ee59774 Define local seekdir and telldir prototypes on Android.
These functions are not yet defined in the `libc` crate.
See https://github.com/rust-lang/libc/pull/1996.
2020-12-14 22:03:43 -08:00
whitequark
919600d10b Stub out the utimesat emulation logic on Android.
Android always has `utimensat` available, so it is not necessary (or
possible, for that matter) to emulate it. Mark the fallback path as
`unreachable!()`.
2020-12-14 22:03:43 -08:00
Dan Gohman
88a073eac3 rustfmt 2020-12-11 10:52:54 -08:00
Dan Gohman
c3f0471ff2 Fix the return value from wasi-common's fd_readdir.
`fd_readdir` returns a "bufused" value, which indicates the number of
bytes read into the buffer. WASI libc expects this value to be equal
to the size of the buffer if the end of the directory has not yet
been scanned.

Previously, wasi-common's `fd_readdir` was writing as many complete
entries as it could fit and then stopping, but this meant it was
returning size less than the buffer size even when the directory had
more entries. This patch makes it continue writing up until the end
of the buffer, and return that number of bytes, to let WASI libc
know that there's more to be read.

Fixes #2493.
2020-12-11 10:52:54 -08:00
Alex Crichton
efe7f37542 Remove duplication in wasi-common for snapshot_0 (#2444)
This commit deletes the old `snapshot_0` implementation of wasi-common,
along with the `wig` crate that was used to generate bindings for it.
This then reimplements `snapshot_0` in terms of
`wasi_snapshot_preview1`. There were very few changes between the two
snapshots:

* The `nlink` field of `FileStat` was increased from 32 to 64 bits.
* The `set` field of `whence` was reordered.
* Clock subscriptions in polling dropped their redundant userdata field.

This makes all of the syscalls relatively straightforward to simply
delegate to the next snapshot's implementation. Some trickery happens to
avoid extra cost when dealing with iovecs, but since the memory layout
of iovecs remained the same this should still work.

Now that `snapshot_0` is using wiggle we simply have a trait to
implement, and that's implemented for the same `WasiCtx` that has the
`wasi_snapshot_preview1` trait implemented for it as well. While this
theoretically means that you could share the file descriptor table
between the two snapshots that's not supported in the generated bindings
just yet. A separate `WasiCtx` will be created for each WASI module.
2020-11-30 12:27:49 -06:00
Tanya L. Crenshaw
b06ed39c1e Fixes #2418: Enhance wiggle to generate its UserErrorConverstion trait with a function that returns Result<abi_err, String> (#2419)
* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns
a Result<abi_err, String>.  This enhancement allows hostcall implementations using wiggle
to return an actionable error to the instance (the abi_err) or to terminate the instance
using the String as fatal error information.

* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns
a Result<abi_err, String>.  This enhancement allows hostcall implementations using wiggle
to return an actionable error to the instance (the abi_err) or to terminate the instance
using the String as fatal error information.

* Enhance the wiggle/wasmtime integration to leverage new work in ab7e9c6.  Hostcall
implementations generated by wiggle now return an Result<abi_error, Trap>.  As a
result, hostcalls experiencing fatal errors may trap, thereby terminating the
wasmtime instance.  This enhancement has been performed for both wasi snapshot1
and wasi snapshot0.

* Update wasi-nn crate to reflect enhancement in issue #2418.

* Update wiggle test-helpers for wiggle enhancement made in issue #2418.

* Address PR feedback; omit verbose return statement.

* Address PR feedback; manually format within a proc macro.

* Address PR feedback; manually format proc macro.

* Restore return statements to wasi.rs.

* Restore return statements in funcs.rs.

* Address PR feedback; omit TODO and fix formatting.

* Ok-wrap error type in assert statement.
2020-11-24 14:06:57 -06:00
Pat Hickey
26192d6760 wasi-common: opt in to mutable borrowing 2020-11-18 14:43:47 -08:00
Andrew Brown
c9e8889d47 Update clippy annotation to use latest version (#2375) 2020-11-09 09:24:59 -06:00
Alex Crichton
e4c3fc5cf2 Update immediate and transitive dependencies
I don't think this has happened in awhile but I've run a `cargo update`
as well as trimming some of the duplicate/older dependencies in
`Cargo.lock` by updating some of our immediate dependencies as well.
2020-11-05 08:34:09 -08:00
Alex Crichton
ab1958434a Bump to 0.21.0 (#2359) 2020-11-05 09:39:53 -06:00
Andrew Brown
6ebbab61b9 Update cfg-if dependency 2020-10-23 16:50:51 -07:00
Joshua Warner
eb650f6fe0 filesystem example (#2236) 2020-09-29 13:20:14 -05:00
Joshua Warner
d947010181 Don't implicitly create empty files in VirtualDir::openat (#2235)
* Don't implicitly create empty files in VirtualDir::openat

* Add test

* Add note on how to run test-program tests to the README
2020-09-25 19:52:13 -07:00
Alex Crichton
5e08eb3b83 Bump wasmtime to 0.20.0 (#2222)
At the same time bump cranelift crates to 0.67.0
2020-09-23 13:54:02 -05:00
Pat Hickey
b72d5de86c virtfs: import types from handle, drop types:: prefix 2020-09-14 16:42:20 -07:00
Pat Hickey
4763678be2 sys: import types from handle or sched, not wasi. drop types:: prefix. 2020-09-14 16:42:20 -07:00
Pat Hickey
e5129b39cb path: import types from handle rather than wasi 2020-09-14 16:42:20 -07:00
Pat Hickey
e47927f0fd fs: only import wasi Fd type in one place 2020-09-14 16:42:20 -07:00
Pat Hickey
83c1fa1b8b entry: import types from handle 2020-09-14 16:42:20 -07:00
Pat Hickey
5639881519 ctx: import Fd without any types:: prefix 2020-09-14 16:42:20 -07:00
Pat Hickey
66ba582bba sched: re-export the wasi types used for times and events 2020-09-14 16:42:20 -07:00
Pat Hickey
6db24fd08f handle: re-export all of the wasi types used by handles 2020-09-14 16:42:20 -07:00
Pat Hickey
1d410d6559 move more constructor stuff into stringarray 2020-09-02 17:16:39 -07:00
Pat Hickey
39f1c9716c restructure StringArrayWriter trait into StringArray struct 2020-09-02 14:11:32 -07:00
Pat Hickey
ddd50f7443 fix error report 2020-09-02 13:13:13 -07:00
Pat Hickey
51d88f7899 wasi-common: move implementation of args, env methods into StringArrayWriter 2020-09-01 13:50:31 -07:00
Pat Hickey
87222d6db0 wasi-common: move GuestPtr deref out of path::get 2020-09-01 13:50:30 -07:00
Pat Hickey
20ccc11564 Merge pull request #2140 from bytecodealliance/pch/wasi_error_handling
wasi-common: refactor error types
2020-09-01 13:01:26 -07:00
Pat Hickey
22b427baa0 use WASI_ROOT env var to specify witx paths to wiggle macros 2020-08-28 15:42:51 -07:00
Pat Hickey
393581b2ae Merge branch 'main' into pch/wasi_error_handling 2020-08-26 17:26:03 -07:00
Pat Hickey
7e750845cd Remove unnecessary check - fixed in std since Rust 1.38
issue now closed: https://github.com/rust-lang/rust/issues/63326
fix landed in a rollup: https://github.com/rust-lang/rust/pull/63380 merged aug 8, 2019
rust 1.38 beta cut on aug 15, 2019: https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html
minimum supported rust version for this repo is currently 1.41.
2020-08-25 17:27:47 -07:00
Pat Hickey
02aba548e1 Merge remote-tracking branch 'origin/main' into pch/wasi_error_handling 2020-08-25 15:22:51 -07:00
Pat Hickey
5e0ca3c13b tracing: some windows fixes 2020-08-25 11:32:24 -07:00
Pat Hickey
930912f783 tracing fixes in unix poll; add some missing debug impls 2020-08-25 11:29:34 -07:00
Pat Hickey
963fe37eea Update crates/wasi-common/src/sys/windows/path.rs
Co-authored-by: iximeow <git@iximeow.net>
2020-08-25 11:17:08 -07:00
Pat Hickey
fceea4e7d2 Update crates/wasi-common/src/sys/unix/mod.rs
Co-authored-by: iximeow <git@iximeow.net>
2020-08-25 11:16:48 -07:00
Pat Hickey
530ea50c82 wasi-common: dep on getrandom requires std 2020-08-19 15:10:04 -07:00
Pat Hickey
e8c01ddef1 put getrandom::Error into Error 2020-08-19 14:29:14 -07:00
Pat Hickey
c1aec81b84 add enough errno variants to cover all windows codes too 2020-08-19 12:03:38 -07:00
Pat Hickey
4535741d01 refactor when we translate io::Error to an Error
* a certain subset of io::Errors are expected - these we have
  a (platform-specific, because windows) method to translate into
  one of the wasi errno variants in the Error enum.
* some io::Errors are unexpected - wasi-common doesnt expect them from
  the underlying OS. rather than preserve any fidelity in reporting
  those to the user (only the unix impl attempts this), lets collect
  those as an `Error::UnexpectedIo(#[source] std::io::Error)`.
  Rather than trace at the conversion site, we rely on the wiggle error
  conversion hooks to trace the `Error`'s `Debug` impl, and then
  we convert all of these unexpected into `Errno::Io` for returning
  to the guest.

This is a different behavior from before, and I don't have any firm
guarantees that nobody was depending on the old behavior, but it
appears to me that none of those unexpected errnos were reasonable
to expect from any of the filesystem syscalls wasi-common is making.
2020-08-19 11:32:59 -07:00
Pat Hickey
9286bb8f08 hmm this code is challenging 2020-08-18 16:22:15 -07:00
Pat Hickey
e08173da9e fix windows: Error is not Copy like Errno is 2020-08-18 16:11:59 -07:00
Pat Hickey
94f904449b fix yanix 2020-08-18 16:02:53 -07:00
Pat Hickey
c4fbec6387 additional windows fix 2020-08-18 15:02:54 -07:00
Pat Hickey
73aef4c6ca guess i forgot a lot of these that dont build on linux 2020-08-18 15:01:04 -07:00
Pat Hickey
3bc1f84c9d windows: success fixes 2020-08-18 11:31:08 -07:00