Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Import all changes from lucet-wasi #18

Merged
merged 3 commits into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,29 @@
[Wasmtime]: https://github.com/CraneStation/wasmtime
[Lucet]: https://github.com/fastly/lucet
[lucet-wasi]: https://github.com/fastly/lucet/tree/master/lucet-wasi
[lucet-wasi-tracker]: https://github.com/fastly/lucet/commit/5d3efb6005391a7c71d585732a5507b00db6bb1e
[lucet-wasi-tracker]: https://github.com/fastly/lucet/commit/40ae1df64536250a2b6ab67e7f167d22f4aa7f94
[WASI API]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md

This repo will ultimately serve as a library providing a common implementation of
WASI hostcalls for re-use in any WASI (and potentially non-WASI) runtimes
such as [Wasmtime] and [Lucet].

The library is an adaption of [lucet-wasi] crate from the [Lucet] project, and it is
currently based on [5d3efb6005][lucet-wasi-tracker] git revision.
currently based on [40ae1df][lucet-wasi-tracker] git revision.

Please note that the library requires Rust compiler version at least 1.34.0.

## Supported syscalls

We support a subset of the [WASI API], though we are working on new hostcalls
on a regular basis. We currently implement:

- `__wasi_args_get`
- `__wasi_args_sizes_get`
- `__wasi_clock_res_get`
- `__wasi_clock_time_get`
- `__wasi_environ_get`
- `__wasi_environ_sizes_get`
- `__wasi_fd_close`
- `__wasi_fd_fdstat_get`
- `__wasi_fd_fdstat_set_flags`
- `__wasi_fd_filestat_get`
- `__wasi_fd_prestat_dir_name`
- `__wasi_fd_prestat_get`
- `__wasi_fd_read`
- `__wasi_fd_seek`
- `__wasi_fd_write`
- `__wasi_path_open`
- `__wasi_path_filestat_get`
- `__wasi_path_create_directory`
- `__wasi_path_unlink_file`
- `__wasi_poll_oneoff`
- `__wasi_proc_exit`
- `__wasi_random_get`

This is enough to run basic C and Rust programs, including those that use command-line arguments,
environment variables, stdio, and basic file operations.
We currently support the entire [WASI API] with the exception of socket hostcalls:
- `sock_recv`
- `sock_send`
- `sock_shutdown`

We expect these to be implemented when network access is standardised.

We also currently do not support the `proc_raise` hostcall, as it is expected to
be dropped entirely from WASI.

## Third-Party Code
Significant parts of our hostcall implementations are derived from the C implementations in
Expand Down
12 changes: 12 additions & 0 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,18 @@ pub unsafe fn ciovec_to_nix_mut<'a>(
nix::sys::uio::IoVec::from_mut_slice(slice)
}

pub unsafe fn iovec_to_nix<'a>(iovec: &'a __wasi_iovec_t) -> nix::sys::uio::IoVec<&'a [u8]> {
let slice = std::slice::from_raw_parts(iovec.buf as *const u8, iovec.buf_len);
nix::sys::uio::IoVec::from_slice(slice)
}

pub unsafe fn iovec_to_nix_mut<'a>(
iovec: &'a mut __wasi_iovec_t,
) -> nix::sys::uio::IoVec<&'a mut [u8]> {
let slice = std::slice::from_raw_parts_mut(iovec.buf as *mut u8, iovec.buf_len);
nix::sys::uio::IoVec::from_mut_slice(slice)
}

#[cfg(target_os = "linux")]
pub const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_RSYNC;

Expand Down
Loading