Remove duplication in wasi-common for snapshot_0 (#2444)
This commit deletes the old `snapshot_0` implementation of wasi-common, along with the `wig` crate that was used to generate bindings for it. This then reimplements `snapshot_0` in terms of `wasi_snapshot_preview1`. There were very few changes between the two snapshots: * The `nlink` field of `FileStat` was increased from 32 to 64 bits. * The `set` field of `whence` was reordered. * Clock subscriptions in polling dropped their redundant userdata field. This makes all of the syscalls relatively straightforward to simply delegate to the next snapshot's implementation. Some trickery happens to avoid extra cost when dealing with iovecs, but since the memory layout of iovecs remained the same this should still work. Now that `snapshot_0` is using wiggle we simply have a trait to implement, and that's implemented for the same `WasiCtx` that has the `wasi_snapshot_preview1` trait implemented for it as well. While this theoretically means that you could share the file descriptor table between the two snapshots that's not supported in the generated bindings just yet. A separate `WasiCtx` will be created for each WASI module.
This commit is contained in:
@@ -1,13 +1,41 @@
|
||||
use wasi_common::old::snapshot_0::hostcalls;
|
||||
pub use wasi_common::old::snapshot_0::{WasiCtx, WasiCtxBuilder};
|
||||
pub use wasi_common::virtfs;
|
||||
pub use wasi_common::{WasiCtx, WasiCtxBuilder};
|
||||
|
||||
use crate::wasi_proc_exit;
|
||||
|
||||
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
||||
// with all the various WASI exports.
|
||||
wig::define_wasi_struct!("phases/old/snapshot_0/witx/wasi_unstable.witx");
|
||||
wasmtime_wiggle::wasmtime_integration!({
|
||||
// The wiggle code to integrate with lives here:
|
||||
target: wasi_common::snapshots::wasi_unstable,
|
||||
// This must be the same witx document as used above. This should be
|
||||
// ensured by the `WASI_ROOT` env variable, which is set in wasi-common's
|
||||
// `build.rs`.
|
||||
witx: ["$WASI_ROOT/phases/old/snapshot_0/witx/wasi_unstable.witx"],
|
||||
// This must be the same ctx type as used for the target:
|
||||
ctx: WasiCtx,
|
||||
// This macro will emit a struct to represent the instance,
|
||||
// with this name and docs:
|
||||
modules: { wasi_unstable =>
|
||||
{ name: Wasi,
|
||||
docs: "An instantiated instance of the wasi exports.
|
||||
|
||||
This represents a wasi module which can be used to instantiate other wasm
|
||||
modules. This structure exports all that various fields of the wasi instance
|
||||
as fields which can be used to implement your own instantiation logic, if
|
||||
necessary. Additionally [`Wasi::get_export`] can be used to do name-based
|
||||
resolution.",
|
||||
// Don't use the wiggle generated code to implement proc_exit, we need
|
||||
// to hook directly into the runtime there:
|
||||
function_override: {
|
||||
proc_exit => wasi_proc_exit
|
||||
}
|
||||
},
|
||||
},
|
||||
// Error to return when caller module is missing memory export:
|
||||
missing_memory: { wasi_common::wasi::types::Errno::Inval },
|
||||
});
|
||||
|
||||
pub fn is_wasi_module(name: &str) -> bool {
|
||||
// FIXME: this should be more conservative, but while WASI is in flux and
|
||||
// we're figuring out how to support multiple revisions, this should do the
|
||||
// trick.
|
||||
name.starts_with("wasi")
|
||||
crate::is_wasi_module(name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user