Add wasi state

This commit is contained in:
Lachlan Sneff 2019-03-28 12:18:05 -07:00
parent c045da3de6
commit 94674e9d80
3 changed files with 34 additions and 5 deletions

View File

@ -1,14 +1,33 @@
mod state;
mod syscalls;
use syscalls::*;
use self::state::WasiState;
use self::syscalls::*;
use std::ffi::c_void;
use wasmer_runtime_core::{func, import::ImportObject, imports};
pub fn generate_import_object() -> ImportObject {
pub fn generate_import_object(args: Vec<u8>, envs: Vec<u8>) -> ImportObject {
let state_gen = move || {
fn state_dtor(data: *mut c_void) {
unsafe {
drop(Box::from_raw(data as *mut WasiState));
}
}
let state = Box::new(WasiState {
args: &args[..],
envs: &envs[..],
});
(
Box::leak(state) as *mut WasiState as *mut c_void,
state_dtor as fn(*mut c_void),
)
};
imports! {
// This generates the wasi state.
|| {
// returns (pointer to state, function that can destruct the state).
},
state_gen,
"wasi_unstable" => {
"__wasi_args_get" => func!(__wasi_args_get),
"__wasi_args_sizes_get" => func!(__wasi_args_sizes_get),

5
lib/wasi/src/state.rs Normal file
View File

@ -0,0 +1,5 @@
pub struct WasiState<'a> {
// vfs: Vfs,
pub args: &'a [u8],
pub envs: &'a [u8],
}

View File

@ -1,5 +1,10 @@
use crate::state::WasiState;
use wasmer_runtime_core::vm::Ctx;
fn get_wasi_state(ctx: &mut Ctx) -> &mut WasiState {
unsafe { &mut *(ctx.data as *mut WasiState) }
}
pub fn __wasi_args_get(ctx: &mut Ctx) {
unimplemented!()
}