mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 22:25:40 +00:00
Add wasi state
This commit is contained in:
parent
c045da3de6
commit
94674e9d80
@ -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
5
lib/wasi/src/state.rs
Normal file
@ -0,0 +1,5 @@
|
||||
pub struct WasiState<'a> {
|
||||
// vfs: Vfs,
|
||||
pub args: &'a [u8],
|
||||
pub envs: &'a [u8],
|
||||
}
|
@ -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!()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user