Auto-generate the hostcalls module of wasi-common (#846)

* Auto-generate shims for old `wasi_unstable` module

This commit is effectively just doing what #707 already did, but
applying it to the `snapshot_0` module as well. The end result is the
same, where we cut down on all the boilerplate in `snapshot_0` and bring
it in line with the main `wasi_snapshot_preview1` implementation. The
goal here is to make it easier to change the two in tandem since they're
both doing the same thing.

* Migrate `wasi_common::hostcalls` to a macro

This commit migrates the `hostcalls` module to being auto-generated by a
macro rather than duplicating a handwritten signature for each wasi
syscall.

* Auto-generate snapshot_0's `hostcalls` module

Similar to the previous commit, but for `snapshot_0`

* Delete the `wasi-common-cbindgen` crate

This is no longer needed with the hostcalls macro now, we can easily
fold the definition of the cbindgen macro into the same crate.

* Rustfmt

* Fix windows build errors

* Rustfmt

* Remove now no-longer-necessary code

* rustfmt
This commit is contained in:
Alex Crichton
2020-01-22 14:54:39 -06:00
committed by GitHub
parent 5d7635c351
commit 5953215bac
44 changed files with 391 additions and 2742 deletions

View File

@@ -16,7 +16,11 @@ use std::io::{self, Read, Seek, SeekFrom, Write};
use std::ops::DerefMut;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
pub(crate) unsafe fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasi::__wasi_fd_t) -> Result<()> {
pub(crate) unsafe fn fd_close(
wasi_ctx: &mut WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_close(fd={:?})", fd);
if let Ok(fe) = wasi_ctx.get_fd_entry(fd) {
@@ -30,7 +34,11 @@ pub(crate) unsafe fn fd_close(wasi_ctx: &mut WasiCtx, fd: wasi::__wasi_fd_t) ->
Ok(())
}
pub(crate) unsafe fn fd_datasync(wasi_ctx: &WasiCtx, fd: wasi::__wasi_fd_t) -> Result<()> {
pub(crate) unsafe fn fd_datasync(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_datasync(fd={:?})", fd);
let fd = wasi_ctx
@@ -175,6 +183,7 @@ pub(crate) unsafe fn fd_read(
pub(crate) unsafe fn fd_renumber(
wasi_ctx: &mut WasiCtx,
_mem: &mut [u8],
from: wasi::__wasi_fd_t,
to: wasi::__wasi_fd_t,
) -> Result<()> {
@@ -291,6 +300,7 @@ pub(crate) unsafe fn fd_fdstat_get(
pub(crate) unsafe fn fd_fdstat_set_flags(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
fdflags: wasi::__wasi_fdflags_t,
) -> Result<()> {
@@ -306,6 +316,7 @@ pub(crate) unsafe fn fd_fdstat_set_flags(
pub(crate) unsafe fn fd_fdstat_set_rights(
wasi_ctx: &mut WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
fs_rights_base: wasi::__wasi_rights_t,
fs_rights_inheriting: wasi::__wasi_rights_t,
@@ -329,7 +340,11 @@ pub(crate) unsafe fn fd_fdstat_set_rights(
Ok(())
}
pub(crate) unsafe fn fd_sync(wasi_ctx: &WasiCtx, fd: wasi::__wasi_fd_t) -> Result<()> {
pub(crate) unsafe fn fd_sync(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
) -> Result<()> {
trace!("fd_sync(fd={:?})", fd);
let fd = wasi_ctx
@@ -397,6 +412,7 @@ pub(crate) unsafe fn fd_write(
pub(crate) unsafe fn fd_advise(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
offset: wasi::__wasi_filesize_t,
len: wasi::__wasi_filesize_t,
@@ -420,6 +436,7 @@ pub(crate) unsafe fn fd_advise(
pub(crate) unsafe fn fd_allocate(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
offset: wasi::__wasi_filesize_t,
len: wasi::__wasi_filesize_t,
@@ -702,6 +719,7 @@ pub(crate) unsafe fn fd_filestat_get(
pub(crate) unsafe fn fd_filestat_set_times(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
st_atim: wasi::__wasi_timestamp_t,
st_mtim: wasi::__wasi_timestamp_t,
@@ -761,6 +779,7 @@ pub(crate) fn fd_filestat_set_times_impl(
pub(crate) unsafe fn fd_filestat_set_size(
wasi_ctx: &WasiCtx,
_mem: &mut [u8],
fd: wasi::__wasi_fd_t,
st_size: wasi::__wasi_filesize_t,
) -> Result<()> {