Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Implement the remaining hostcalls (#176)
Browse files Browse the repository at this point in the history
* Implement the remaining hostcalls

* host->wasm32 encoding: convert to little-endian if required

* Add an errno test
  • Loading branch information
jedisct1 authored May 17, 2019
1 parent 6806813 commit 40ae1df
Show file tree
Hide file tree
Showing 10 changed files with 2,851 additions and 1,362 deletions.
27 changes: 23 additions & 4 deletions lucet-wasi/bindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,40 @@
"clock_time_get": "__wasi_clock_time_get",
"environ_get": "__wasi_environ_get",
"environ_sizes_get": "__wasi_environ_sizes_get",
"proc_exit": "__wasi_proc_exit",
"fd_advise": "__wasi_fd_advise",
"fd_allocate": "__wasi_fd_allocate",
"fd_close": "__wasi_fd_close",
"fd_datasync": "__wasi_fd_datasync",
"fd_fdstat_get": "__wasi_fd_fdstat_get",
"fd_fdstat_set_flags": "__wasi_fd_fdstat_set_flags",
"fd_fdstat_set_rights": "__wasi_fd_fdstat_set_rights",
"fd_filestat_get": "__wasi_fd_filestat_get",
"fd_prestat_get": "__wasi_fd_prestat_get",
"fd_filestat_set_size": "__wasi_fd_filestat_set_size",
"fd_filestat_set_times": "__wasi_fd_filestat_set_times",
"fd_pread": "__wasi_fd_pread",
"fd_prestat_dir_name": "__wasi_fd_prestat_dir_name",
"fd_prestat_get": "__wasi_fd_prestat_get",
"fd_pwrite": "__wasi_fd_pwrite",
"fd_read": "__wasi_fd_read",
"fd_readdir": "__wasi_fd_readdir",
"fd_renumber": "__wasi_fd_renumber",
"fd_seek": "__wasi_fd_seek",
"fd_sync": "__wasi_fd_sync",
"fd_tell": "__wasi_fd_tell",
"fd_write": "__wasi_fd_write",
"path_create_directory": "__wasi_path_create_directory",
"path_filestat_get": "__wasi_path_filestat_get",
"path_unlink_file": "__wasi_path_unlink_file",
"path_filestat_set_times": "__wasi_path_filestat_set_times",
"path_link": "__wasi_path_link",
"path_open": "__wasi_path_open",
"path_readlink": "__wasi_path_readlink",
"path_remove_directory": "__wasi_path_remove_directory",
"path_rename": "__wasi_path_rename",
"path_symlink": "__wasi_path_symlink",
"path_unlink_file": "__wasi_path_unlink_file",
"poll_oneoff": "__wasi_poll_oneoff",
"random_get": "__wasi_random_get"
"proc_exit": "__wasi_proc_exit",
"random_get": "__wasi_random_get",
"sched_yield": "__wasi_sched_yield"
}
}
12 changes: 12 additions & 0 deletions lucet-wasi/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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)
}

pub fn errno_from_nix(errno: nix::errno::Errno) -> __wasi_errno_t {
let e = match errno {
nix::errno::Errno::EPERM => __WASI_EPERM,
Expand Down
Loading

0 comments on commit 40ae1df

Please sign in to comment.