Commit Graph

401 Commits

Author SHA1 Message Date
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
Pat Hickey
4be3b06b61 switch from log::debug to tracing::debug
this duplicates work done in #2139 on code that moves from
where the switch took place in that PR.
2020-08-18 10:55:42 -07:00
Pat Hickey
e8160c9a6b redefine crate to use Error everywhere except in wasi 2020-08-18 10:50:17 -07:00
Pat Hickey
b8409dd9aa wasi-common: define an Error type for the crate 2020-08-18 10:50:17 -07:00
Pat Hickey
19369142cb wasi-common: trace and convert error
this is a bug - the TODO was never resolved, even when the code to
implement it was added right below :)

tracing is already in the transitive deps via wiggle, so no extra
trouble there. tracing::debug is more appropriate than eprintln
2020-08-18 10:50:17 -07:00
Pat Hickey
0e1c534e07 wasi-common: fix some warnings 2020-08-18 10:46:14 -07:00
Pat Hickey
94ee96712a wasi-common: switch all logs from log to tracing
tracing is already the dep that wiggle uses.

I used tracing structured arguments wherever I could, but I skipped over
it in all of the snapshot_0 code, because I'm going to delete that code
and replace it with wiggle-based stuff real soon.
2020-08-18 10:46:14 -07:00
Pat Hickey
19e2a46aaf bump to latest wasi submodule
witx is now 0.8.6.
2020-08-17 15:58:56 -07:00
Daiki Ueno
e70f73211d virtfs file: update cursor position on fd_read (#2070)
* virtfs file: update cursor position on fd_read

If a handle is backed by InMemoryFile, fd_read (turned into
Handle::read_vectored) doesn't update the cursor position properly and
thus prevents the caller from detecting EOF.

* virtfs file: fd_{pread,pwrite}: update offset in iovec iteration

If multiple iovec's are supplied, fd_pread and fd_pwrite previously
access data at the same offset for each iovec.
2020-07-29 14:19:17 +02:00
Dan Gohman
4c15a4daf2 Use AsRef<Path> instead of AsRef<OsStr> in yanix functions (#1950)
* Use AsRef<Path> instead of AsRef<OsStr> in yanix functions.

`AsRef<Path>` makes these more consistent with `std` interfaces, making
them easier to use outside of wasi-common.

Also, refactor the conversion to `CString` into a helper function.

* Reduce clutter from fully-qualifying names.

* rustfmt
2020-07-20 10:02:45 -07:00
Alex Crichton
2f368ed5d6 Fixes needed for 0.19.0 (#2035)
* Add some more wiggle crates to publish

* Fix build of wasi-common on crates.io

* Bump crates to 0.19.1 to fix crates.io build
2020-07-16 17:27:21 -05:00
Alex Crichton
63d5b91930 Wasmtime 0.19.0 and Cranelift 0.66.0 (#2027)
This commit updates Wasmtime's version to 0.19.0, Cranelift's version to
0.66.0, and updates the release notes as well.
2020-07-16 12:46:21 -05:00
Peter Huene
f48f9eb4b3 Merge pull request #2010 from whitequark/fix-windows-creat_trunc
WASI: make O_CREAT|O_TRUNC actually truncate files on Windows
2020-07-11 17:11:22 -07:00
whitequark
92f33284b6 WASI: make O_CREAT|O_TRUNC actually truncate files on Windows
Fixes #2009.
2020-07-10 19:23:37 +00:00
Dan Gohman
cf5289c553 Begin porting yanix to WASI.
This isn't complete yet, but subsequent steps will depend on Rust libstd
and libc bindings changes that are in flight.
2020-07-06 20:20:28 +02:00
Pat Hickey
301277e60d Merge pull request #1961 from bytecodealliance/pch/sync_wasi_pipe
wasi-common virtfs pipe: convert to be Send and Sync; fix Clone
2020-07-01 22:54:25 -07:00
Pat Hickey
e7869c7320 virtfs pipe: implement Clone correctly
* The underlying `R`/`W` doesnt need to be Clone, since we just need to
  clone the Arc it sits behind.
* The rights actually shouldn't be behind an Arc - those get mutated
  separately in each clone.
2020-07-01 17:54:30 -07:00
Pat Hickey
cf303d91fc wasi-common virtfs pipe: convert to be Send and Sync 2020-07-01 14:51:30 -07:00
Dan Gohman
b37adbbe31 Rename OFlag/AtFlag to OFlags/AtFlags. (#1951)
* Rename `OFlag`/`AtFlag` to `OFlags`/`AtFlags`.

This makes them consistent with `PollFlags` and common usage of
bitflags types in Rust code in general.

POSIX does tend to use names like `oflag` and `flag`, so this is in mild
disagreement with POSIX style, however I find this particular aspects of
POSIX confusing because these values hold multiple flags.

* rustfmt
2020-07-01 20:53:16 +02:00
Adam C. Foltzer
4f16f0dc32 Merge pull request #1949 from bytecodealliance/acf/virtual-pipes
🕳 Add virtual pipes to wasi-common
2020-07-01 11:26:13 -07:00
Adam C. Foltzer
fddd94d23f address review comments 2020-07-01 09:46:38 -07:00
Dan Gohman
959e424c81 Add O_PATH and O_CLOEXEC to yanix. (#1946)
* Add O_PATH and O_CLOEXEC to yanix.

While here, update the Wasmtime git branch name in a comment.

* Add AT_EMPTY_PATH too.
2020-06-30 11:26:59 -07:00
Adam C. Foltzer
5a96b0deaa 🕳 Add virtual pipes to wasi-common
This introduces `Handle` implementations for readable and writable pipes, backed by arbitrary `Read`
and `Write` types, respectively. In particular, this allows for easily providing, capturing, or
redirecting WASI stdio without having to resort to OS-provided file descriptors.

The implementation is based heavily on `wasi_common::virtfs::InMemoryFile`, but without inapplicable
operations like `seek` or `allocate`.

Note that these types are not 1:1 replacements for real pipes, because they do not support `poll_oneoff`.
2020-06-30 10:44:42 -07:00
Alex Crichton
a92a31d850 Rename the master branch to main (#1924)
* This PR is against a branch called `main`
* Internally all docs/CI/etc is updated
* The default branch of the repo is now `main`
* All active PRs have been updated to retarget `main`

Closes #1914
2020-06-25 14:03:21 -05:00
Pat Hickey
7d3d16aef0 wig: delete wiggle integration functionality 2020-06-22 17:24:53 -07:00
Jakub Konka
60d55a3483 Remove a runaway explicit drop 2020-06-13 15:55:01 +02:00
Dan Gohman
caa87048ab Wasmtime 0.18.0 and Cranelift 0.65.0. 2020-06-11 17:49:56 -07:00
Daiki Ueno
65ebfc3a03 wasi-common: don't rely on platform dependent "NUL" device
If stdio is not inherited nor associated with a file, WasiCtxBuilder
tries to open "/dev/null" ("NUL" on Windows) and attach stdio to it.
While most platforms today support those device files, it would be
good to avoid unnecessary access to the host device if possible.  This
patch instead uses a virtual Handle that emulates the "NUL" device.
2020-06-11 16:46:28 +02:00
Jakub Konka
f47133b229 Allow different Handles to act as stdio (#1600)
* Allow any type which implements Handle to act as stdio

There have been requests to allow more than just raw OS handles to
act as stdio in `wasi-common`. This commit makes this possible by
loosening the requirement of the `WasiCtxBuilder` to accept any
type `T: Handle + 'static` to act as any of the stdio handles.

A couple words about correctness of this approach. Currently, since
we only have a single `Handle` super-trait to represent all possible
WASI handle types (files, dirs, stdio, pipes, virtual, etc.), it
is possible to pass in any type to act as stdio which can be wrong.
However, I envision this being a problem only in the near(est) future
until we work out how to split `Handle` into several traits, each
representing a different type of WASI resource. In this particular
case, this would be a resource which would implement the interface
required for a handle to act as a stdio (with appropriate rights, etc.).

* Use OsFile in c-api

* Add some documention to the types exposed by this PR, and a few others

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>

* Add construction examples and missing docs for Handle trait

* Fix example on Windows

* Merge wasi_preview_builder into create_preview1_instance

Co-authored-by: Pat Hickey <pat@moreproductive.org>
2020-06-09 20:19:20 +02:00
Pat Hickey
dcb774a35e temporarily use tracing from git 2020-06-03 10:54:34 -07:00
Dan Gohman
a76639c6fb Wasmtime 0.17.0 and Cranelift 0.64.0. (#1805) 2020-06-02 18:51:59 -07:00
Dan Gohman
3715e19c67 Reactor support. (#1565)
* Reactor support.

This implements the new WASI ABI described here:

https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md

It adds APIs to `Instance` and `Linker` with support for running
WASI programs, and also simplifies the process of instantiating
WASI API modules.

This currently only includes Rust API support.

* Add comments and fix a typo in a comment.

* Fix a rustdoc warning.

* Tidy an unneeded `mut`.

* Factor out instance initialization with `NewInstance`.

This also separates instantiation from initialization in a manner
similar to https://github.com/bytecodealliance/lucet/pull/506.

* Update fuzzing oracles for the API changes.

* Remove `wasi_linker` and clarify that Commands/Reactors aren't connected to WASI.

* Move Command/Reactor semantics into the Linker.

* C API support.

* Fix fuzzer build.

* Update usage syntax from "::" to "=".

* Remove `NewInstance` and `start()`.

* Elaborate on Commands and Reactors and add a spec link.

* Add more comments.

* Fix wat syntax.

* Fix wat.

* Use the `Debug` formatter to format an anyhow::Error.

* Fix wat.
2020-05-26 10:39:40 -05:00
Pat Hickey
d57fea20ca Merge pull request #1717 from bytecodealliance/pch/wiggle_auto_borrow_checking
Automate borrow checking in wiggle
2020-05-22 09:35:12 -07:00
Pat Hickey
561f9e084a wig: bugfixes (sorry, thought i had tested before committimg) 2020-05-21 14:21:47 -07:00
Pat Hickey
d19a09a4be wig: wiggle now puts BorrowChecker inside GuestMemory 2020-05-21 12:40:39 -07:00
Pat Hickey
9f763375de error name change fixup 2020-05-21 12:38:06 -07:00
Pat Hickey
3920d8c1f3 code review fix 2020-05-21 12:22:47 -07:00
whitequark
e5635f4bc9 winx: do not link directly to ntdll.dll. (#1739)
The documentation for RtlNtStatusToDosError explicitly tells to call
it via GetProcAddress. The documentation for NtQueryInformationFile
does not, but similar considerations apply because there is normally
no import library for ntdll.

The main reason to use GetProcAddress though is because MinGW does
include an import library for ntdll, this import library contains
a definition of setjmp, and because of the way rustc orders linker
arguments, this definition of setjmp conflicts with and gets picked
over the one in msvcrt. Using setjmp from ntdll is undesirable as it
is an undocumented API and it is missing from wine, making it harder
to develop wasmtime using a cross-compiler.

Fixes #1738.
2020-05-21 13:56:20 -05:00