Commit Graph

198 Commits

Author SHA1 Message Date
Jakub Konka
b0199ef396 Enable Github Actions 2019-10-25 11:52:18 +02:00
Jakub Konka
8e45a14cec Fast-forward wasmtime to latest rev 2019-10-24 12:07:45 +02:00
Jakub Konka
3a374d0016 Update poll_oneoff API
This commit updates `poll_oneoff`'s API in a potentially least
invasive way. That is, it adds unused `WasiCtx` argument to the
syscall which will be required by #137. I am hopeful that this way
 #137 can pass all tests and hence this commit should aid the review
 process.
2019-10-24 11:19:33 +02:00
Dan Gohman
bd8d550ba3 Improve Cargo.toml files for publishing (#141)
* Add versions to the crates.

This is needed for publishing on crates.io.

* Add a few Cargo.toml attributes to make the crates.io page friendlier.
2019-10-23 19:17:22 +02:00
Dan Gohman
056e1d8cc0 Add more links in the fs module's documentation. 2019-10-23 19:16:18 +02:00
Jakub Konka
951456d79b Update misc_testsuite to latest master 2019-10-23 19:13:05 +02:00
Jakub Konka
63c1f71036 Sync with latest wasmtime rev
This commit syncs tests with latest wasmtime revision.
As such, it now utilises the `wasmtime-api` crate for
runtime setup.

Closes #126, #127, #128, #129.
2019-10-22 15:27:21 +02:00
Jakub Konka
0d63cc2dbc Fix remove_directory_trailing_slashes on Windows
This commit provides a fix for `remove_directory_trailing_slashes`
test case on Windows. It adds a missing mapping between the following
WinAPI error code and WASI error:

```
ERROR_DIRECTORY => __WASI_ENOTDIR
```

where `ERROR_DIRECTORY` is thrown when the directory name is invalid.
2019-10-22 10:12:54 +02:00
Dan Gohman
ef010b44b7 Fix nondeterminism in the preopen order.
We iterate over the preopens to present them to the WASI program, so
storing them in a `HashMap` means this order is nondeterministic. Switch
to a `Vec` of tuples instead. This means we don't eliminate duplicates,
but they should be rare.
2019-10-18 19:52:08 +02:00
Dan Gohman
4120d3b44f Optimize away an owned string in path_readlink. 2019-10-18 19:37:58 +02:00
Dan Gohman
14bad3cb97 Ensure that each crate has its own copy of the LICENSE file.
On crates.io, each crate is distributed separately, so ensure that each
crate has a license file.
2019-10-18 19:27:36 +02:00
Jakub Konka
c3bf04042e Fixes path_symlink_trailing_slashes test case (#125)
* Fixes `path_symlink_trailing_slashes` test case

This commit:
* adds a couple `log::debug!` macro calls in and around `path_get`
  for easier future debugging
* changes impl of `path_symlink` hostcall to actually *require*
  the final component (matching the impl of WASI in C)
* ignores the error `__WASI_ENOTDIR` in `path_get`'s `readlinkat` call
  which is not meant to be an error at this stage (i.e., this
  potentially erroneous condition *will be* handled later, in
  one of the layers above)

* Fixes `path_symlink_trailing` slashes on BSD-nixes

This commit:
* makes `path_symlink` host-specific (Linux and BSD-like nixes
  now have their own differing implementations)
* on BSD-like nixes, when `ENOTDIR` is returned from `symlinkat`
  it checks whether the target path contains a trailing slash,
  strips it, and then checks if the target path without the trailing
  slash exists; if yes, then converts the error code to `EEXIST` to
  match Linux/POSIX spec
2019-10-17 11:33:56 +02:00
Jakub Konka
d458fb6815 Clean up BSD vs Linux implementation details
This commit moves a couple of things around:
* separates the logic of `path_unlink_file` into separate impls
  for linux and BSD-style nixes
* moves implementation consts into appropriate impl modules: linux
  or bsd
* cleans up `utime_now` and `utime_omit` for BSD-style nixes
2019-10-17 11:15:01 +02:00
Jakub Konka
f1f6b3780b Fixes CraneStation/wasmtime#396
This commit fixes an issue with incorrect handling of /dev/(u)random
on Linux. It turns out that `nix::unistd::isatty` call handled only
the POSIX spec case where `ENOTTY` is returned in case the passed
in file descriptor is OK but not a TTY, whereas on Linux this is not
always the case. On Linux, it can be the case that `EINVAL` is returned
instead and this case AFAIK is not handled by the `nix` crate. This
commit fixes this by using `libc::isatty` syscall directly and checking
the return values.
2019-10-17 10:38:58 +02:00
Marcin Mielniczuk
968fb19f17 Add a typesafe enum for file type 2019-10-15 19:25:05 +09:00
Marcin Mielniczuk
5dad532a43 Use cvt from the cvt crate in winx 2019-10-15 17:15:10 +09:00
Marcin Mielniczuk
692bb27209 Correct the clippy::use_self lint where possible. (#114) 2019-10-04 18:10:30 -07:00
Jakub Konka
603f7a9f22 Misc testsuite feature gated (#113)
* Put misc_testsuite behind a feature gate

This PR puts building and generating of misc_testsuite behind
a feature gate "misc_testsuite". This is mainly to allow projects
which pull `wasi-common` as a dependency not to have to have
`wasm32-wasi` target installed in order to build it as it currently
is.

* Update the CI

* Rename feature to wasm_tests

* Explain integration testing in the README
2019-10-03 23:08:55 +02:00
Jakub Konka
da59c95f0c Update dependencies and use Once::new() instead of ONCE_INIT 2019-10-03 10:59:45 +02:00
dependabot-preview[bot]
6749015c26 Update target-lexicon requirement from 0.4.0 to 0.8.1
Updates the requirements on [target-lexicon](https://github.com/CraneStation/target-lexicon) to permit the latest version.
- [Release notes](https://github.com/CraneStation/target-lexicon/releases)
- [Commits](https://github.com/CraneStation/target-lexicon/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-03 10:03:59 +02:00
dependabot-preview[bot]
cf9cbbb519 Update cranelift-wasm requirement from 0.41.0 to 0.44.0
Updates the requirements on [cranelift-wasm](https://github.com/CraneStation/cranelift) to permit the latest version.
- [Release notes](https://github.com/CraneStation/cranelift/releases)
- [Commits](https://github.com/CraneStation/cranelift/compare/v0.41.0...v0.44.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-03 10:00:46 +02:00
dependabot-preview[bot]
c097f567a9 Update cranelift-native requirement from 0.41.0 to 0.44.0
Updates the requirements on [cranelift-native](https://github.com/CraneStation/cranelift) to permit the latest version.
- [Release notes](https://github.com/CraneStation/cranelift/releases)
- [Commits](https://github.com/CraneStation/cranelift/compare/v0.41.0...v0.44.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-03 09:58:19 +02:00
Jakub Konka
b4c60f0c36 Merge pull request #111 from CraneStation/dependabot/cargo/rand-0.7
Update rand requirement from 0.6 to 0.7
2019-10-03 09:54:18 +02:00
dependabot-preview[bot]
183611d796 Update rand requirement from 0.6 to 0.7
Updates the requirements on [rand](https://github.com/rust-random/rand) to permit the latest version.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/0.6.0...0.7.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-03 07:53:58 +00:00
dependabot-preview[bot]
825ed4f4d4 Update cranelift-entity requirement from 0.41.0 to 0.44.0
Updates the requirements on [cranelift-entity](https://github.com/CraneStation/cranelift) to permit the latest version.
- [Release notes](https://github.com/CraneStation/cranelift/releases)
- [Commits](https://github.com/CraneStation/cranelift/compare/v0.41.0...v0.44.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-03 09:52:12 +02:00
Dan Gohman
6b2f3ebf7c Begin sketching out a new high-level fs API. (#91)
* Begin sketching out a new high-level `fs` API.

This is a very preliminary sketch of #83. It doesn't even compile yet,
but it shows a possible high-level structure of such an API.

* Stub out more functionality.

* Switch from a lazy_static WasiCtx to a borrowed one.

* Reformat some comments.

* Code-quote `Self`.

* Implement error translation for Windows.

* Calls to `fd_close` are now unsafe.

* Implement a few more functions.
2019-09-30 11:27:53 -07:00
Dan Gohman
a679412dd0 Sync with lucet-wasi (#106)
* Open /dev/null for writing as well as reading.

Port this fix to wasi-common:

b905c44483

* Remove all remaining uses of `std::mem::uninitialized`.

Patch inspired by:

2d6519d051

* Replace libc::memcpy() calls with std::ptr::copy_nonoverlapping()

Port this fix to wasi-common:

a3f3a33e9b

* Pass `WasiError` by value.

It's a `u16` underneath, so we can pass it by value.

* Avoid unnecessary explicit lifetime parameters.

* Use immutable references rather than mutable references.

Patch inspired by:

54baa4c38c
2019-09-30 19:22:11 +02:00
Jakub Konka
d33036a3b5 Fix path_rename on *nix hosts
The fix contains an errno remapping in macOS case where in case
when we try to rename a file into a path with a trailing slash an
ENOENT is returned. In this case, if the destination does not exist,
an ENOTDIR should be thrown as is thrown correctly on Linux hosts.
Thus, as a fix, if an ENOENT is thrown, an additional check is
performed to see whether the destination path indeed contains
a trailing slash, and if so, the errno is adjusted to ENOTDIR
to match the POSIX/WASI spec.
2019-09-25 22:20:39 +02:00
Jakub Konka
90f1cd5c96 Fix path_remove_directory on *nixes 2019-09-17 23:22:43 +02:00
Dan Gohman
30a4f73cce Mark public API functions as unsafe. (#90)
* Mark public API functions as unsafe.

This marks the public hostcalls functions as unsafe.

This is generalizing from Rust's `from_raw_fd` function, which is
unsafe. The observation is that nothing prevents code using this
function from passing a bogus or stale dangling file descriptor and
corrupting an arbitrary open stream.

Technically, some of these functions don't use file descriptors, such as
random, clocks, and a few others. However I expect that in the future,
random and clocks will switch to using file descriptors anyway, and it
keeps the macro definitions simpler if we only have to handle one form.

* Mark WasiCtx functions that operate on file descriptors unsafe too.

* `fd_filestat_set_times_impl` doesn't need to be unsafe.

* Remove unnecessary unsafes
2019-09-16 15:55:35 -07:00
Jakub Konka
fec5b7ab0a Refactor mgmt of misc testsuite (#101)
Changes:
* use [tempfile] crate for auto mgmt of temp dirs
* use concrete types in place of generics in `utils` module

[tempfile]: https://github.com/Stebalien/tempfile
2019-09-16 15:35:14 -07:00
Jakub Konka
dfeae067cc Sync with wasmtime and update public interface
Internal modules `memory` and `host` can indeed be internal hidden
behind public-private visibility as `wasmtime-wasi` has already
been updated not to use the said modules (see
CraneStation/wasmtime#298).
2019-09-16 15:30:20 -07:00
Dan Gohman
febecc418c Make functions that operate on raw I/O handles unsafe.
Functions which trust that their arguments are valid raw file descriptors
or raw handles should be marked unsafe, because these arguments are
passed unchecked to I/O routines.
2019-09-14 21:46:38 +02:00
Jakub Konka
c98b3d10ec Fix fd_readdir on BSD-style nixes (#81)
* Fix fd_readdir on BSD-style nixes

The fix was tested on Darwin-XNU and FreeBSD. The change introduces
thread-safe cache of (RawFd, *mut libc::DIR) pairs so that
libc::fdopendir syscall is called only once when invoking fd_readdir
for the first time, and then the pointer to the directory stream,
*mut libc::DIR, is reused until the matching raw file descriptor
is closed.

This fix allows then correct use (and matching to the implementation
on Linux kernels) of libc::seekdir and libc::rewinddir to seek through
and rewind the existing directory stream, *mut libc::DIR, which
otherwise seems to be reset/invalidated every time libc::fdopendir
is called (unlike on Linux, where this behaviour is not observed).

* Store dir stream as part of the FdEntry's Descriptor

* Move bsd specifics into separate module

* Add todo comments and fix formatting

* Refactor int conversions

* Emphasise in debug logs that we're looking at fd_readdir entry

* Change visibility of FdEntry and related to public-private

* Rewrite creating DirStream for the first time
2019-09-14 21:01:39 +02:00
Jakub Konka
500e32a3b2 Use fcntl with F_RDADVISE on MacOS 2019-09-14 08:12:49 +02:00
Marcin Mielniczuk
8d7e80f440 Refactor error handling in fd_advise 2019-09-13 14:38:17 +02:00
Marcin Mielniczuk
86e3d3e307 Fix a typo in fd_advise 2019-09-13 14:38:17 +02:00
Jakub Konka
f22a468f91 Add fd_advise smoke test 2019-09-13 12:19:34 +02:00
Jakub Konka
4915f0734e Ignore failing tests for the moment 2019-09-12 08:58:19 +02:00
Jakub Konka
d69b295985 Sync wasi_misc_tests 2019-09-12 08:58:19 +02:00
Marcin Mielniczuk
f07392c175 Quick fix for path_filestat_set_times. Closes #95. 2019-09-11 15:01:01 -07:00
Dan Gohman
e85376ec07 Add doc comments to WasiCtxBuilder's methods. 2019-09-11 11:33:37 +02:00
Dan Gohman
c1c74ca54b Add a method for inhering the command-line arguments from the host. 2019-09-11 11:05:29 +02:00
Dan Gohman
aea2f11f06 Mark WasiCtx's internals as pub(crate). 2019-09-11 10:39:02 +02:00
Dan Gohman
52b69c21cf Miscellaneous clippy fixes. 2019-09-09 18:07:39 +02:00
Dan Gohman
39161d020f Clippy: use from functions rather than as casts.
`as` is a many-faceted conversion operator, while `from` functions only do
lossless conversions.
2019-09-09 18:07:39 +02:00
Dan Gohman
09ace35295 Clippy: use ptr::add rather than ptr::offset. 2019-09-09 18:07:39 +02:00
Dan Gohman
34db7f0150 Update to syn 1 and quote 1. 2019-09-09 16:33:32 +02:00
Jakub Konka
33c78e2e5b Fix formatting 2019-09-09 11:26:06 +02:00
Marcin Mielniczuk
612617b0ba reuse the host::* consts in enum Error 2019-09-09 11:26:06 +02:00