Reactor support. (#1565)
* Reactor support. This implements the new WASI ABI described here: https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md It adds APIs to `Instance` and `Linker` with support for running WASI programs, and also simplifies the process of instantiating WASI API modules. This currently only includes Rust API support. * Add comments and fix a typo in a comment. * Fix a rustdoc warning. * Tidy an unneeded `mut`. * Factor out instance initialization with `NewInstance`. This also separates instantiation from initialization in a manner similar to https://github.com/bytecodealliance/lucet/pull/506. * Update fuzzing oracles for the API changes. * Remove `wasi_linker` and clarify that Commands/Reactors aren't connected to WASI. * Move Command/Reactor semantics into the Linker. * C API support. * Fix fuzzer build. * Update usage syntax from "::" to "=". * Remove `NewInstance` and `start()`. * Elaborate on Commands and Reactors and add a spec link. * Add more comments. * Fix wat syntax. * Fix wat. * Use the `Debug` formatter to format an anyhow::Error. * Fix wat.
This commit is contained in:
@@ -117,6 +117,18 @@ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_instantiate(
|
||||
own wasm_trap_t **trap
|
||||
);
|
||||
|
||||
WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_module(
|
||||
const wasmtime_linker_t *linker,
|
||||
const wasm_name_t *name,
|
||||
const wasm_module_t *module
|
||||
);
|
||||
|
||||
WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_get_default(
|
||||
const wasmtime_linker_t *linker,
|
||||
const wasm_name_t *name,
|
||||
own wasm_func_t **func
|
||||
);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// wasmtime_caller_t extension, binding the `Caller` type in the Rust API
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::{bad_utf8, handle_result, wasmtime_error_t};
|
||||
use crate::{wasm_extern_t, wasm_store_t, ExternHost};
|
||||
use crate::{wasm_instance_t, wasm_module_t, wasm_name_t, wasm_trap_t};
|
||||
use crate::{wasm_func_t, wasm_instance_t, wasm_module_t, wasm_name_t, wasm_trap_t};
|
||||
use std::str;
|
||||
use wasmtime::{Extern, Linker};
|
||||
use wasmtime::{Extern, HostRef, Linker};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasmtime_linker_t {
|
||||
@@ -89,3 +89,33 @@ pub unsafe extern "C" fn wasmtime_linker_instantiate(
|
||||
let result = linker.linker.instantiate(&module.module.borrow());
|
||||
super::instance::handle_instantiate(result, instance_ptr, trap_ptr)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasmtime_linker_module(
|
||||
linker: &mut wasmtime_linker_t,
|
||||
name: &wasm_name_t,
|
||||
module: &wasm_module_t,
|
||||
) -> Option<Box<wasmtime_error_t>> {
|
||||
let linker = &mut linker.linker;
|
||||
let name = match str::from_utf8(name.as_slice()) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return bad_utf8(),
|
||||
};
|
||||
handle_result(linker.module(name, &module.module.borrow()), |_linker| ())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasmtime_linker_get_default(
|
||||
linker: &mut wasmtime_linker_t,
|
||||
name: &wasm_name_t,
|
||||
func: &mut *mut wasm_func_t,
|
||||
) -> Option<Box<wasmtime_error_t>> {
|
||||
let linker = &mut linker.linker;
|
||||
let name = match str::from_utf8(name.as_slice()) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return bad_utf8(),
|
||||
};
|
||||
handle_result(linker.get_default(name), |f| {
|
||||
*func = Box::into_raw(Box::new(HostRef::new(f).into()))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user