From be0815467084496be206259cdc4705a9321f765a Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 11:23:08 -0700 Subject: [PATCH 01/73] Add wasi crate --- Cargo.toml | 2 +- lib/wasi/Cargo.toml | 7 +++++++ lib/wasi/src/lib.rs | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 lib/wasi/Cargo.toml create mode 100644 lib/wasi/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index a3b2066ed39..06da98dc95f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true } wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true } [workspace] -members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend"] +members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi"] [build-dependencies] wabt = "0.7.2" diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml new file mode 100644 index 00000000000..d0a670c5d39 --- /dev/null +++ b/lib/wasi/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "wasmer-wasi" +version = "0.1.0" +authors = ["The Wasmer Engineering Team "] +edition = "2018" + +[dependencies] diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/lib/wasi/src/lib.rs @@ -0,0 +1 @@ + From 0787d001e36b4b61208c5e18bcc56b210b9ef5bc Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 11:41:14 -0700 Subject: [PATCH 02/73] Add data support to import macro --- lib/runtime-core/src/import.rs | 14 ++++++++++++++ lib/runtime-core/src/macros.rs | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/runtime-core/src/import.rs b/lib/runtime-core/src/import.rs index 4c8401f06de..32b089462fd 100644 --- a/lib/runtime-core/src/import.rs +++ b/lib/runtime-core/src/import.rs @@ -4,6 +4,7 @@ use std::collections::VecDeque; use std::{ cell::{Ref, RefCell}, rc::Rc, + ffi::c_void, }; pub trait LikeNamespace { @@ -45,6 +46,7 @@ impl IsExport for Export { /// ``` pub struct ImportObject { map: Rc>>>, + state_creator: Option (*mut c_void, fn(*mut c_void))>>, } impl ImportObject { @@ -52,6 +54,17 @@ impl ImportObject { pub fn new() -> Self { Self { map: Rc::new(RefCell::new(HashMap::new())), + state_creator: None, + } + } + + pub fn new_with_data(state_creator: F) -> Self + where + F: Fn() -> (*mut c_void, fn(*mut c_void)) + 'static, + { + Self { + map: Rc::new(RefCell::new(HashMap::new())), + state_creator: Some(Rc::new(state_creator)), } } @@ -98,6 +111,7 @@ impl ImportObject { pub fn clone_ref(&self) -> Self { Self { map: Rc::clone(&self.map), + state_creator: self.state_creator.clone(), } } diff --git a/lib/runtime-core/src/macros.rs b/lib/runtime-core/src/macros.rs index e23ce1185ab..6c608fc9268 100644 --- a/lib/runtime-core/src/macros.rs +++ b/lib/runtime-core/src/macros.rs @@ -37,6 +37,13 @@ macro_rules! func { /// "foo" => func!(foo), /// }, /// }; +/// +/// let imports_with_state = imports! { +/// || (0 as _, |_a| {}), +/// "env" => { +/// "foo" => func!(foo), +/// }, +/// }; /// /// fn foo(_: &mut Ctx, n: i32) -> i32 { /// n @@ -57,6 +64,21 @@ macro_rules! imports { import_object.register($ns_name, ns); })* + import_object + }}; + ($state_gen:expr, $( $ns_name:expr => $ns:tt, )* ) => {{ + use $crate::{ + import::{ImportObject, Namespace}, + }; + + let mut import_object = ImportObject::new_with_data($state_gen); + + $({ + let ns = $crate::__imports_internal!($ns); + + import_object.register($ns_name, ns); + })* + import_object }}; } From e3a6b7c9d8ca9ded52b45a531bc098b415e762b2 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 11:44:31 -0700 Subject: [PATCH 03/73] Add skeleton for wasi abi --- lib/wasi/Cargo.toml | 1 + lib/wasi/src/lib.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index d0a670c5d39..17a2f14f429 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -5,3 +5,4 @@ authors = ["The Wasmer Engineering Team "] edition = "2018" [dependencies] +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } \ No newline at end of file diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 8b137891791..bb402c46f5e 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1 +1,18 @@ +use wasmer_runtime_core::{ + import::ImportObject, + imports, + func, +}; + +pub fn generate_import_object() -> ImportObject { + imports! { + // This generates the wasi state. + || { + // returns (pointer to state, function that can destruct the state). + }, + "wasi_unstable" => { + + }, + } +} \ No newline at end of file From b7254ce1f5a8c3e331c50aed15e6f7c08b590833 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 11:54:22 -0700 Subject: [PATCH 04/73] add stubs and dispatch --- Cargo.lock | 7 ++ lib/wasi/src/lib.rs | 56 ++++++++++++-- lib/wasi/src/syscalls/mod.rs | 137 +++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 7 deletions(-) create mode 100644 lib/wasi/src/syscalls/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 6e8811b5394..af062dc8670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1477,6 +1477,13 @@ dependencies = [ "wasmer-runtime-core 0.2.1", ] +[[package]] +name = "wasmer-wasi" +version = "0.1.0" +dependencies = [ + "wasmer-runtime-core 0.2.1", +] + [[package]] name = "wasmer-win-exception-handler" version = "0.2.0" diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index bb402c46f5e..cade0133297 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,9 +1,7 @@ +mod syscalls; +use syscalls::*; -use wasmer_runtime_core::{ - import::ImportObject, - imports, - func, -}; +use wasmer_runtime_core::{func, import::ImportObject, imports}; pub fn generate_import_object() -> ImportObject { imports! { @@ -12,7 +10,51 @@ pub fn generate_import_object() -> ImportObject { // returns (pointer to state, function that can destruct the state). }, "wasi_unstable" => { - + "__wasi_args_get" => func!(__wasi_args_get), + "__wasi_args_sizes_get" => func!(__wasi_args_sizes_get), + "__wasi_clock_res_get" => func!(__wasi_clock_res_get), + "__wasi_clock_time_get" => func!(__wasi_clock_time_get), + "__wasi_environ_get" => func!(__wasi_environ_get), + "__wasi_environ_sizes_get" => func!(__wasi_environ_sizes_get), + "__wasi_fd_advise" => func!(__wasi_fd_advise), + "__wasi_fd_allocate" => func!(__wasi_fd_allocate), + "__wasi_fd_close" => func!(__wasi_fd_close), + "__wasi_fd_datasync" => func!(__wasi_fd_datasync), + "__wasi_fd_fdstat_get" => func!(__wasi_fd_fdstat_get), + "__wasi_fd_fdstat_set_flags" => func!(__wasi_fd_fdstat_set_flags), + "__wasi_fd_fdstat_set_rights" => func!(__wasi_fd_fdstat_set_rights), + "__wasi_fd_filestat_get" => func!(__wasi_fd_filestat_get), + "__wasi_fd_filestat_set_size" => func!(__wasi_fd_filestat_set_size), + "__wasi_fd_filestat_set_times" => func!(__wasi_fd_filestat_set_times), + "__wasi_fd_pread" => func!(__wasi_fd_pread), + "__wasi_fd_prestat_get" => func!(__wasi_fd_prestat_get), + "__wasi_fd_prestat_dir_name" => func!(__wasi_fd_prestat_dir_name), + "__wasi_fd_pwrite" => func!(__wasi_fd_pwrite), + "__wasi_fd_read" => func!(__wasi_fd_read), + "__wasi_fd_readdir" => func!(__wasi_fd_readdir), + "__wasi_fd_renumber" => func!(__wasi_fd_renumber), + "__wasi_fd_seek" => func!(__wasi_fd_seek), + "__wasi_fd_sync" => func!(__wasi_fd_sync), + "__wasi_fd_tell" => func!(__wasi_fd_tell), + "__wasi_fd_write" => func!(__wasi_fd_write), + "__wasi_path_create_directory" => func!(__wasi_path_create_directory), + "__wasi_path_filestat_get" => func!(__wasi_path_filestat_get), + "__wasi_path_filestat_set_times" => func!(__wasi_path_filestat_set_times), + "__wasi_path_link" => func!(__wasi_path_link), + "__wasi_path_open" => func!(__wasi_path_open), + "__wasi_path_readlink" => func!(__wasi_path_readlink), + "__wasi_path_remove_directory" => func!(__wasi_path_remove_directory), + "__wasi_path_rename" => func!(__wasi_path_rename), + "__wasi_path_symlink" => func!(__wasi_path_symlink), + "__wasi_path_unlink_file" => func!(__wasi_path_unlink_file), + "__wasi_poll_oneoff" => func!(__wasi_poll_oneoff), + "__wasi_proc_exit" => func!(__wasi_proc_exit), + "__wasi_proc_raise" => func!(__wasi_proc_raise), + "__wasi_random_get" => func!(__wasi_random_get), + "__wasi_sched_yield" => func!(__wasi_sched_yield), + "__wasi_sock_recv" => func!(__wasi_sock_recv), + "__wasi_sock_send" => func!(__wasi_sock_send), + "__wasi_sock_shutdown" => func!(__wasi_sock_shutdown), }, } -} \ No newline at end of file +} diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs new file mode 100644 index 00000000000..f765e9c8763 --- /dev/null +++ b/lib/wasi/src/syscalls/mod.rs @@ -0,0 +1,137 @@ +use wasmer_runtime_core::vm::Ctx; + +pub fn __wasi_args_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_args_sizes_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_clock_res_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_clock_time_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_environ_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_environ_sizes_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_advise(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_allocate(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_close(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_datasync(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_fdstat_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_fdstat_set_flags(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_fdstat_set_rights(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_filestat_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_filestat_set_size(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_filestat_set_times(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_pread(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_prestat_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_prestat_dir_name(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_pwrite(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_read(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_readdir(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_renumber(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_seek(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_sync(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_tell(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_fd_write(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_create_directory(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_filestat_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_filestat_set_times(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_link(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_open(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_readlink(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_remove_directory(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_rename(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_symlink(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_path_unlink_file(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_poll_oneoff(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_proc_exit(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_proc_raise(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_random_get(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_sched_yield(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_sock_recv(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_sock_send(ctx: &mut Ctx) { + unimplemented!() +} +pub fn __wasi_sock_shutdown(ctx: &mut Ctx) { + unimplemented!() +} From 7b0992e44f21828a53c8ca8c06b234d24641c09f Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 11:56:31 -0700 Subject: [PATCH 05/73] Instance now pulls state from the ImportObject --- lib/runtime-core/src/import.rs | 8 ++++++-- lib/runtime-core/src/instance.rs | 11 ++++++++++- lib/runtime-core/src/macros.rs | 2 +- lib/runtime-core/src/vm.rs | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/runtime-core/src/import.rs b/lib/runtime-core/src/import.rs index 32b089462fd..14465deedd3 100644 --- a/lib/runtime-core/src/import.rs +++ b/lib/runtime-core/src/import.rs @@ -3,8 +3,8 @@ use hashbrown::{hash_map::Entry, HashMap}; use std::collections::VecDeque; use std::{ cell::{Ref, RefCell}, - rc::Rc, ffi::c_void, + rc::Rc, }; pub trait LikeNamespace { @@ -58,7 +58,7 @@ impl ImportObject { } } - pub fn new_with_data(state_creator: F) -> Self + pub fn new_with_data(state_creator: F) -> Self where F: Fn() -> (*mut c_void, fn(*mut c_void)) + 'static, { @@ -68,6 +68,10 @@ impl ImportObject { } } + pub(crate) fn call_state_creator(&self) -> Option<(*mut c_void, fn(*mut c_void))> { + self.state_creator.as_ref().map(|state_gen| state_gen()) + } + /// Register anything that implements `LikeNamespace` as a namespace. /// /// # Usage: diff --git a/lib/runtime-core/src/instance.rs b/lib/runtime-core/src/instance.rs index ba1dcba370c..956b95d7b5b 100644 --- a/lib/runtime-core/src/instance.rs +++ b/lib/runtime-core/src/instance.rs @@ -63,7 +63,16 @@ impl Instance { // Initialize the vm::Ctx in-place after the backing // has been boxed. unsafe { - *inner.vmctx = vm::Ctx::new(&mut inner.backing, &mut inner.import_backing, &module) + *inner.vmctx = match imports.call_state_creator() { + Some((data, dtor)) => vm::Ctx::new_with_data( + &mut inner.backing, + &mut inner.import_backing, + &module, + data, + dtor, + ), + None => vm::Ctx::new(&mut inner.backing, &mut inner.import_backing, &module), + }; }; let instance = Instance { diff --git a/lib/runtime-core/src/macros.rs b/lib/runtime-core/src/macros.rs index 6c608fc9268..0fb1c3fc9aa 100644 --- a/lib/runtime-core/src/macros.rs +++ b/lib/runtime-core/src/macros.rs @@ -37,7 +37,7 @@ macro_rules! func { /// "foo" => func!(foo), /// }, /// }; -/// +/// /// let imports_with_state = imports! { /// || (0 as _, |_a| {}), /// "env" => { diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index 8b970587e11..90afbc408a0 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -25,7 +25,7 @@ pub struct Ctx { module: *const ModuleInner, pub data: *mut c_void, - pub data_finalizer: Option, + pub data_finalizer: Option, } /// The internal context of the currently running WebAssembly instance. @@ -100,7 +100,7 @@ impl Ctx { import_backing: &mut ImportBacking, module: &ModuleInner, data: *mut c_void, - data_finalizer: extern "C" fn(*mut c_void), + data_finalizer: fn(*mut c_void), ) -> Self { Self { internal: InternalCtx { From 94674e9d80d4e8e67f5b14ffcc87b4639ffa2434 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 12:18:05 -0700 Subject: [PATCH 06/73] Add wasi state --- lib/wasi/src/lib.rs | 29 ++++++++++++++++++++++++----- lib/wasi/src/state.rs | 5 +++++ lib/wasi/src/syscalls/mod.rs | 5 +++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 lib/wasi/src/state.rs diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index cade0133297..29f2f3a4ffa 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -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, envs: Vec) -> 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), diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs new file mode 100644 index 00000000000..df5a7ca1ef8 --- /dev/null +++ b/lib/wasi/src/state.rs @@ -0,0 +1,5 @@ +pub struct WasiState<'a> { + // vfs: Vfs, + pub args: &'a [u8], + pub envs: &'a [u8], +} diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index f765e9c8763..d4402e8c04f 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -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!() } From bc863fcf0cf3cebf5b10255e0cfa283d80c7e7aa Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 12:19:23 -0700 Subject: [PATCH 07/73] hook up wasi to wasmer --- Cargo.lock | 1 + Cargo.toml | 4 +++- lib/wasi/src/lib.rs | 4 ++++ lib/wasi/src/utils.rs | 8 ++++++++ src/bin/wasmer.rs | 16 ++++++++++++++++ src/webassembly.rs | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/wasi/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index af062dc8670..18ac80db931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1339,6 +1339,7 @@ dependencies = [ "wasmer-llvm-backend 0.1.0", "wasmer-runtime 0.2.1", "wasmer-runtime-core 0.2.1", + "wasmer-wasi 0.1.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 06da98dc95f..db2a2b5f381 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ wasmer-runtime-core = { path = "lib/runtime-core" } wasmer-emscripten = { path = "lib/emscripten" } wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true } wasmer-dynasm-backend = { path = "lib/dynasm-backend", optional = true } +wasmer-wasi = { path = "lib/wasi", optional = true } [workspace] members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend", "lib/wasi"] @@ -42,4 +43,5 @@ default = ["fast-tests"] # This feature will allow cargo test to run much faster fast-tests = [] llvm = ["wasmer-llvm-backend"] -dynasm = ["wasmer-dynasm-backend"] \ No newline at end of file +dynasm = ["wasmer-dynasm-backend"] +wasi = ["wasmer-wasi"] \ No newline at end of file diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index cade0133297..d6f72cbfcf6 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,6 +1,10 @@ mod syscalls; +mod utils; + use syscalls::*; +pub use self::utils::is_wasi_module; + use wasmer_runtime_core::{func, import::ImportObject, imports}; pub fn generate_import_object() -> ImportObject { diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs new file mode 100644 index 00000000000..c6fb3267dfc --- /dev/null +++ b/lib/wasi/src/utils.rs @@ -0,0 +1,8 @@ +use wasmer_runtime_core::{module::Module, vm::Ctx}; + +// Cargo culting this from our emscripten implementation for now, but it seems like a +// good thing to check; TODO: verify this is useful +pub fn is_wasi_module(module: &Module) -> bool { + true + // TODO: +} diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 61bd50dacc9..b12465c9921 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -15,6 +15,7 @@ use wasmer::*; use wasmer_emscripten; use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}; use wasmer_runtime_core::backend::CompilerConfig; +use wasmer_wasi; #[derive(Debug, StructOpt)] #[structopt(name = "wasmer", about = "Wasm execution runtime.")] @@ -200,6 +201,8 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .map_err(|e| format!("Can't compile module: {:?}", e))? }; + // TODO: refactor this + #[cfg(not(features = "wasi"))] let (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) { let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); ( @@ -215,6 +218,19 @@ fn execute_wasm(options: &Run) -> Result<(), String> { ) }; + #[cfg(features = "wasi")] + let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { + ( + InstanceABI::WASI, + wasmer_emscripten::generate_import_object(), + ) + } else { + ( + InstanceABI::None, + wasmer_runtime_core::import::ImportObject::new(), + ) + }; + let mut instance = module .instantiate(&import_object) .map_err(|e| format!("Can't instantiate module: {:?}", e))?; diff --git a/src/webassembly.rs b/src/webassembly.rs index d3496606096..51f1e7a927d 100644 --- a/src/webassembly.rs +++ b/src/webassembly.rs @@ -21,6 +21,7 @@ pub struct ResultObject { #[derive(PartialEq)] pub enum InstanceABI { Emscripten, + WASI, None, } From 72dd995522a684ac6ed2a99b782400f2391420d8 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 12:21:44 -0700 Subject: [PATCH 08/73] fix typo --- src/bin/wasmer.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index b12465c9921..59f3c8fab84 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -220,10 +220,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { #[cfg(features = "wasi")] let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { - ( - InstanceABI::WASI, - wasmer_emscripten::generate_import_object(), - ) + (InstanceABI::WASI, wasmer_wasi::generate_import_object()) } else { ( InstanceABI::None, From dbc4176964fb7931b7b2f3665d712058e844eef4 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 12:56:11 -0700 Subject: [PATCH 09/73] Add env and args syscalls --- lib/wasi/src/lib.rs | 2 +- lib/wasi/src/state.rs | 4 +- lib/wasi/src/syscalls/mod.rs | 95 ++++++++++++++++++++++++++++++++---- 3 files changed, 88 insertions(+), 13 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 29f2f3a4ffa..edbd54aeb72 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -7,7 +7,7 @@ use std::ffi::c_void; use wasmer_runtime_core::{func, import::ImportObject, imports}; -pub fn generate_import_object(args: Vec, envs: Vec) -> ImportObject { +pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportObject { let state_gen = move || { fn state_dtor(data: *mut c_void) { unsafe { diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index df5a7ca1ef8..e7cafc1baf7 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -1,5 +1,5 @@ pub struct WasiState<'a> { // vfs: Vfs, - pub args: &'a [u8], - pub envs: &'a [u8], + pub args: &'a [Vec], + pub envs: &'a [Vec], } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d4402e8c04f..20e674b0068 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,28 +1,103 @@ use crate::state::WasiState; -use wasmer_runtime_core::vm::Ctx; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; -fn get_wasi_state(ctx: &mut Ctx) -> &mut WasiState { +fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } } -pub fn __wasi_args_get(ctx: &mut Ctx) { - unimplemented!() +fn write_buffer_array( + memory: &Memory, + from: &[Vec], + ptr_buffer_offset: u32, + buffer_offset: u32, +) { + let mut current_buffer_offset = buffer_offset; + for (i, sub_buffer) in from.iter().enumerate() { + memory.view::()[(ptr_buffer_offset as usize)..][i].set(current_buffer_offset); + for (cell, &byte) in memory.view()[(current_buffer_offset as usize)..] + .iter() + .zip(sub_buffer.iter()) + { + cell.set(byte); + } + current_buffer_offset += sub_buffer.len() as u32; + } } -pub fn __wasi_args_sizes_get(ctx: &mut Ctx) { - unimplemented!() + +/// ### `__wasi_args_get()` +/// Read command-line argument data. +/// The sizes of the buffers should match that returned by [`__wasi_args_sizes_get()`](#args_sizes_get). +/// Inputs: +/// - `char **argv` +/// A pointer to a buffer to write the argument pointers. +/// - `char *argv_buf` +/// A pointer to a buffer to write the argument string data. +/// +pub fn __wasi_args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) { + let state = get_wasi_state(ctx); + let memory = ctx.memory(0); + + write_buffer_array(memory, &*state.args, ptr_buffer_offset, buffer_offset); } + +/// ### `__wasi_args_sizes_get()` +/// Return command-line argument data sizes. +/// Outputs: +/// - `size_t *argc` +/// The number of arguments. +/// - `size_t *argv_buf_size` +/// The size of the argument string data. +pub fn __wasi_args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { + let state = get_wasi_state(ctx); + let memory = ctx.memory(0); + + let arg_count = state.args.len(); + let total_arg_size: usize = state.args.iter().map(|v| v.len()).sum(); + + memory.view::()[(argc_out / 4) as usize].set(arg_count as u32); + memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); +} + pub fn __wasi_clock_res_get(ctx: &mut Ctx) { unimplemented!() } pub fn __wasi_clock_time_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_environ_get(ctx: &mut Ctx) { - unimplemented!() + +/// ### `__wasi_environ_get()` +/// Read environment variable data. +/// The sizes of the buffers should match that returned by [`__wasi_environ_sizes_get()`](#environ_sizes_get). +/// Inputs: +/// - `char **environ` +/// A pointer to a buffer to write the environment variable pointers. +/// - `char *environ_buf` +/// A pointer to a buffer to write the environment variable string data. +pub fn __wasi_environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) { + let state = get_wasi_state(ctx); + let memory = ctx.memory(0); + + write_buffer_array(memory, &*state.args, environ, environ_buf); } -pub fn __wasi_environ_sizes_get(ctx: &mut Ctx) { - unimplemented!() + +/// ### `__wasi_environ_sizes_get()` +/// Return command-line argument data sizes. +/// Outputs: +/// - `size_t *environ_count` +/// The number of environment variables. +/// - `size_t *environ_buf_size` +/// The size of the environment variable string data. +pub fn __wasi_environ_sizes_get(ctx: &mut Ctx, environ_count_out: u32, environ_buf_size_out: u32) { + let state = get_wasi_state(ctx); + let memory = ctx.memory(0); + + let env_count = state.envs.len(); + let total_env_size: usize = state.envs.iter().map(|v| v.len()).sum(); + + memory.view::()[(environ_count_out / 4) as usize].set(env_count as u32); + memory.view::()[(environ_buf_size_out / 4) as usize].set(total_env_size as u32); } + pub fn __wasi_fd_advise(ctx: &mut Ctx) { unimplemented!() } From 256253a1d5349540670dbed4ec814e4d6692b277 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 13:10:22 -0700 Subject: [PATCH 10/73] Fix clippy lint --- lib/wasi/src/syscalls/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 20e674b0068..a05c41cea32 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,6 +1,7 @@ use crate::state::WasiState; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +#[allow(clippy::mut_from_ref)] fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } } From 3c01c11f0168501743486afea94244cdc7b83323 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 13:24:15 -0700 Subject: [PATCH 11/73] pass args and env vars to wasi --- src/bin/wasmer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 59f3c8fab84..0c493c92eed 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -220,7 +220,16 @@ fn execute_wasm(options: &Run) -> Result<(), String> { #[cfg(features = "wasi")] let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { - (InstanceABI::WASI, wasmer_wasi::generate_import_object()) + ( + InstanceABI::WASI, + wasmer_wasi::generate_import_object( + options.args.iter().map(|arg| arg.into_bytes()).collect(), + env::vars() + .iter() + .map(|(k, v)| format!("{}={}", k, v).into_bytes()) + .collect(), + ), + ) } else { ( InstanceABI::None, From a69fdfef3850925d60d3a1224badffa3dac1c5e3 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 13:46:30 -0700 Subject: [PATCH 12/73] implement wasi check --- lib/wasi/src/utils.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index c6fb3267dfc..4c3680be2e8 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -1,8 +1,15 @@ -use wasmer_runtime_core::{module::Module, vm::Ctx}; +use wasmer_runtime_core::module::Module; -// Cargo culting this from our emscripten implementation for now, but it seems like a -// good thing to check; TODO: verify this is useful +/// Check if a provided module is compiled with WASI support pub fn is_wasi_module(module: &Module) -> bool { - true - // TODO: + for (_, import_name) in &module.info().imported_functions { + let namespace = module + .info() + .namespace_table + .get(import_name.namespace_index); + if namespace == "wasi_unstable" { + return true; + } + } + false } From 5c12fd0b49665ed712beaf0fef1f61bf3d2b9764 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 13:55:38 -0700 Subject: [PATCH 13/73] fix test --- lib/runtime-core/src/vm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index 90afbc408a0..44511bb8289 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -481,7 +481,7 @@ mod vm_ctx_tests { str: String, } - extern "C" fn test_data_finalizer(data: *mut c_void) { + fn test_data_finalizer(data: *mut c_void) { let test_data: &mut TestData = unsafe { &mut *(data as *mut TestData) }; assert_eq!(test_data.x, 10); assert_eq!(test_data.y, true); From ce22818c35f0ed405114872bf88f9d43f9a33f16 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 14:22:28 -0700 Subject: [PATCH 14/73] add feature gate on import --- src/bin/wasmer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 0c493c92eed..29de018e232 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -15,6 +15,7 @@ use wasmer::*; use wasmer_emscripten; use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}; use wasmer_runtime_core::backend::CompilerConfig; +#[cfg(feature = "wasi")] use wasmer_wasi; #[derive(Debug, StructOpt)] From bde6bdfd3ac3c8d0f1727effbc6967ffd035f38c Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 14:33:15 -0700 Subject: [PATCH 15/73] Add all wasi types --- lib/wasi/src/syscalls/types.rs | 336 +++++++++++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 lib/wasi/src/syscalls/types.rs diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs new file mode 100644 index 00000000000..6a927a30119 --- /dev/null +++ b/lib/wasi/src/syscalls/types.rs @@ -0,0 +1,336 @@ +#![allow(non_camel_case_types)] + +pub type __wasi_advice_t = u8; +pub const __WASI_ADVICE_DONTNEED: u8 = 0; +pub const __WASI_ADVICE_NOREUSE: u8 = 1; +pub const __WASI_ADVICE_NORMAL: u8 = 2; +pub const __WASI_ADVICE_RANDOM: u8 = 3; +pub const __WASI_ADVICE_SEQUENTIAL: u8 = 4; +pub const __WASI_ADVICE_WILLNEED: u8 = 5; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_ciovec_t { + pub buf: u32, + pub buf_len: u32, +} + +pub type __wasi_clockid_t = u32; +pub const __WASI_CLOCK_MONOTONIC: u32 = 0; +pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 1; +pub const __WASI_CLOCK_REALTIME: u32 = 2; +pub const __WASI_CLOCK_THREAD_CPUTIME_ID: u32 = 3; + +pub type __wasi_device_t = u64; + +pub type __wasi_dircookie_t = u64; +pub const __WASI_DIRCOOKIE_START: u64 = 0; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_dirent_t { + pub d_next: __wasi_dircookie_t, + pub d_ino: __wasi_inode_t, + pub _namlen: u32, + pub d_type: __wasi_filetype_t, +} + +pub type __wasi_errno_t = u16; +pub const __WASI_ESUCCESS: u16 = 0; +pub const __WASI_E2BIG: u16 = 1; +pub const __WASI_EACCES: u16 = 2; +pub const __WASI_EADDRINUSE: u16 = 3; +pub const __WASI_EADDRNOTAVAIL: u16 = 4; +pub const __WASI_EAFNOSUPPORT: u16 = 5; +pub const __WASI_EAGAIN: u16 = 6; +pub const __WASI_EALREADY: u16 = 7; +pub const __WASI_EBADF: u16 = 8; +pub const __WASI_EBADMSG: u16 = 9; +pub const __WASI_EBUSY: u16 = 10; +pub const __WASI_ECANCELED: u16 = 11; +pub const __WASI_ECHILD: u16 = 12; +pub const __WASI_ECONNABORTED: u16 = 13; +pub const __WASI_ECONNREFUSED: u16 = 14; +pub const __WASI_ECONNRESET: u16 = 15; +pub const __WASI_EDEADLK: u16 = 16; +pub const __WASI_EDESTADDRREQ: u16 = 17; +pub const __WASI_EDOM: u16 = 18; +pub const __WASI_EDQUOT: u16 = 19; +pub const __WASI_EEXIST: u16 = 20; +pub const __WASI_EFAULT: u16 = 21; +pub const __WASI_EFBIG: u16 = 22; +pub const __WASI_EHOSTUNREACH: u16 = 23; +pub const __WASI_EIDRM: u16 = 24; +pub const __WASI_EILSEQ: u16 = 25; +pub const __WASI_EINPROGRESS: u16 = 26; +pub const __WASI_EINTR: u16 = 27; +pub const __WASI_EINVAL: u16 = 28; +pub const __WASI_EIO: u16 = 29; +pub const __WASI_EISCONN: u16 = 30; +pub const __WASI_EISDIR: u16 = 31; +pub const __WASI_ELOOP: u16 = 32; +pub const __WASI_EMFILE: u16 = 33; +pub const __WASI_EMLINK: u16 = 34; +pub const __WASI_EMSGSIZE: u16 = 35; +pub const __WASI_EMULTIHOP: u16 = 36; +pub const __WASI_ENAMETOOLONG: u16 = 37; +pub const __WASI_ENETDOWN: u16 = 38; +pub const __WASI_ENETRESET: u16 = 39; +pub const __WASI_ENETUNREACH: u16 = 40; +pub const __WASI_ENFILE: u16 = 41; +pub const __WASI_ENOBUFS: u16 = 42; +pub const __WASI_ENODEV: u16 = 43; +pub const __WASI_ENOENT: u16 = 44; +pub const __WASI_ENOEXEC: u16 = 45; +pub const __WASI_ENOLCK: u16 = 46; +pub const __WASI_ENOLINK: u16 = 47; +pub const __WASI_ENOMEM: u16 = 48; +pub const __WASI_ENOMSG: u16 = 49; +pub const __WASI_ENOPROTOOPT: u16 = 50; +pub const __WASI_ENOSPC: u16 = 51; +pub const __WASI_ENOSYS: u16 = 52; +pub const __WASI_ENOTCONN: u16 = 53; +pub const __WASI_ENOTDIR: u16 = 54; +pub const __WASI_ENOTEMPTY: u16 = 55; +pub const __WASI_ENOTRECOVERABLE: u16 = 56; +pub const __WASI_ENOTSOCK: u16 = 57; +pub const __WASI_ENOTSUP: u16 = 58; +pub const __WASI_ENOTTY: u16 = 59; +pub const __WASI_ENXIO: u16 = 60; +pub const __WASI_EOVERFLOW: u16 = 61; +pub const __WASI_EOWNERDEAD: u16 = 62; +pub const __WASI_EPERM: u16 = 63; +pub const __WASI_EPIPE: u16 = 64; +pub const __WASI_EPROTO: u16 = 65; +pub const __WASI_EPROTONOSUPPORT: u16 = 66; +pub const __WASI_EPROTOTYPE: u16 = 67; +pub const __WASI_ERANGE: u16 = 68; +pub const __WASI_EROFS: u16 = 69; +pub const __WASI_ESPIPE: u16 = 70; +pub const __WASI_ESRCH: u16 = 71; +pub const __WASI_ESTALE: u16 = 72; +pub const __WASI_ETIMEDOUT: u16 = 73; +pub const __WASI_ETXTBSY: u16 = 74; +pub const __WASI_EXDEV: u16 = 75; +pub const __WASI_ENOTCAPABLE: u16 = 76; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_event_fd_readwrite_t { + pub nbytes: __wasi_filesize_t, + pub flags: __wasi_eventrwflags_t, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub union __wasi_event_u { + fd_readwrite: __wasi_event_fd_readwrite_t, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct __wasi_event_t { + pub userdata: __wasi_userdata_t, + pub error: __wasi_errno_t, + pub type_: __wasi_eventtype_t, + pub u: __wasi_event_u, +} + +pub type __wasi_eventrwflags_t = u16; +pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 1 << 0; + +pub type __wasi_eventtype_t = u8; +pub const __WASI_EVENTTYPE_CLOCK: u8 = 0; +pub const __WASI_EVENTTYPE_FD_READ: u8 = 1; +pub const __WASI_EVENTTYPE_FD_WRITE: u8 = 2; + +pub type __wasi_exitcode_t = u32; + +pub type __wasi_fd_t = u32; +pub const __WASI_STDIN_FILENO: u32 = 0; +pub const __WASI_STDOUT_FILENO: u32 = 1; +pub const __WASI_STDERR_FILENO: u32 = 2; + +pub type __wasi_fdflags_t = u16; +pub const __WASI_FDFLAG_APPEND: u16 = 1 << 0; +pub const __WASI_FDFLAG_DSYNC: u16 = 1 << 1; +pub const __WASI_FDFLAG_NONBLOCK: u16 = 1 << 2; +pub const __WASI_FDFLAG_RSYNC: u16 = 1 << 3; +pub const __WASI_FDFLAG_SYNC: u16 = 1 << 4; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_fdstat_t { + pub fs_filetype: __wasi_filetype_t, + pub fs_flags: __wasi_fdflags_t, + pub fs_rights_base: __wasi_rights_t, + pub fs_rights_inheriting: __wasi_rights_t, +} + +pub type __wasi_filedelta_t = i64; + +pub type __wasi_filesize_t = u64; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_filestat_t { + pub st_dev: __wasi_device_t, + pub st_ino: __wasi_inode_t, + pub st_filetype: __wasi_filetype_t, + pub st_nlink: __wasi_linkcount_t, + pub st_size: __wasi_filesize_t, + pub st_atim: __wasi_timestamp_t, + pub st_mtim: __wasi_timestamp_t, + pub st_ctim: __wasi_timestamp_t, +} + +pub type __wasi_filetype_t = u8; +pub const __WASI_FILETYPE_UNKNOWN: u8 = 0; +pub const __WASI_FILETYPE_BLOCK_DEVICE: u8 = 1; +pub const __WASI_FILETYPE_CHARACTER_DEVICE: u8 = 2; +pub const __WASI_FILETYPE_DIRECTORY: u8 = 3; +pub const __WASI_FILETYPE_REGULAR_FILE: u8 = 4; +pub const __WASI_FILETYPE_SOCKET_DGRAM: u8 = 5; +pub const __WASI_FILETYPE_SOCKET_STREAM: u8 = 6; +pub const __WASI_FILETYPE_SYMBOLIC_LINK: u8 = 7; + +pub type __wasi_fstflags_t = u16; +pub const __WASI_FILESTAT_SET_ATIM: u16 = 1 << 0; +pub const __WASI_FILESTAT_SET_ATIM_NOW: u16 = 1 << 1; +pub const __WASI_FILESTAT_SET_MTIM: u16 = 1 << 2; +pub const __WASI_FILESTAT_SET_MTIM_NOW: u16 = 1 << 3; + +pub type __wasi_inode_t = u64; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_iovec_t { + pub buf: u32, + pub buf_len: u32, +} + +pub type __wasi_linkcount_t = u32; + +pub type __wasi_lookupflags_t = u32; +pub const __WASI_LOOKUP_SYMLINK_FOLLOW: u32 = 1 << 0; + +pub type __wasi_oflags_t = u16; +pub const __WASI_O_CREAT: u16 = 1 << 0; +pub const __WASI_O_DIRECTORY: u16 = 1 << 1; +pub const __WASI_O_EXCL: u16 = 1 << 2; +pub const __WASI_O_TRUNC: u16 = 1 << 3; + +pub type __wasi_riflags = u16; +pub const __WASI_SOCK_RECV_PEEK: u16 = 1 << 0; +pub const __WASI_SOCK_RECV_WAITALL: u16 = 1 << 1; + +pub type __wasi_rights_t = u64; +pub const __WASI_RIGHT_FD_DATASYNC: u64 = 1 << 0; +pub const __WASI_RIGHT_FD_READ: u64 = 1 << 1; +pub const __WASI_RIGHT_FD_SEEK: u64 = 1 << 2; +pub const __WASI_RIGHT_FD_FDSTAT_SET_FLAGS: u64 = 1 << 3; +pub const __WASI_RIGHT_FD_SYNC: u64 = 1 << 4; +pub const __WASI_RIGHT_FD_TELL: u64 = 1 << 5; +pub const __WASI_RIGHT_FD_WRITE: u64 = 1 << 6; +pub const __WASI_RIGHT_FD_ADVISE: u64 = 1 << 7; +pub const __WASI_RIGHT_FD_ALLOCATE: u64 = 1 << 8; +pub const __WASI_RIGHT_PATH_CREATE_DIRECTORY: u64 = 1 << 9; +pub const __WASI_RIGHT_PATH_CREATE_FILE: u64 = 1 << 10; +pub const __WASI_RIGHT_PATH_LINK_SOURCE: u64 = 1 << 11; +pub const __WASI_RIGHT_PATH_LINK_TARGET: u64 = 1 << 12; +pub const __WASI_RIGHT_PATH_OPEN: u64 = 1 << 13; +pub const __WASI_RIGHT_FD_READDIR: u64 = 1 << 14; +pub const __WASI_RIGHT_PATH_READLINK: u64 = 1 << 15; +pub const __WASI_RIGHT_PATH_RENAME_SOURCE: u64 = 1 << 16; +pub const __WASI_RIGHT_PATH_RENAME_TARGET: u64 = 1 << 17; +pub const __WASI_RIGHT_PATH_FILESTAT_GET: u64 = 1 << 18; +pub const __WASI_RIGHT_PATH_FILESTAT_SET_SIZE: u64 = 1 << 19; +pub const __WASI_RIGHT_PATH_FILESTAT_SET_TIMES: u64 = 1 << 20; +pub const __WASI_RIGHT_FD_FILESTAT_GET: u64 = 1 << 21; +pub const __WASI_RIGHT_FD_FILESTAT_SET_SIZE: u64 = 1 << 22; +pub const __WASI_RIGHT_FD_FILESTAT_SET_TIMES: u64 = 1 << 23; +pub const __WASI_RIGHT_PATH_SYMLINK: u64 = 1 << 24; +pub const __WASI_RIGHT_PATH_UNLINK_FILE: u64 = 1 << 25; +pub const __WASI_RIGHT_PATH_REMOVE_DIRECTORY: u64 = 1 << 26; +pub const __WASI_RIGHT_POLL_FD_READWRITE: u64 = 1 << 27; +pub const __WASI_RIGHT_SOCK_SHUTDOWN: u64 = 1 << 28; + +pub type __wasi_roflags_t = u16; +pub const __WASI_SOCK_RECV_DATA_TRUNCATED: u16 = 1 << 0; + +pub type __wasi_sdflags_t = u8; +pub const __WASI_SHUT_RD: u8 = 1 << 0; +pub const __WASI_SHUT_WR: u8 = 1 << 1; + +pub type __wasi_siflags_t = u16; + +pub type __wasi_signal_t = u8; +pub const __WASI_SIGABRT: u8 = 0; +pub const __WASI_SIGALRM: u8 = 1; +pub const __WASI_SIGBUS: u8 = 2; +pub const __WASI_SIGCHLD: u8 = 3; +pub const __WASI_SIGCONT: u8 = 4; +pub const __WASI_SIGFPE: u8 = 5; +pub const __WASI_SIGHUP: u8 = 6; +pub const __WASI_SIGILL: u8 = 7; +pub const __WASI_SIGINT: u8 = 8; +pub const __WASI_SIGKILL: u8 = 9; +pub const __WASI_SIGPIPE: u8 = 10; +pub const __WASI_SIGQUIT: u8 = 11; +pub const __WASI_SIGSEGV: u8 = 12; +pub const __WASI_SIGSTOP: u8 = 13; +pub const __WASI_SIGSYS: u8 = 14; +pub const __WASI_SIGTERM: u8 = 15; +pub const __WASI_SIGTRAP: u8 = 16; +pub const __WASI_SIGTSTP: u8 = 17; +pub const __WASI_SIGTTIN: u8 = 18; +pub const __WASI_SIGTTOU: u8 = 19; +pub const __WASI_SIGURG: u8 = 20; +pub const __WASI_SIGUSR1: u8 = 21; +pub const __WASI_SIGUSR2: u8 = 22; +pub const __WASI_SIGVTALRM: u8 = 23; +pub const __WASI_SIGXCPU: u8 = 24; +pub const __WASI_SIGXFSZ: u8 = 25; + +pub type __wasi_subclockflags_t = u16; +pub const __WASI_SUBSCRIPTION_CLOCK_ABSTIME: u16 = 1 << 0; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_subscription_clock_t { + pub userdata: __wasi_userdata_t, + pub clock_id: __wasi_clockid_t, + pub timeout: __wasi_timestamp_t, + pub precision: __wasi_timestamp_t, + pub flags: __wasi_subclockflags_t, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_subscription_fs_readwrite_t { + pub fd: __wasi_fd_t, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub union __wasi_subscription_u { + clock: __wasi_subscription_clock_t, + fd_readwrite: __wasi_subscription_fs_readwrite_t, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct __wasi_subscription_t { + pub userdata: __wasi_userdata_t, + pub type_: __wasi_eventtype_t, + pub u: __wasi_subscription_u, +} + +pub type __wasi_timestamp_t = u64; + +pub type __wasi_userdata_t = u64; + +pub type __wasi_whence_t = u8; +pub const __WASI_WHENCE_CUR: u8 = 0; +pub const __WASI_WHENCE_END: u8 = 1; +pub const __WASI_WHENCE_SET: u8 = 2; From aed9d3b9b7a07a35cf5b885f990dfe89907ccaac Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 15:17:52 -0700 Subject: [PATCH 16/73] remove __wasi_ prefix --- lib/wasi/src/lib.rs | 90 +++++++++++++++---------------- lib/wasi/src/syscalls/mod.rs | 102 +++++++++++++++++------------------ 2 files changed, 96 insertions(+), 96 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 64c2750cbce..b62f84dfb98 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -33,51 +33,51 @@ pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportO // This generates the wasi state. state_gen, "wasi_unstable" => { - "__wasi_args_get" => func!(__wasi_args_get), - "__wasi_args_sizes_get" => func!(__wasi_args_sizes_get), - "__wasi_clock_res_get" => func!(__wasi_clock_res_get), - "__wasi_clock_time_get" => func!(__wasi_clock_time_get), - "__wasi_environ_get" => func!(__wasi_environ_get), - "__wasi_environ_sizes_get" => func!(__wasi_environ_sizes_get), - "__wasi_fd_advise" => func!(__wasi_fd_advise), - "__wasi_fd_allocate" => func!(__wasi_fd_allocate), - "__wasi_fd_close" => func!(__wasi_fd_close), - "__wasi_fd_datasync" => func!(__wasi_fd_datasync), - "__wasi_fd_fdstat_get" => func!(__wasi_fd_fdstat_get), - "__wasi_fd_fdstat_set_flags" => func!(__wasi_fd_fdstat_set_flags), - "__wasi_fd_fdstat_set_rights" => func!(__wasi_fd_fdstat_set_rights), - "__wasi_fd_filestat_get" => func!(__wasi_fd_filestat_get), - "__wasi_fd_filestat_set_size" => func!(__wasi_fd_filestat_set_size), - "__wasi_fd_filestat_set_times" => func!(__wasi_fd_filestat_set_times), - "__wasi_fd_pread" => func!(__wasi_fd_pread), - "__wasi_fd_prestat_get" => func!(__wasi_fd_prestat_get), - "__wasi_fd_prestat_dir_name" => func!(__wasi_fd_prestat_dir_name), - "__wasi_fd_pwrite" => func!(__wasi_fd_pwrite), - "__wasi_fd_read" => func!(__wasi_fd_read), - "__wasi_fd_readdir" => func!(__wasi_fd_readdir), - "__wasi_fd_renumber" => func!(__wasi_fd_renumber), - "__wasi_fd_seek" => func!(__wasi_fd_seek), - "__wasi_fd_sync" => func!(__wasi_fd_sync), - "__wasi_fd_tell" => func!(__wasi_fd_tell), - "__wasi_fd_write" => func!(__wasi_fd_write), - "__wasi_path_create_directory" => func!(__wasi_path_create_directory), - "__wasi_path_filestat_get" => func!(__wasi_path_filestat_get), - "__wasi_path_filestat_set_times" => func!(__wasi_path_filestat_set_times), - "__wasi_path_link" => func!(__wasi_path_link), - "__wasi_path_open" => func!(__wasi_path_open), - "__wasi_path_readlink" => func!(__wasi_path_readlink), - "__wasi_path_remove_directory" => func!(__wasi_path_remove_directory), - "__wasi_path_rename" => func!(__wasi_path_rename), - "__wasi_path_symlink" => func!(__wasi_path_symlink), - "__wasi_path_unlink_file" => func!(__wasi_path_unlink_file), - "__wasi_poll_oneoff" => func!(__wasi_poll_oneoff), - "__wasi_proc_exit" => func!(__wasi_proc_exit), - "__wasi_proc_raise" => func!(__wasi_proc_raise), - "__wasi_random_get" => func!(__wasi_random_get), - "__wasi_sched_yield" => func!(__wasi_sched_yield), - "__wasi_sock_recv" => func!(__wasi_sock_recv), - "__wasi_sock_send" => func!(__wasi_sock_send), - "__wasi_sock_shutdown" => func!(__wasi_sock_shutdown), + "args_get" => func!(args_get), + "args_sizes_get" => func!(args_sizes_get), + "clock_res_get" => func!(clock_res_get), + "clock_time_get" => func!(clock_time_get), + "environ_get" => func!(environ_get), + "environ_sizes_get" => func!(environ_sizes_get), + "fd_advise" => func!(fd_advise), + "fd_allocate" => func!(fd_allocate), + "fd_close" => func!(fd_close), + "fd_datasync" => func!(fd_datasync), + "fd_fdstat_get" => func!(fd_fdstat_get), + "fd_fdstat_set_flags" => func!(fd_fdstat_set_flags), + "fd_fdstat_set_rights" => func!(fd_fdstat_set_rights), + "fd_filestat_get" => func!(fd_filestat_get), + "fd_filestat_set_size" => func!(fd_filestat_set_size), + "fd_filestat_set_times" => func!(fd_filestat_set_times), + "fd_pread" => func!(fd_pread), + "fd_prestat_get" => func!(fd_prestat_get), + "fd_prestat_dir_name" => func!(fd_prestat_dir_name), + "fd_pwrite" => func!(fd_pwrite), + "fd_read" => func!(fd_read), + "fd_readdir" => func!(fd_readdir), + "fd_renumber" => func!(fd_renumber), + "fd_seek" => func!(fd_seek), + "fd_sync" => func!(fd_sync), + "fd_tell" => func!(fd_tell), + "fd_write" => func!(fd_write), + "path_create_directory" => func!(path_create_directory), + "path_filestat_get" => func!(path_filestat_get), + "path_filestat_set_times" => func!(path_filestat_set_times), + "path_link" => func!(path_link), + "path_open" => func!(path_open), + "path_readlink" => func!(path_readlink), + "path_remove_directory" => func!(path_remove_directory), + "path_rename" => func!(path_rename), + "path_symlink" => func!(path_symlink), + "path_unlink_file" => func!(path_unlink_file), + "poll_oneoff" => func!(poll_oneoff), + "proc_exit" => func!(proc_exit), + "proc_raise" => func!(proc_raise), + "random_get" => func!(random_get), + "sched_yield" => func!(sched_yield), + "sock_recv" => func!(sock_recv), + "sock_send" => func!(sock_send), + "sock_shutdown" => func!(sock_shutdown), }, } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index a05c41cea32..0c5f2f9b018 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -25,30 +25,30 @@ fn write_buffer_array( } } -/// ### `__wasi_args_get()` +/// ### `args_get()` /// Read command-line argument data. -/// The sizes of the buffers should match that returned by [`__wasi_args_sizes_get()`](#args_sizes_get). +/// The sizes of the buffers should match that returned by [`args_sizes_get()`](#args_sizes_get). /// Inputs: /// - `char **argv` /// A pointer to a buffer to write the argument pointers. /// - `char *argv_buf` /// A pointer to a buffer to write the argument string data. /// -pub fn __wasi_args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) { +pub fn args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) { let state = get_wasi_state(ctx); let memory = ctx.memory(0); write_buffer_array(memory, &*state.args, ptr_buffer_offset, buffer_offset); } -/// ### `__wasi_args_sizes_get()` +/// ### `args_sizes_get()` /// Return command-line argument data sizes. /// Outputs: /// - `size_t *argc` /// The number of arguments. /// - `size_t *argv_buf_size` /// The size of the argument string data. -pub fn __wasi_args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { +pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { let state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -59,36 +59,36 @@ pub fn __wasi_args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u3 memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); } -pub fn __wasi_clock_res_get(ctx: &mut Ctx) { +pub fn clock_res_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_clock_time_get(ctx: &mut Ctx) { +pub fn clock_time_get(ctx: &mut Ctx) { unimplemented!() } -/// ### `__wasi_environ_get()` +/// ### `environ_get()` /// Read environment variable data. -/// The sizes of the buffers should match that returned by [`__wasi_environ_sizes_get()`](#environ_sizes_get). +/// The sizes of the buffers should match that returned by [`environ_sizes_get()`](#environ_sizes_get). /// Inputs: /// - `char **environ` /// A pointer to a buffer to write the environment variable pointers. /// - `char *environ_buf` /// A pointer to a buffer to write the environment variable string data. -pub fn __wasi_environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) { +pub fn environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) { let state = get_wasi_state(ctx); let memory = ctx.memory(0); write_buffer_array(memory, &*state.args, environ, environ_buf); } -/// ### `__wasi_environ_sizes_get()` +/// ### `environ_sizes_get()` /// Return command-line argument data sizes. /// Outputs: /// - `size_t *environ_count` /// The number of environment variables. /// - `size_t *environ_buf_size` /// The size of the environment variable string data. -pub fn __wasi_environ_sizes_get(ctx: &mut Ctx, environ_count_out: u32, environ_buf_size_out: u32) { +pub fn environ_sizes_get(ctx: &mut Ctx, environ_count_out: u32, environ_buf_size_out: u32) { let state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -99,120 +99,120 @@ pub fn __wasi_environ_sizes_get(ctx: &mut Ctx, environ_count_out: u32, environ_b memory.view::()[(environ_buf_size_out / 4) as usize].set(total_env_size as u32); } -pub fn __wasi_fd_advise(ctx: &mut Ctx) { +pub fn fd_advise(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_allocate(ctx: &mut Ctx) { +pub fn fd_allocate(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_close(ctx: &mut Ctx) { +pub fn fd_close(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_datasync(ctx: &mut Ctx) { +pub fn fd_datasync(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_fdstat_get(ctx: &mut Ctx) { +pub fn fd_fdstat_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_fdstat_set_flags(ctx: &mut Ctx) { +pub fn fd_fdstat_set_flags(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_fdstat_set_rights(ctx: &mut Ctx) { +pub fn fd_fdstat_set_rights(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_filestat_get(ctx: &mut Ctx) { +pub fn fd_filestat_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_filestat_set_size(ctx: &mut Ctx) { +pub fn fd_filestat_set_size(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_filestat_set_times(ctx: &mut Ctx) { +pub fn fd_filestat_set_times(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_pread(ctx: &mut Ctx) { +pub fn fd_pread(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_prestat_get(ctx: &mut Ctx) { +pub fn fd_prestat_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_prestat_dir_name(ctx: &mut Ctx) { +pub fn fd_prestat_dir_name(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_pwrite(ctx: &mut Ctx) { +pub fn fd_pwrite(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_read(ctx: &mut Ctx) { +pub fn fd_read(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_readdir(ctx: &mut Ctx) { +pub fn fd_readdir(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_renumber(ctx: &mut Ctx) { +pub fn fd_renumber(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_seek(ctx: &mut Ctx) { +pub fn fd_seek(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_sync(ctx: &mut Ctx) { +pub fn fd_sync(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_tell(ctx: &mut Ctx) { +pub fn fd_tell(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_fd_write(ctx: &mut Ctx) { +pub fn fd_write(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_create_directory(ctx: &mut Ctx) { +pub fn path_create_directory(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_filestat_get(ctx: &mut Ctx) { +pub fn path_filestat_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_filestat_set_times(ctx: &mut Ctx) { +pub fn path_filestat_set_times(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_link(ctx: &mut Ctx) { +pub fn path_link(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_open(ctx: &mut Ctx) { +pub fn path_open(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_readlink(ctx: &mut Ctx) { +pub fn path_readlink(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_remove_directory(ctx: &mut Ctx) { +pub fn path_remove_directory(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_rename(ctx: &mut Ctx) { +pub fn path_rename(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_symlink(ctx: &mut Ctx) { +pub fn path_symlink(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_path_unlink_file(ctx: &mut Ctx) { +pub fn path_unlink_file(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_poll_oneoff(ctx: &mut Ctx) { +pub fn poll_oneoff(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_proc_exit(ctx: &mut Ctx) { +pub fn proc_exit(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_proc_raise(ctx: &mut Ctx) { +pub fn proc_raise(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_random_get(ctx: &mut Ctx) { +pub fn random_get(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_sched_yield(ctx: &mut Ctx) { +pub fn sched_yield(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_sock_recv(ctx: &mut Ctx) { +pub fn sock_recv(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_sock_send(ctx: &mut Ctx) { +pub fn sock_send(ctx: &mut Ctx) { unimplemented!() } -pub fn __wasi_sock_shutdown(ctx: &mut Ctx) { +pub fn sock_shutdown(ctx: &mut Ctx) { unimplemented!() } From 46f90d3415bb95ccd98f92ad95ceffda17a314c2 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 15:42:34 -0700 Subject: [PATCH 17/73] fix conditional compliation --- src/bin/wasmer.rs | 70 +++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 29de018e232..9b918318921 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -203,39 +203,45 @@ fn execute_wasm(options: &Run) -> Result<(), String> { }; // TODO: refactor this - #[cfg(not(features = "wasi"))] - let (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) { - let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); - ( - InstanceABI::Emscripten, - wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals), - Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution - ) - } else { - ( - InstanceABI::None, - wasmer_runtime_core::import::ImportObject::new(), - None, - ) - }; - - #[cfg(features = "wasi")] - let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { - ( - InstanceABI::WASI, - wasmer_wasi::generate_import_object( - options.args.iter().map(|arg| arg.into_bytes()).collect(), - env::vars() - .iter() - .map(|(k, v)| format!("{}={}", k, v).into_bytes()) - .collect(), - ), - ) + let (_abi, import_object, _em_globals) = if cfg!(feature = "wasi") { + if wasmer_wasi::is_wasi_module(&module) { + ( + InstanceABI::WASI, + wasmer_wasi::generate_import_object( + options + .args + .iter() + .cloned() + .map(|arg| arg.into_bytes()) + .collect(), + env::vars() + .map(|(k, v)| format!("{}={}", k, v).into_bytes()) + .collect(), + ), + None, + ) + } else { + ( + InstanceABI::None, + wasmer_runtime_core::import::ImportObject::new(), + None, + ) + } } else { - ( - InstanceABI::None, - wasmer_runtime_core::import::ImportObject::new(), - ) + if wasmer_emscripten::is_emscripten_module(&module) { + let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); + ( + InstanceABI::Emscripten, + wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals), + Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution + ) + } else { + ( + InstanceABI::None, + wasmer_runtime_core::import::ImportObject::new(), + None, + ) + } }; let mut instance = module From 9478ba71af7d0df5d7c73c09120a1911bf39606a Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 15:47:00 -0700 Subject: [PATCH 18/73] actually fix it --- src/bin/wasmer.rs | 74 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 9b918318921..5f80c2640f0 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -203,45 +203,43 @@ fn execute_wasm(options: &Run) -> Result<(), String> { }; // TODO: refactor this - let (_abi, import_object, _em_globals) = if cfg!(feature = "wasi") { - if wasmer_wasi::is_wasi_module(&module) { - ( - InstanceABI::WASI, - wasmer_wasi::generate_import_object( - options - .args - .iter() - .cloned() - .map(|arg| arg.into_bytes()) - .collect(), - env::vars() - .map(|(k, v)| format!("{}={}", k, v).into_bytes()) - .collect(), - ), - None, - ) - } else { - ( - InstanceABI::None, - wasmer_runtime_core::import::ImportObject::new(), - None, - ) - } + #[cfg(not(feature = "wasi"))] + let (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) { + let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); + ( + InstanceABI::Emscripten, + wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals), + Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution + ) } else { - if wasmer_emscripten::is_emscripten_module(&module) { - let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); - ( - InstanceABI::Emscripten, - wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals), - Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution - ) - } else { - ( - InstanceABI::None, - wasmer_runtime_core::import::ImportObject::new(), - None, - ) - } + ( + InstanceABI::None, + wasmer_runtime_core::import::ImportObject::new(), + None, + ) + }; + + #[cfg(feature = "wasi")] + let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { + ( + InstanceABI::WASI, + wasmer_wasi::generate_import_object( + options + .args + .iter() + .cloned() + .map(|arg| arg.into_bytes()) + .collect(), + env::vars() + .map(|(k, v)| format!("{}={}", k, v).into_bytes()) + .collect(), + ), + ) + } else { + ( + InstanceABI::None, + wasmer_runtime_core::import::ImportObject::new(), + ) }; let mut instance = module From c45de2207ee85e729f0accb31713d9711c526ff1 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 17:00:10 -0700 Subject: [PATCH 19/73] Add helper types and half-ish of the wasi signatures --- lib/runtime-core/src/types.rs | 13 +++ lib/wasi/src/lib.rs | 1 + lib/wasi/src/ptr.rs | 89 ++++++++++++++++ lib/wasi/src/syscalls/mod.rs | 180 ++++++++++++++++++++++++--------- lib/wasi/src/syscalls/types.rs | 7 +- 5 files changed, 243 insertions(+), 47 deletions(-) create mode 100644 lib/wasi/src/ptr.rs diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 9ee5270dd73..d9e983f34dc 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -77,6 +77,19 @@ where { const TYPE: Type; } + +unsafe impl WasmExternType for i8 { + const TYPE: Type = Type::I32; +} +unsafe impl WasmExternType for u8 { + const TYPE: Type = Type::I32; +} +unsafe impl WasmExternType for i16 { + const TYPE: Type = Type::I32; +} +unsafe impl WasmExternType for u16 { + const TYPE: Type = Type::I32; +} unsafe impl WasmExternType for i32 { const TYPE: Type = Type::I32; } diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index b62f84dfb98..3dcb2f7cb7e 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,3 +1,4 @@ +mod ptr; mod state; mod syscalls; mod utils; diff --git a/lib/wasi/src/ptr.rs b/lib/wasi/src/ptr.rs new file mode 100644 index 00000000000..efc85185816 --- /dev/null +++ b/lib/wasi/src/ptr.rs @@ -0,0 +1,89 @@ +use std::{cell::Cell, fmt, marker::PhantomData, mem}; +use wasmer_runtime_core::{ + memory::Memory, + types::{Type, ValueType, WasmExternType}, +}; + +pub struct Array; +pub struct Item; + +#[repr(transparent)] +pub struct WasmPtr { + offset: u32, + _phantom: PhantomData<(T, Ty)>, +} + +impl WasmPtr { + pub fn new(offset: u32) -> Self { + Self { + offset, + _phantom: PhantomData, + } + } + + pub fn offset(self) -> u32 { + self.offset + } +} + +impl WasmPtr { + pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell> { + if (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 { + return None; + } + unsafe { + let cell_ptr = memory + .view::() + .get_unchecked((self.offset() as usize) / mem::size_of::()) + as *const _; + Some(&*cell_ptr) + } + } +} + +impl WasmPtr { + pub fn deref<'a>(self, memory: &'a Memory, length: u32) -> Option<&'a [Cell]> { + if (self.offset as usize) + (mem::size_of::() * (length as usize)) + >= memory.size().bytes().0 + { + return None; + } + + unsafe { + let cell_ptrs = memory.view::().get_unchecked( + ((self.offset() as usize) / mem::size_of::()) + ..((self.offset() as usize) / mem::size_of::()) + (length as usize), + ) as *const _; + Some(&*cell_ptrs) + } + } +} + +unsafe impl WasmExternType for WasmPtr { + const TYPE: Type = Type::I32; +} + +impl Clone for WasmPtr { + fn clone(&self) -> Self { + Self { + offset: self.offset, + _phantom: PhantomData, + } + } +} + +impl Copy for WasmPtr {} + +impl PartialEq for WasmPtr { + fn eq(&self, other: &Self) -> bool { + self.offset == other.offset + } +} + +impl Eq for WasmPtr {} + +impl fmt::Debug for WasmPtr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "WasmPtr({:#x})", self.offset) + } +} diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0c5f2f9b018..606c877a204 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,4 +1,12 @@ -use crate::state::WasiState; +#![allow(unused)] + +mod types; + +use self::types::*; +use crate::{ + ptr::{Array, WasmPtr}, + state::WasiState, +}; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; #[allow(clippy::mut_from_ref)] @@ -34,11 +42,13 @@ fn write_buffer_array( /// - `char *argv_buf` /// A pointer to a buffer to write the argument string data. /// -pub fn args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) { +pub fn args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) -> __wasi_errno_t { let state = get_wasi_state(ctx); let memory = ctx.memory(0); write_buffer_array(memory, &*state.args, ptr_buffer_offset, buffer_offset); + + __WASI_ESUCCESS } /// ### `args_sizes_get()` @@ -48,7 +58,7 @@ pub fn args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) { /// The number of arguments. /// - `size_t *argv_buf_size` /// The size of the argument string data. -pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { +pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) -> __wasi_errno_t { let state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -57,12 +67,23 @@ pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { memory.view::()[(argc_out / 4) as usize].set(arg_count as u32); memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); + + __WASI_ESUCCESS } -pub fn clock_res_get(ctx: &mut Ctx) { +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn clock_time_get(ctx: &mut Ctx) { +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { unimplemented!() } @@ -74,11 +95,13 @@ pub fn clock_time_get(ctx: &mut Ctx) { /// A pointer to a buffer to write the environment variable pointers. /// - `char *environ_buf` /// A pointer to a buffer to write the environment variable string data. -pub fn environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) { +pub fn environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) -> __wasi_errno_t { let state = get_wasi_state(ctx); let memory = ctx.memory(0); write_buffer_array(memory, &*state.args, environ, environ_buf); + + __WASI_ESUCCESS } /// ### `environ_sizes_get()` @@ -88,7 +111,11 @@ pub fn environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) { /// The number of environment variables. /// - `size_t *environ_buf_size` /// The size of the environment variable string data. -pub fn environ_sizes_get(ctx: &mut Ctx, environ_count_out: u32, environ_buf_size_out: u32) { +pub fn environ_sizes_get( + ctx: &mut Ctx, + environ_count_out: u32, + environ_buf_size_out: u32, +) -> __wasi_errno_t { let state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -97,122 +124,185 @@ pub fn environ_sizes_get(ctx: &mut Ctx, environ_count_out: u32, environ_buf_size memory.view::()[(environ_count_out / 4) as usize].set(env_count as u32); memory.view::()[(environ_buf_size_out / 4) as usize].set(total_env_size as u32); + + __WASI_ESUCCESS } -pub fn fd_advise(ctx: &mut Ctx) { +pub fn fd_advise( + ctx: &mut Ctx, + fd: __wasi_fd_t, + offset: __wasi_filesize_t, + len: __wasi_filesize_t, + advice: __wasi_advice_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_allocate(ctx: &mut Ctx) { +pub fn fd_allocate( + ctx: &mut Ctx, + fd: __wasi_fd_t, + offset: __wasi_filesize_t, + len: __wasi_filesize_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_close(ctx: &mut Ctx) { +pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } -pub fn fd_datasync(ctx: &mut Ctx) { +pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } -pub fn fd_fdstat_get(ctx: &mut Ctx) { +pub fn fd_fdstat_get( + ctx: &mut Ctx, + fd: __wasi_fd_t, + buf: WasmPtr<__wasi_fdstat_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_fdstat_set_flags(ctx: &mut Ctx) { +pub fn fd_fdstat_set_flags( + ctx: &mut Ctx, + fd: __wasi_fd_t, + flags: __wasi_fdflags_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_fdstat_set_rights(ctx: &mut Ctx) { +pub fn fd_fdstat_set_rights( + ctx: &mut Ctx, + fd: __wasi_fd_t, + fs_rights_base: __wasi_rights_t, + fs_rights_inheriting: __wasi_rights_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_filestat_get(ctx: &mut Ctx) { +pub fn fd_filestat_get( + ctx: &mut Ctx, + fd: __wasi_fd_t, + buf: WasmPtr<__wasi_filestat_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_filestat_set_size(ctx: &mut Ctx) { +pub fn fd_filestat_set_size( + ctx: &mut Ctx, + fd: __wasi_fd_t, + st_size: __wasi_filesize_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_filestat_set_times(ctx: &mut Ctx) { +pub fn fd_filestat_set_times( + ctx: &mut Ctx, + fd: __wasi_fd_t, + st_atim: __wasi_timestamp_t, + st_mtim: __wasi_timestamp_t, + fst_flags: __wasi_fstflags_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_pread(ctx: &mut Ctx) { +pub fn fd_pread( + ctx: &mut Ctx, + fd: __wasi_fd_t, + iovs: WasmPtr<__wasi_iovec_t, Array>, + iovs_len: u32, + offset: __wasi_filesize_t, + nread: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_prestat_get(ctx: &mut Ctx) { +pub fn fd_prestat_get( + ctx: &mut Ctx, + fd: __wasi_fd_t, + buf: WasmPtr<__wasi_fdstat_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_prestat_dir_name(ctx: &mut Ctx) { +pub fn fd_prestat_dir_name( + ctx: &mut Ctx, + fd: __wasi_fd_t, + path: WasmPtr, + path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_pwrite(ctx: &mut Ctx) { +pub fn fd_pwrite( + ctx: &mut Ctx, + fd: __wasi_fd_t, + iovs: WasmPtr<__wasi_ciovec_t, Array>, + iovs_len: u32, + offset: __wasi_filesize_t, + nwritten: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_read(ctx: &mut Ctx) { +pub fn fd_read(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn fd_readdir(ctx: &mut Ctx) { +pub fn fd_readdir(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn fd_renumber(ctx: &mut Ctx) { +pub fn fd_renumber(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn fd_seek(ctx: &mut Ctx) { +pub fn fd_seek(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn fd_sync(ctx: &mut Ctx) { +pub fn fd_sync(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn fd_tell(ctx: &mut Ctx) { +pub fn fd_tell(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn fd_write(ctx: &mut Ctx) { +pub fn fd_write(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_create_directory(ctx: &mut Ctx) { +pub fn path_create_directory(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_filestat_get(ctx: &mut Ctx) { +pub fn path_filestat_get(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_filestat_set_times(ctx: &mut Ctx) { +pub fn path_filestat_set_times(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_link(ctx: &mut Ctx) { +pub fn path_link(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_open(ctx: &mut Ctx) { +pub fn path_open(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_readlink(ctx: &mut Ctx) { +pub fn path_readlink(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_remove_directory(ctx: &mut Ctx) { +pub fn path_remove_directory(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_rename(ctx: &mut Ctx) { +pub fn path_rename(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_symlink(ctx: &mut Ctx) { +pub fn path_symlink(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn path_unlink_file(ctx: &mut Ctx) { +pub fn path_unlink_file(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn poll_oneoff(ctx: &mut Ctx) { +pub fn poll_oneoff(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } pub fn proc_exit(ctx: &mut Ctx) { unimplemented!() } -pub fn proc_raise(ctx: &mut Ctx) { +pub fn proc_raise(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn random_get(ctx: &mut Ctx) { +pub fn random_get(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn sched_yield(ctx: &mut Ctx) { +pub fn sched_yield(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn sock_recv(ctx: &mut Ctx) { +pub fn sock_recv(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn sock_send(ctx: &mut Ctx) { +pub fn sock_send(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn sock_shutdown(ctx: &mut Ctx) { +pub fn sock_shutdown(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 6a927a30119..bda4bd1b542 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -1,5 +1,8 @@ #![allow(non_camel_case_types)] +use crate::ptr::{Array, WasmPtr}; +use wasmer_runtime_core::types::{ValueError, ValueType}; + pub type __wasi_advice_t = u8; pub const __WASI_ADVICE_DONTNEED: u8 = 0; pub const __WASI_ADVICE_NOREUSE: u8 = 1; @@ -11,7 +14,7 @@ pub const __WASI_ADVICE_WILLNEED: u8 = 5; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct __wasi_ciovec_t { - pub buf: u32, + pub buf: WasmPtr, pub buf_len: u32, } @@ -205,7 +208,7 @@ pub type __wasi_inode_t = u64; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct __wasi_iovec_t { - pub buf: u32, + pub buf: WasmPtr, pub buf_len: u32, } From bd09343fcad694128b559da0ce4c6e383eb29d93 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 17:09:39 -0700 Subject: [PATCH 20/73] add structure for cross-platform wasi syscall implementations --- lib/wasi/src/syscalls/mod.rs | 20 +++++++++++++------- lib/wasi/src/syscalls/unix/linux.rs | 19 +++++++++++++++++++ lib/wasi/src/syscalls/unix/macos.rs | 19 +++++++++++++++++++ lib/wasi/src/syscalls/unix/mod.rs | 11 +++++++++++ lib/wasi/src/syscalls/windows.rs | 19 +++++++++++++++++++ 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 lib/wasi/src/syscalls/unix/linux.rs create mode 100644 lib/wasi/src/syscalls/unix/macos.rs create mode 100644 lib/wasi/src/syscalls/unix/mod.rs create mode 100644 lib/wasi/src/syscalls/windows.rs diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0c5f2f9b018..077a61155f6 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,6 +1,19 @@ +pub mod types; +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub mod unix; +#[cfg(any(target_os = "windows"))] +pub mod windows; + use crate::state::WasiState; +use types::*; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub use unix::*; + +#[cfg(any(target_os = "windows"))] +pub use windows::*; + #[allow(clippy::mut_from_ref)] fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } @@ -59,13 +72,6 @@ pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); } -pub fn clock_res_get(ctx: &mut Ctx) { - unimplemented!() -} -pub fn clock_time_get(ctx: &mut Ctx) { - unimplemented!() -} - /// ### `environ_get()` /// Read environment variable data. /// The sizes of the buffers should match that returned by [`environ_sizes_get()`](#environ_sizes_get). diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs new file mode 100644 index 00000000000..c3556faba0b --- /dev/null +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -0,0 +1,19 @@ +use crate::syscalls::types::*; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; + +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + __WASI_EINVAL +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + unimplemented!() +} diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs new file mode 100644 index 00000000000..c3556faba0b --- /dev/null +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -0,0 +1,19 @@ +use crate::syscalls::types::*; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; + +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + __WASI_EINVAL +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + unimplemented!() +} diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs new file mode 100644 index 00000000000..8fab04668ff --- /dev/null +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -0,0 +1,11 @@ +#[cfg(target_os = "linux")] +pub mod linux; + +#[cfg(target_os = "macos")] +pub mod macos; + +#[cfg(target_os = "linux")] +pub use linux::*; + +#[cfg(target_os = "macos")] +pub use macos::*; diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs new file mode 100644 index 00000000000..c3556faba0b --- /dev/null +++ b/lib/wasi/src/syscalls/windows.rs @@ -0,0 +1,19 @@ +use crate::syscalls::types::*; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; + +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + __WASI_EINVAL +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + unimplemented!() +} From 90db12e59a659636e6e7bc00cc89329341b19f41 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 22:10:11 -0700 Subject: [PATCH 21/73] Finish up signatures and converting function types --- lib/wasi/src/ptr.rs | 28 +++- lib/wasi/src/syscalls/mod.rs | 265 ++++++++++++++++++++++++++------- lib/wasi/src/syscalls/types.rs | 2 +- 3 files changed, 235 insertions(+), 60 deletions(-) diff --git a/lib/wasi/src/ptr.rs b/lib/wasi/src/ptr.rs index efc85185816..486ba808cc3 100644 --- a/lib/wasi/src/ptr.rs +++ b/lib/wasi/src/ptr.rs @@ -1,7 +1,7 @@ use std::{cell::Cell, fmt, marker::PhantomData, mem}; use wasmer_runtime_core::{ memory::Memory, - types::{Type, ValueType, WasmExternType}, + types::{Type, ValueError, ValueType, WasmExternType}, }; pub struct Array; @@ -14,6 +14,7 @@ pub struct WasmPtr { } impl WasmPtr { + #[inline] pub fn new(offset: u32) -> Self { Self { offset, @@ -21,12 +22,14 @@ impl WasmPtr { } } + #[inline] pub fn offset(self) -> u32 { self.offset } } impl WasmPtr { + #[inline] pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell> { if (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 { return None; @@ -42,8 +45,9 @@ impl WasmPtr { } impl WasmPtr { - pub fn deref<'a>(self, memory: &'a Memory, length: u32) -> Option<&'a [Cell]> { - if (self.offset as usize) + (mem::size_of::() * (length as usize)) + #[inline] + pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell]> { + if (self.offset as usize) + (mem::size_of::() * ((index + length) as usize)) >= memory.size().bytes().0 { return None; @@ -63,6 +67,24 @@ unsafe impl WasmExternType for WasmPtr { const TYPE: Type = Type::I32; } +impl ValueType for WasmPtr { + fn into_le(self, buffer: &mut [u8]) { + buffer[..mem::size_of::()].copy_from_slice(&self.offset.to_le_bytes()); + } + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::() { + let mut array = [0u8; mem::size_of::()]; + array.copy_from_slice(&buffer[..mem::size_of::()]); + Ok(Self { + offset: u32::from_le_bytes(array), + _phantom: PhantomData, + }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + impl Clone for WasmPtr { fn clone(&self) -> Self { Self { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 606c877a204..0c0298383e8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -14,23 +14,38 @@ fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } } +#[must_use] fn write_buffer_array( memory: &Memory, from: &[Vec], - ptr_buffer_offset: u32, - buffer_offset: u32, -) { - let mut current_buffer_offset = buffer_offset; - for (i, sub_buffer) in from.iter().enumerate() { - memory.view::()[(ptr_buffer_offset as usize)..][i].set(current_buffer_offset); - for (cell, &byte) in memory.view()[(current_buffer_offset as usize)..] - .iter() - .zip(sub_buffer.iter()) + ptr_buffer: WasmPtr, Array>, + buffer: WasmPtr, +) -> __wasi_errno_t { + let ptrs = if let Some(cells) = ptr_buffer.deref(memory, 0, from.len() as u32) { + cells + } else { + return __WASI_EOVERFLOW; + }; + + let mut current_buffer_offset = 0; + for ((i, sub_buffer), ptr) in from.iter().enumerate().zip(ptrs.iter()) { + ptr.set(WasmPtr::new(buffer.offset() + current_buffer_offset)); + + let cells = if let Some(cells) = + buffer.deref(memory, current_buffer_offset, sub_buffer.len() as u32) { + cells + } else { + return __WASI_EOVERFLOW; + }; + + for (cell, &byte) in cells.iter().zip(sub_buffer.iter()) { cell.set(byte); } current_buffer_offset += sub_buffer.len() as u32; } + + __WASI_ESUCCESS } /// ### `args_get()` @@ -42,13 +57,15 @@ fn write_buffer_array( /// - `char *argv_buf` /// A pointer to a buffer to write the argument string data. /// -pub fn args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) -> __wasi_errno_t { +pub fn args_get( + ctx: &mut Ctx, + argv: WasmPtr, Array>, + argv_buf: WasmPtr, +) -> __wasi_errno_t { let state = get_wasi_state(ctx); let memory = ctx.memory(0); - write_buffer_array(memory, &*state.args, ptr_buffer_offset, buffer_offset); - - __WASI_ESUCCESS + write_buffer_array(memory, &*state.args, argv, argv_buf) } /// ### `args_sizes_get()` @@ -58,17 +75,23 @@ pub fn args_get(ctx: &mut Ctx, ptr_buffer_offset: u32, buffer_offset: u32) -> __ /// The number of arguments. /// - `size_t *argv_buf_size` /// The size of the argument string data. -pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) -> __wasi_errno_t { - let state = get_wasi_state(ctx); +pub fn args_sizes_get( + ctx: &mut Ctx, + argc: WasmPtr, + argv_buf_size: WasmPtr, +) -> __wasi_errno_t { let memory = ctx.memory(0); - let arg_count = state.args.len(); - let total_arg_size: usize = state.args.iter().map(|v| v.len()).sum(); + if let (Some(argc), Some(argv_buf_size)) = (argc.deref(memory), argv_buf_size.deref(memory)) { + let state = get_wasi_state(ctx); - memory.view::()[(argc_out / 4) as usize].set(arg_count as u32); - memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); + argc.set(state.args.len() as u32); + argv_buf_size.set(state.args.iter().map(|v| v.len() as u32).sum()); - __WASI_ESUCCESS + __WASI_ESUCCESS + } else { + __WASI_EOVERFLOW + } } pub fn clock_res_get( @@ -95,13 +118,15 @@ pub fn clock_time_get( /// A pointer to a buffer to write the environment variable pointers. /// - `char *environ_buf` /// A pointer to a buffer to write the environment variable string data. -pub fn environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) -> __wasi_errno_t { +pub fn environ_get( + ctx: &mut Ctx, + environ: WasmPtr, Array>, + environ_buf: WasmPtr, +) -> __wasi_errno_t { let state = get_wasi_state(ctx); let memory = ctx.memory(0); - write_buffer_array(memory, &*state.args, environ, environ_buf); - - __WASI_ESUCCESS + write_buffer_array(memory, &*state.args, environ, environ_buf) } /// ### `environ_sizes_get()` @@ -113,19 +138,23 @@ pub fn environ_get(ctx: &mut Ctx, environ: u32, environ_buf: u32) -> __wasi_errn /// The size of the environment variable string data. pub fn environ_sizes_get( ctx: &mut Ctx, - environ_count_out: u32, - environ_buf_size_out: u32, + environ_count: WasmPtr, + environ_buf_size: WasmPtr, ) -> __wasi_errno_t { - let state = get_wasi_state(ctx); let memory = ctx.memory(0); - let env_count = state.envs.len(); - let total_env_size: usize = state.envs.iter().map(|v| v.len()).sum(); + if let (Some(environ_count), Some(environ_buf_size)) = + (environ_count.deref(memory), environ_buf_size.deref(memory)) + { + let state = get_wasi_state(ctx); - memory.view::()[(environ_count_out / 4) as usize].set(env_count as u32); - memory.view::()[(environ_buf_size_out / 4) as usize].set(total_env_size as u32); + environ_count.set(state.envs.len() as u32); + environ_buf_size.set(state.envs.iter().map(|v| v.len() as u32).sum()); - __WASI_ESUCCESS + __WASI_ESUCCESS + } else { + __WASI_EOVERFLOW + } } pub fn fd_advise( @@ -231,78 +260,202 @@ pub fn fd_pwrite( ) -> __wasi_errno_t { unimplemented!() } -pub fn fd_read(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_read( + ctx: &mut Ctx, + fd: __wasi_fd_t, + iovs: WasmPtr<__wasi_iovec_t, Array>, + iovs_len: u32, + nread: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_readdir(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_readdir( + ctx: &mut Ctx, + fd: __wasi_fd_t, + buf: WasmPtr, + buf_len: u32, + cookie: __wasi_dircookie_t, + bufused: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_renumber(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_renumber(ctx: &mut Ctx, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } -pub fn fd_seek(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_seek( + ctx: &mut Ctx, + fd: __wasi_fd_t, + offset: __wasi_filedelta_t, + whence: __wasi_whence_t, + newoffset: WasmPtr<__wasi_filesize_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_sync(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_sync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } -pub fn fd_tell(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_tell( + ctx: &mut Ctx, + fd: __wasi_fd_t, + offset: WasmPtr<__wasi_filesize_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn fd_write(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn fd_write( + ctx: &mut Ctx, + fd: __wasi_fd_t, + iovs: WasmPtr<__wasi_ciovec_t, Array>, + iovs_len: u32, + nwritten: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_create_directory(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_create_directory( + ctx: &mut Ctx, + fd: __wasi_fd_t, + path: WasmPtr, + path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_filestat_get(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_filestat_get( + ctx: &mut Ctx, + fd: __wasi_fd_t, + flags: __wasi_lookupflags_t, + path: WasmPtr, + path_len: u32, + buf: WasmPtr<__wasi_filestat_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_filestat_set_times(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_filestat_set_times( + ctx: &mut Ctx, + fd: __wasi_fd_t, + flags: __wasi_lookupflags_t, + path: WasmPtr, + path_len: u32, + st_atim: __wasi_timestamp_t, + st_mtim: __wasi_timestamp_t, + fst_flags: __wasi_fstflags_t, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_link(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_link( + ctx: &mut Ctx, + old_fd: __wasi_fd_t, + old_flags: __wasi_lookupflags_t, + old_path: WasmPtr, + old_path_len: u32, + new_fd: __wasi_fd_t, + new_path: WasmPtr, + new_path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_open(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_open( + ctx: &mut Ctx, + dirfd: __wasi_fd_t, + dirflags: __wasi_lookupflags_t, + path: WasmPtr, + path_len: u32, + o_flags: __wasi_oflags_t, + fs_rights_base: __wasi_rights_t, + fs_rights_inheriting: __wasi_rights_t, + fs_flags: __wasi_fdflags_t, + fd: WasmPtr<__wasi_fd_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_readlink(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_readlink( + ctx: &mut Ctx, + fd: __wasi_fd_t, + path: WasmPtr, + path_len: u32, + buf: WasmPtr, + buf_len: u32, + bufused: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_remove_directory(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_remove_directory( + ctx: &mut Ctx, + fd: __wasi_fd_t, + path: WasmPtr, + path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_rename(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_rename( + ctx: &mut Ctx, + old_fd: __wasi_fd_t, + old_path: WasmPtr, + old_path_len: u32, + new_fd: __wasi_fd_t, + new_path: WasmPtr, + new_path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_symlink(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_symlink( + ctx: &mut Ctx, + old_path: WasmPtr, + old_path_len: u32, + fd: __wasi_fd_t, + new_path: WasmPtr, + new_path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn path_unlink_file(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn path_unlink_file( + ctx: &mut Ctx, + fd: __wasi_fd_t, + path: WasmPtr, + path_len: u32, +) -> __wasi_errno_t { unimplemented!() } -pub fn poll_oneoff(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn poll_oneoff( + ctx: &mut Ctx, + in_: WasmPtr<__wasi_subscription_t, Array>, + out_: WasmPtr<__wasi_event_t, Array>, + nsubscriptions: u32, + nevents: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn proc_exit(ctx: &mut Ctx) { +pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) { unimplemented!() } -pub fn proc_raise(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t { unimplemented!() } -pub fn random_get(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __wasi_errno_t { unimplemented!() } pub fn sched_yield(ctx: &mut Ctx) -> __wasi_errno_t { unimplemented!() } -pub fn sock_recv(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn sock_recv( + ctx: &mut Ctx, + sock: __wasi_fd_t, + ri_data: WasmPtr<__wasi_iovec_t, Array>, + ri_data_len: u32, + ri_flags: __wasi_riflags_t, + ro_datalen: WasmPtr, + ro_flags: WasmPtr<__wasi_roflags_t>, +) -> __wasi_errno_t { unimplemented!() } -pub fn sock_send(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn sock_send( + ctx: &mut Ctx, + sock: __wasi_fd_t, + si_data: WasmPtr<__wasi_ciovec_t, Array>, + si_data_len: u32, + si_flags: __wasi_siflags_t, + so_datalen: WasmPtr, +) -> __wasi_errno_t { unimplemented!() } -pub fn sock_shutdown(ctx: &mut Ctx) -> __wasi_errno_t { +pub fn sock_shutdown(ctx: &mut Ctx, sock: __wasi_fd_t, how: __wasi_sdflags_t) -> __wasi_errno_t { unimplemented!() } diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index bda4bd1b542..7995e86bec8 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -223,7 +223,7 @@ pub const __WASI_O_DIRECTORY: u16 = 1 << 1; pub const __WASI_O_EXCL: u16 = 1 << 2; pub const __WASI_O_TRUNC: u16 = 1 << 3; -pub type __wasi_riflags = u16; +pub type __wasi_riflags_t = u16; pub const __WASI_SOCK_RECV_PEEK: u16 = 1 << 0; pub const __WASI_SOCK_RECV_WAITALL: u16 = 1 << 1; From d9b89b46ee982e5d9c9b802a6baf291e852fff21 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Thu, 28 Mar 2019 22:22:46 -0700 Subject: [PATCH 22/73] Fix bug in deref of WasmPtr --- lib/wasi/src/ptr.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/ptr.rs b/lib/wasi/src/ptr.rs index 486ba808cc3..f6d1c4ce4f8 100644 --- a/lib/wasi/src/ptr.rs +++ b/lib/wasi/src/ptr.rs @@ -55,8 +55,9 @@ impl WasmPtr { unsafe { let cell_ptrs = memory.view::().get_unchecked( - ((self.offset() as usize) / mem::size_of::()) - ..((self.offset() as usize) / mem::size_of::()) + (length as usize), + ((self.offset as usize) / mem::size_of::()) + (index as usize) + ..((self.offset() as usize) / mem::size_of::()) + + ((index + length) as usize), ) as *const _; Some(&*cell_ptrs) } From ea27effdb3d95907c3d8d34e4442b9cdf2ced20c Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 10:20:08 -0700 Subject: [PATCH 23/73] keeep top level wasi calls that call out to platform-specific impls --- lib/wasi/src/syscalls/mod.rs | 17 +++++++++++++++++ lib/wasi/src/syscalls/unix/linux.rs | 4 ++-- lib/wasi/src/syscalls/unix/macos.rs | 4 ++-- lib/wasi/src/syscalls/windows.rs | 4 ++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 077a61155f6..380adc68bdb 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -72,6 +72,23 @@ pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); } +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + platform_clock_res_get(ctx, clock_id, resolution) +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + platform_clock_time_get(ctx, clock_id, precision, time) +} + /// ### `environ_get()` /// Read environment variable data. /// The sizes of the buffers should match that returned by [`environ_sizes_get()`](#environ_sizes_get). diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index c3556faba0b..43ca2cb6dab 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -1,7 +1,7 @@ use crate::syscalls::types::*; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; -pub fn clock_res_get( +pub fn platform_clock_res_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t>, @@ -9,7 +9,7 @@ pub fn clock_res_get( __WASI_EINVAL } -pub fn clock_time_get( +pub fn platform_clock_time_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs index c3556faba0b..43ca2cb6dab 100644 --- a/lib/wasi/src/syscalls/unix/macos.rs +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -1,7 +1,7 @@ use crate::syscalls::types::*; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; -pub fn clock_res_get( +pub fn platform_clock_res_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t>, @@ -9,7 +9,7 @@ pub fn clock_res_get( __WASI_EINVAL } -pub fn clock_time_get( +pub fn platform_clock_time_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index c3556faba0b..43ca2cb6dab 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -1,7 +1,7 @@ use crate::syscalls::types::*; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; -pub fn clock_res_get( +pub fn platform_clock_res_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t>, @@ -9,7 +9,7 @@ pub fn clock_res_get( __WASI_EINVAL } -pub fn clock_time_get( +pub fn platform_clock_time_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, From 514432c05aa0ec567aada36d8edaacbe0f5b8c74 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 10:58:56 -0700 Subject: [PATCH 24/73] call wasi files correctly --- src/bin/wasmer.rs | 5 +++-- src/webassembly.rs | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 5f80c2640f0..ceb6604d634 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -204,7 +204,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { // TODO: refactor this #[cfg(not(feature = "wasi"))] - let (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) { + let (abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) { let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); ( InstanceABI::Emscripten, @@ -220,7 +220,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { }; #[cfg(feature = "wasi")] - let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { + let (abi, import_object) = if wasmer_wasi::is_wasi_module(&module) { ( InstanceABI::WASI, wasmer_wasi::generate_import_object( @@ -249,6 +249,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { webassembly::run_instance( &module, &mut instance, + abi, options.path.to_str().unwrap(), options.args.iter().map(|arg| arg.as_str()).collect(), ) diff --git a/src/webassembly.rs b/src/webassembly.rs index 51f1e7a927d..01367795aed 100644 --- a/src/webassembly.rs +++ b/src/webassembly.rs @@ -7,7 +7,7 @@ use wasmer_runtime::{ use wasmer_runtime_core::backend::CompilerConfig; use wasmer_runtime_core::types::Value; -use wasmer_emscripten::{is_emscripten_module, run_emscripten_instance}; +use wasmer_emscripten::run_emscripten_instance; pub struct ResultObject { /// A webassembly::Module object representing the compiled WebAssembly module. @@ -93,18 +93,24 @@ pub fn compile_with_config( pub fn run_instance( module: &Module, instance: &mut Instance, + abi: InstanceABI, path: &str, args: Vec<&str>, ) -> CallResult<()> { - if is_emscripten_module(module) { - run_emscripten_instance(module, instance, path, args)?; - } else { - let args: Vec = args - .into_iter() - .map(|x| Value::I32(x.parse().unwrap())) - .collect(); - instance.call("main", &args)?; - }; - + match abi { + InstanceABI::Emscripten => { + run_emscripten_instance(module, instance, path, args)?; + } + InstanceABI::WASI => { + instance.call("_start", &[])?; + } + InstanceABI::None => { + let args: Vec = args + .into_iter() + .map(|x| Value::I32(x.parse().unwrap())) + .collect(); + instance.call("main", &args)?; + } + } Ok(()) } From b1030d31814f85e8c6619ce1e0246ee214905446 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Fri, 29 Mar 2019 11:03:21 -0700 Subject: [PATCH 25/73] Add prestat_t --- lib/wasi/src/syscalls/mod.rs | 2 +- lib/wasi/src/syscalls/types.rs | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0c0298383e8..d72cbf46610 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -238,7 +238,7 @@ pub fn fd_pread( pub fn fd_prestat_get( ctx: &mut Ctx, fd: __wasi_fd_t, - buf: WasmPtr<__wasi_fdstat_t>, + buf: WasmPtr<__wasi_prestat_t>, ) -> __wasi_errno_t { unimplemented!() } diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 7995e86bec8..0221b1690df 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -34,7 +34,7 @@ pub const __WASI_DIRCOOKIE_START: u64 = 0; pub struct __wasi_dirent_t { pub d_next: __wasi_dircookie_t, pub d_ino: __wasi_inode_t, - pub _namlen: u32, + pub d_namlen: u32, pub d_type: __wasi_filetype_t, } @@ -161,6 +161,28 @@ pub const __WASI_FDFLAG_NONBLOCK: u16 = 1 << 2; pub const __WASI_FDFLAG_RSYNC: u16 = 1 << 3; pub const __WASI_FDFLAG_SYNC: u16 = 1 << 4; +pub type __wasi_preopentype_t = u8; +pub const __WASI_PREOPENTYPE_DIR: u8 = 0; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[repr(C)] +pub struct __wasi_prestat_u_dir_t { + pr_name_len: u32, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub union __wasi_prestat_u { + dir: __wasi_prestat_u_dir_t, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct __wasi_prestat_t { + pr_type: __wasi_preopentype_t, + u: __wasi_prestat_u, +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct __wasi_fdstat_t { From 23c09ac0429f78fdf4e82c255b85beda541241ed Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 11:04:38 -0700 Subject: [PATCH 26/73] add imports --- lib/wasi/src/syscalls/unix/linux.rs | 1 + lib/wasi/src/syscalls/unix/macos.rs | 1 + lib/wasi/src/syscalls/windows.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 43ca2cb6dab..78ee51c9a0b 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -1,4 +1,5 @@ use crate::syscalls::types::*; +use crate::ptr::{Array, WasmPtr}, use wasmer_runtime_core::{memory::Memory, vm::Ctx}; pub fn platform_clock_res_get( diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs index 43ca2cb6dab..78ee51c9a0b 100644 --- a/lib/wasi/src/syscalls/unix/macos.rs +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -1,4 +1,5 @@ use crate::syscalls::types::*; +use crate::ptr::{Array, WasmPtr}, use wasmer_runtime_core::{memory::Memory, vm::Ctx}; pub fn platform_clock_res_get( diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index 43ca2cb6dab..78ee51c9a0b 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -1,4 +1,5 @@ use crate::syscalls::types::*; +use crate::ptr::{Array, WasmPtr}, use wasmer_runtime_core::{memory::Memory, vm::Ctx}; pub fn platform_clock_res_get( From 48d34d9522e0fbeba3b2001dec649117c00675c6 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 11:38:48 -0700 Subject: [PATCH 27/73] improve calling of platform-specific code and impl linux clock calls --- Cargo.lock | 1 + lib/wasi/Cargo.toml | 3 +- lib/wasi/src/syscalls/mod.rs | 16 +++++++-- lib/wasi/src/syscalls/unix/linux.rs | 50 ++++++++++++++++++++++++----- lib/wasi/src/syscalls/unix/macos.rs | 9 ++---- lib/wasi/src/syscalls/windows.rs | 9 ++---- 6 files changed, 65 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18ac80db931..53f1b1d5f4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1482,6 +1482,7 @@ dependencies = [ name = "wasmer-wasi" version = "0.1.0" dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", ] diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 17a2f14f429..3d2151d3e13 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -5,4 +5,5 @@ authors = ["The Wasmer Engineering Team "] edition = "2018" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } \ No newline at end of file +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } +libc = "0.2.50" \ No newline at end of file diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0ccc7bd649a..95d5f5240fe 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -108,7 +108,13 @@ pub fn clock_res_get( clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t>, ) -> __wasi_errno_t { - platform_clock_res_get(ctx, clock_id, resolution) + let memory = ctx.memory(0); + + if let Some(out_addr) = resolution.deref(memory) { + platform_clock_res_get(clock_id, out_addr) + } else { + __WASI_EFAULT + } } pub fn clock_time_get( @@ -117,7 +123,13 @@ pub fn clock_time_get( precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t>, ) -> __wasi_errno_t { - platform_clock_time_get(ctx, clock_id, precision, time) + let memory = ctx.memory(0); + + if let Some(out_addr) = time.deref(memory) { + platform_clock_time_get(clock_id, precision, out_addr) + } else { + __WASI_EFAULT + } } /// ### `environ_get()` diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 78ee51c9a0b..e68d470fad6 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -1,20 +1,54 @@ use crate::syscalls::types::*; -use crate::ptr::{Array, WasmPtr}, -use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +use libc::{ + clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, + CLOCK_REALTIME, CLOCK_THREAD_CPUTIME_ID, +}; +use std::cell::Cell; +use std::mem; pub fn platform_clock_res_get( - ctx: &mut Ctx, clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t>, + resolution: &Cell<__wasi_timestamp_t>, ) -> __wasi_errno_t { - __WASI_EINVAL + let linux_clock_id = match clock_id { + __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, + __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, + __WASI_CLOCK_REALTIME => CLOCK_REALTIME, + __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, + _ => return __WASI_EINVAL, + }; + + let output = unsafe { + let mut timespec_out: timespec = mem::uninitialized(); + clock_getres(linux_clock_id, &mut timespec_out); + }; + + resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); + + // TODO: map output of clock_getres to __wasi_errno_t + __WASI_ESUCCESS } pub fn platform_clock_time_get( - ctx: &mut Ctx, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t>, + time: &Cell<__wasi_timestamp_t>, ) -> __wasi_errno_t { - unimplemented!() + let linux_clock_id = match clock_id { + __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, + __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, + __WASI_CLOCK_REALTIME => CLOCK_REALTIME, + __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, + _ => return __WASI_EINVAL, + }; + + let output = unsafe { + let mut timespec_out: timespec = mem::uninitialized(); + clock_gettime(linux_clock_id, precision, &mut timespec_out); + }; + + resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); + + // TODO: map output of clock_gettime to __wasi_errno_t + __WASI_ESUCCESS } diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs index 78ee51c9a0b..6273695d322 100644 --- a/lib/wasi/src/syscalls/unix/macos.rs +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -1,20 +1,17 @@ use crate::syscalls::types::*; -use crate::ptr::{Array, WasmPtr}, -use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +use std::cell::Cell; pub fn platform_clock_res_get( - ctx: &mut Ctx, clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t>, + resolution: &Cell<__wasi_timestamp_t>, ) -> __wasi_errno_t { __WASI_EINVAL } pub fn platform_clock_time_get( - ctx: &mut Ctx, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t>, + time: &Cell<__wasi_timestamp_t>, ) -> __wasi_errno_t { unimplemented!() } diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index 78ee51c9a0b..6273695d322 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -1,20 +1,17 @@ use crate::syscalls::types::*; -use crate::ptr::{Array, WasmPtr}, -use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +use std::cell::Cell; pub fn platform_clock_res_get( - ctx: &mut Ctx, clock_id: __wasi_clockid_t, - resolution: WasmPtr<__wasi_timestamp_t>, + resolution: &Cell<__wasi_timestamp_t>, ) -> __wasi_errno_t { __WASI_EINVAL } pub fn platform_clock_time_get( - ctx: &mut Ctx, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, - time: WasmPtr<__wasi_timestamp_t>, + time: &Cell<__wasi_timestamp_t>, ) -> __wasi_errno_t { unimplemented!() } From de241a03f9bed9cef6b197f92e47b64a435a3871 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 11:43:32 -0700 Subject: [PATCH 28/73] fix linux impl bugs --- lib/wasi/src/syscalls/unix/linux.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index e68d470fad6..80a079b9be7 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -42,12 +42,17 @@ pub fn platform_clock_time_get( _ => return __WASI_EINVAL, }; - let output = unsafe { + let (output, timespec_out) = unsafe { let mut timespec_out: timespec = mem::uninitialized(); - clock_gettime(linux_clock_id, precision, &mut timespec_out); + ( + clock_gettime(linux_clock_id, &mut timespec_out), + timespec_out, + ) }; - resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); + // TODO: adjust output by precision... + + time.set(timespec_out.tv_nsec as __wasi_timestamp_t); // TODO: map output of clock_gettime to __wasi_errno_t __WASI_ESUCCESS From 1f8b90b57eb802b792e6b1042373d1e73454e21c Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 12:33:32 -0700 Subject: [PATCH 29/73] probably actually fix linux for real though --- lib/wasi/src/syscalls/unix/linux.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 80a079b9be7..8cc6320c6fd 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -18,9 +18,12 @@ pub fn platform_clock_res_get( _ => return __WASI_EINVAL, }; - let output = unsafe { + let (output, timespec_out) = unsafe { let mut timespec_out: timespec = mem::uninitialized(); - clock_getres(linux_clock_id, &mut timespec_out); + ( + clock_getres(linux_clock_id, &mut timespec_out), + timespec_out, + ) }; resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); From 28d9d1fe8784b23dae13b6104721a35abe126f49 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 12:39:48 -0700 Subject: [PATCH 30/73] move linux impl to unix (it works on osx too!) --- lib/wasi/src/syscalls/unix/linux.rs | 61 ----------------------------- lib/wasi/src/syscalls/unix/macos.rs | 16 -------- lib/wasi/src/syscalls/unix/mod.rs | 60 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 77 deletions(-) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 8cc6320c6fd..8b137891791 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -1,62 +1 @@ -use crate::syscalls::types::*; -use libc::{ - clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, - CLOCK_REALTIME, CLOCK_THREAD_CPUTIME_ID, -}; -use std::cell::Cell; -use std::mem; -pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, - resolution: &Cell<__wasi_timestamp_t>, -) -> __wasi_errno_t { - let linux_clock_id = match clock_id { - __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, - __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, - __WASI_CLOCK_REALTIME => CLOCK_REALTIME, - __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, - _ => return __WASI_EINVAL, - }; - - let (output, timespec_out) = unsafe { - let mut timespec_out: timespec = mem::uninitialized(); - ( - clock_getres(linux_clock_id, &mut timespec_out), - timespec_out, - ) - }; - - resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); - - // TODO: map output of clock_getres to __wasi_errno_t - __WASI_ESUCCESS -} - -pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, - time: &Cell<__wasi_timestamp_t>, -) -> __wasi_errno_t { - let linux_clock_id = match clock_id { - __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, - __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, - __WASI_CLOCK_REALTIME => CLOCK_REALTIME, - __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, - _ => return __WASI_EINVAL, - }; - - let (output, timespec_out) = unsafe { - let mut timespec_out: timespec = mem::uninitialized(); - ( - clock_gettime(linux_clock_id, &mut timespec_out), - timespec_out, - ) - }; - - // TODO: adjust output by precision... - - time.set(timespec_out.tv_nsec as __wasi_timestamp_t); - - // TODO: map output of clock_gettime to __wasi_errno_t - __WASI_ESUCCESS -} diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs index 6273695d322..8b137891791 100644 --- a/lib/wasi/src/syscalls/unix/macos.rs +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -1,17 +1 @@ -use crate::syscalls::types::*; -use std::cell::Cell; -pub fn platform_clock_res_get( - clock_id: __wasi_clockid_t, - resolution: &Cell<__wasi_timestamp_t>, -) -> __wasi_errno_t { - __WASI_EINVAL -} - -pub fn platform_clock_time_get( - clock_id: __wasi_clockid_t, - precision: __wasi_timestamp_t, - time: &Cell<__wasi_timestamp_t>, -) -> __wasi_errno_t { - unimplemented!() -} diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index 8fab04668ff..915699c24ec 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -9,3 +9,63 @@ pub use linux::*; #[cfg(target_os = "macos")] pub use macos::*; + +use crate::syscalls::types::*; +use libc::{ + clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, + CLOCK_REALTIME, CLOCK_THREAD_CPUTIME_ID, +}; +use std::cell::Cell; +use std::mem; + +pub fn platform_clock_res_get( + clock_id: __wasi_clockid_t, + resolution: &Cell<__wasi_timestamp_t>, +) -> __wasi_errno_t { + let unix_clock_id = match clock_id { + __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, + __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, + __WASI_CLOCK_REALTIME => CLOCK_REALTIME, + __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, + _ => return __WASI_EINVAL, + }; + + let (output, timespec_out) = unsafe { + let mut timespec_out: timespec = mem::uninitialized(); + (clock_getres(unix_clock_id, &mut timespec_out), timespec_out) + }; + + resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); + + // TODO: map output of clock_getres to __wasi_errno_t + __WASI_ESUCCESS +} + +pub fn platform_clock_time_get( + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: &Cell<__wasi_timestamp_t>, +) -> __wasi_errno_t { + let unix_clock_id = match clock_id { + __WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, + __WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, + __WASI_CLOCK_REALTIME => CLOCK_REALTIME, + __WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, + _ => return __WASI_EINVAL, + }; + + let (output, timespec_out) = unsafe { + let mut timespec_out: timespec = mem::uninitialized(); + ( + clock_gettime(unix_clock_id, &mut timespec_out), + timespec_out, + ) + }; + + // TODO: adjust output by precision... + + time.set(timespec_out.tv_nsec as __wasi_timestamp_t); + + // TODO: map output of clock_gettime to __wasi_errno_t + __WASI_ESUCCESS +} From 88212d356fe07b8e69c53db5a41bf7e6f15902fa Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 13:06:06 -0700 Subject: [PATCH 31/73] implement random_get() --- Cargo.lock | 1 + lib/wasi/Cargo.toml | 3 ++- lib/wasi/src/syscalls/mod.rs | 29 +++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53f1b1d5f4b..f15fd52757c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1483,6 +1483,7 @@ name = "wasmer-wasi" version = "0.1.0" dependencies = [ "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", ] diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 3d2151d3e13..2b3efd25bf0 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } -libc = "0.2.50" \ No newline at end of file +libc = "0.2.50" +rand = "0.6.5" \ No newline at end of file diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 95d5f5240fe..48a8c30677d 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -10,6 +10,7 @@ use crate::{ ptr::{Array, WasmPtr}, state::WasiState, }; +use rand::{thread_rng, Rng}; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -451,12 +452,36 @@ pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) { pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t { unimplemented!() } + +/// ### `random_get()` +/// Fill buffer with high-quality random data. This function may be slow and block +/// Inputs: +/// - `void *buf` +/// A pointer to a buffer where the random bytes will be written +/// - `size_t buf_len` +/// The number of bytes that will be written pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __wasi_errno_t { - unimplemented!() + let mut rng = thread_rng(); + let memory = ctx.memory(0); + + if let Some(buf) = buf.deref(memory, 0, buf_len) { + for i in 0..(buf_len as usize) { + let random_byte = rng.gen::(); + buf[i].set(random_byte); + } + } else { + return __WASI_EFAULT; + } + + __WASI_ESUCCESS } + +/// ### `sched_yield()` +/// Yields execution of the thread pub fn sched_yield(ctx: &mut Ctx) -> __wasi_errno_t { - unimplemented!() + __WASI_ESUCCESS } + pub fn sock_recv( ctx: &mut Ctx, sock: __wasi_fd_t, From 35fbf573c92098ab4cc95880ac78ff94bd6d56c8 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 15:10:46 -0700 Subject: [PATCH 32/73] add pread on linux --- lib/wasi/src/syscalls/mod.rs | 12 +++++++++++- lib/wasi/src/syscalls/types.rs | 20 ++++++++++++++++++++ lib/wasi/src/syscalls/unix/linux.rs | 26 ++++++++++++++++++++++++++ lib/wasi/src/syscalls/unix/macos.rs | 11 +++++++++++ lib/wasi/src/syscalls/windows.rs | 10 ++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 48a8c30677d..a7bbecb4ede 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -248,6 +248,7 @@ pub fn fd_filestat_set_times( ) -> __wasi_errno_t { unimplemented!() } + pub fn fd_pread( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -256,8 +257,17 @@ pub fn fd_pread( offset: __wasi_filesize_t, nread: WasmPtr, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + + if let ((Some(iov_cells), Some(nread_cell))) = + (iovs.deref(memory, 0, iovs_len), nread.deref(memory)) + { + platform_fd_pread(fd, iov_cells, iovs_len, offset, nread_cell) + } else { + __WASI_EFAULT + } } + pub fn fd_prestat_get( ctx: &mut Ctx, fd: __wasi_fd_t, diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 7995e86bec8..7f4cba575b8 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -1,6 +1,7 @@ #![allow(non_camel_case_types)] use crate::ptr::{Array, WasmPtr}; +use std::mem; use wasmer_runtime_core::types::{ValueError, ValueType}; pub type __wasi_advice_t = u8; @@ -212,6 +213,25 @@ pub struct __wasi_iovec_t { pub buf_len: u32, } +impl ValueType for __wasi_iovec_t { + fn into_le(self, buffer: &mut [u8]) { + self.buf + .into_le(&mut buffer[..mem::size_of::>()]); + self.buf_len + .into_le(&mut buffer[mem::size_of::>()..]); + } + + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + let buf = ValueType::from_le(&buffer[..mem::size_of::>()])?; + let buf_len = ValueType::from_le(&buffer[mem::size_of::>()..])?; + Ok(Self { buf, buf_len }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + pub type __wasi_linkcount_t = u32; pub type __wasi_lookupflags_t = u32; diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 8b137891791..cf62cc3800a 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -1 +1,27 @@ +use crate::syscalls::types::*; +use std::cell::Cell; +use libc::preadv; + +pub fn platform_fd_pread( + fd: __wasi_fd_t, + iovs: &[Cell<__wasi_iovec_t>], + iovs_len: u32, + offset: __wasi_filesize_t, + nread: &Cell, +) -> __wasi_errno_t { + let (result, iovec) = unsafe { + let mut iovec = vec![mem::uninitialized(); iovs_len as usize]; + (preadv(fd, &mut iovec, iovs_len, offset), iovec) + }; + nread.set(result); + for (arr_cell, i) in iov_arr.iter().enumerate() { + let wasi_iovec = __wasi_iovec_t { + buf: iovec[i] as _, + buf_len: iovec[i].iov_len as u32, + }; + arr_cell.set(wasi_iovec); + } + + __WASI_ESUCCESS +} diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs index 8b137891791..748a58fb388 100644 --- a/lib/wasi/src/syscalls/unix/macos.rs +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -1 +1,12 @@ +use crate::syscalls::types::*; +use std::cell::Cell; +pub fn platform_fd_pread( + fd: __wasi_fd_t, + iovs: &[Cell<__wasi_iovec_t>], + iovs_len: u32, + offset: __wasi_filesize_t, + nread: &Cell, +) -> __wasi_errno_t { + unimplemented!() +} diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index 6273695d322..5ea255f0a06 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -15,3 +15,13 @@ pub fn platform_clock_time_get( ) -> __wasi_errno_t { unimplemented!() } + +pub fn platform_fd_pread( + fd: __wasi_fd_t, + iovs: &[Cell<__wasi_iovec_t>], + iovs_len: u32, + offset: __wasi_filesize_t, + nread: &Cell, +) -> __wasi_errno_t { + unimplemented!() +} From 5dcb95dd7a344c0e9256657b515ae562155df78f Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 15:17:42 -0700 Subject: [PATCH 33/73] fix basic errors in linux impl --- lib/wasi/src/syscalls/unix/linux.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index cf62cc3800a..1454bea5565 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -1,5 +1,6 @@ use crate::syscalls::types::*; use std::cell::Cell; +use std::mem; use libc::preadv; @@ -12,10 +13,18 @@ pub fn platform_fd_pread( ) -> __wasi_errno_t { let (result, iovec) = unsafe { let mut iovec = vec![mem::uninitialized(); iovs_len as usize]; - (preadv(fd, &mut iovec, iovs_len, offset), iovec) + ( + preadv( + fd as i32, + iovec.as_mut_ptr(), + iovs_len as i32, + offset as i64, + ), + iovec, + ) }; - nread.set(result); - for (arr_cell, i) in iov_arr.iter().enumerate() { + nread.set(result as u32); + for (arr_cell, i) in iovs.iter().enumerate() { let wasi_iovec = __wasi_iovec_t { buf: iovec[i] as _, buf_len: iovec[i].iov_len as u32, From e7a5c01ef8dba3676d2c783c15c0003d1981af45 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 15:21:54 -0700 Subject: [PATCH 34/73] fix backward enumerate --- lib/wasi/src/syscalls/unix/linux.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 1454bea5565..601c49075f1 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -24,7 +24,7 @@ pub fn platform_fd_pread( ) }; nread.set(result as u32); - for (arr_cell, i) in iovs.iter().enumerate() { + for (i, arr_cell) in iovs.iter().enumerate() { let wasi_iovec = __wasi_iovec_t { buf: iovec[i] as _, buf_len: iovec[i].iov_len as u32, From 147d71a32c5e9f53865ac1eb827f18c9a4e06e79 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 15:39:36 -0700 Subject: [PATCH 35/73] implement ValueType for prestat_t --- lib/wasi/src/syscalls/types.rs | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 0221b1690df..19c8250572a 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -2,6 +2,7 @@ use crate::ptr::{Array, WasmPtr}; use wasmer_runtime_core::types::{ValueError, ValueType}; +use std::mem; pub type __wasi_advice_t = u8; pub const __WASI_ADVICE_DONTNEED: u8 = 0; @@ -170,12 +171,44 @@ pub struct __wasi_prestat_u_dir_t { pr_name_len: u32, } +impl ValueType for __wasi_prestat_u_dir_t { + fn into_le(self, buffer: &mut [u8]) { + self.pr_name_len + .into_le(&mut buffer[..mem::size_of::()]); + } + + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + let pr_name_len = ValueType::from_le(&buffer[..mem::size_of::()])?; + Ok(Self { pr_name_len }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + #[derive(Copy, Clone)] #[repr(C)] pub union __wasi_prestat_u { dir: __wasi_prestat_u_dir_t, } +impl ValueType for __wasi_prestat_u { + fn into_le(self, buffer: &mut [u8]) { + unsafe {self.dir + .into_le(&mut buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])}; + } + + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + let dir = ValueType::from_le(&buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])?; + Ok(Self { dir }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + #[derive(Copy, Clone)] #[repr(C)] pub struct __wasi_prestat_t { @@ -183,6 +216,25 @@ pub struct __wasi_prestat_t { u: __wasi_prestat_u, } +impl ValueType for __wasi_prestat_t { + fn into_le(self, buffer: &mut [u8]) { + self.pr_type + .into_le(&mut buffer[..mem::size_of::<__wasi_preopentype_t>()]); + self.u + .into_le(&mut buffer[mem::size_of::<__wasi_preopentype_t>()..]); + } + + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + let pr_type = ValueType::from_le(&buffer[..mem::size_of::<__wasi_preopentype_t>()])?; + let u = ValueType::from_le(&buffer[mem::size_of::<__wasi_preopentype_t>()..])?; + Ok(Self { pr_type, u }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct __wasi_fdstat_t { From 42e8523c0b0bc4a8aeeffe94a1b33bdc6acaadf4 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 15:49:42 -0700 Subject: [PATCH 36/73] impl ValueType for fdstat_t --- lib/wasi/src/syscalls/types.rs | 59 ++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 19c8250572a..378098bcbd0 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -1,8 +1,8 @@ #![allow(non_camel_case_types)] use crate::ptr::{Array, WasmPtr}; -use wasmer_runtime_core::types::{ValueError, ValueType}; use std::mem; +use wasmer_runtime_core::types::{ValueError, ValueType}; pub type __wasi_advice_t = u8; pub const __WASI_ADVICE_DONTNEED: u8 = 0; @@ -178,7 +178,7 @@ impl ValueType for __wasi_prestat_u_dir_t { } fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + if buffer.len() >= mem::size_of::<__wasi_prestat_u_dir_t>() { let pr_name_len = ValueType::from_le(&buffer[..mem::size_of::()])?; Ok(Self { pr_name_len }) } else { @@ -195,12 +195,14 @@ pub union __wasi_prestat_u { impl ValueType for __wasi_prestat_u { fn into_le(self, buffer: &mut [u8]) { - unsafe {self.dir - .into_le(&mut buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])}; + unsafe { + self.dir + .into_le(&mut buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()]) + }; } fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + if buffer.len() >= mem::size_of::<__wasi_prestat_u>() { let dir = ValueType::from_le(&buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])?; Ok(Self { dir }) } else { @@ -225,7 +227,7 @@ impl ValueType for __wasi_prestat_t { } fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { + if buffer.len() >= mem::size_of::<__wasi_prestat_t>() { let pr_type = ValueType::from_le(&buffer[..mem::size_of::<__wasi_preopentype_t>()])?; let u = ValueType::from_le(&buffer[mem::size_of::<__wasi_preopentype_t>()..])?; Ok(Self { pr_type, u }) @@ -244,6 +246,51 @@ pub struct __wasi_fdstat_t { pub fs_rights_inheriting: __wasi_rights_t, } +impl ValueType for __wasi_fdstat_t { + fn into_le(self, buffer: &mut [u8]) { + self.fs_filetype + .into_le(&mut buffer[..mem::size_of::<__wasi_filetype_t>()]); + self.fs_flags.into_le( + &mut buffer[mem::size_of::<__wasi_filetype_t>()..mem::size_of::<__wasi_fdflags_t>()], + ); + self.fs_rights_base.into_le( + &mut buffer[(mem::size_of::<__wasi_filetype_t>() + mem::size_of::<__wasi_fdflags_t>()) + ..mem::size_of::<__wasi_rights_t>()], + ); + self.fs_rights_inheriting.into_le( + &mut buffer[(mem::size_of::<__wasi_filetype_t>() + + mem::size_of::<__wasi_fdflags_t>() + + mem::size_of::<__wasi_rights_t>())..], + ); + } + + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::<__wasi_fdstat_t>() { + let fs_filetype = ValueType::from_le(&buffer[..mem::size_of::<__wasi_filetype_t>()])?; + let fs_flags = ValueType::from_le( + &buffer[mem::size_of::<__wasi_filetype_t>()..mem::size_of::<__wasi_fdflags_t>()], + )?; + let fs_rights_base = ValueType::from_le( + &buffer[(mem::size_of::<__wasi_filetype_t>() + mem::size_of::<__wasi_fdflags_t>()) + ..mem::size_of::<__wasi_rights_t>()], + )?; + let fs_rights_inheriting = ValueType::from_le( + &buffer[(mem::size_of::<__wasi_filetype_t>() + + mem::size_of::<__wasi_fdflags_t>() + + mem::size_of::<__wasi_rights_t>())..], + )?; + Ok(Self { + fs_filetype, + fs_flags, + fs_rights_base, + fs_rights_inheriting, + }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + pub type __wasi_filedelta_t = i64; pub type __wasi_filesize_t = u64; From 5cee576b7b0ed577d0e6a064de29eae46f9977a0 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 17:00:58 -0700 Subject: [PATCH 37/73] add some syscall skeletons; context switching --- lib/wasi/src/syscalls/mod.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d72cbf46610..227dd4647b4 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -240,16 +240,39 @@ pub fn fd_prestat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t>, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + + if let Some(prestat_ptr) = buf.deref(memory) { + // open fd + // write info to prestat_ptr + __WASI_ESUCCESS + } else { + __WASI_EFAULT + } } + pub fn fd_prestat_dir_name( ctx: &mut Ctx, fd: __wasi_fd_t, path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + + if let Some(path_chars) = path.deref(memory, 0, path_len) { + if true /* check if dir */ { + // get name + // write name + // if overflow __WASI_EOVERFLOW + __WASI_ESUCCESS + } else { + __WASI_ENOTDIR + } + } else { + __WASI_EFAULT + } } + pub fn fd_pwrite( ctx: &mut Ctx, fd: __wasi_fd_t, From e156ea2509582348dc20d3ce672d6a348be6b585 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Fri, 29 Mar 2019 17:02:58 -0700 Subject: [PATCH 38/73] comment out write logic in linux fd_pread until design discussion --- lib/wasi/src/syscalls/unix/linux.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs index 601c49075f1..627f95bf15c 100644 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -24,13 +24,13 @@ pub fn platform_fd_pread( ) }; nread.set(result as u32); - for (i, arr_cell) in iovs.iter().enumerate() { + /*for (i, arr_cell) in iovs.iter().enumerate() { let wasi_iovec = __wasi_iovec_t { buf: iovec[i] as _, buf_len: iovec[i].iov_len as u32, }; arr_cell.set(wasi_iovec); - } + }*/ __WASI_ESUCCESS } From 7addd920dff8b30be48e4708546a9a0af320529e Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 1 Apr 2019 12:11:11 -0700 Subject: [PATCH 39/73] add more stubs for fs calls --- lib/wasi/src/syscalls/mod.rs | 102 +++++++++++++++++++++++++++++++-- lib/wasi/src/syscalls/types.rs | 19 ++++++ 2 files changed, 117 insertions(+), 4 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 3e3dd3e8b35..a0bb8d78085 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -197,9 +197,27 @@ pub fn fd_allocate( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_close()` +/// Close an open file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// A file descriptor mapping to an open file to close +/// Errors: +/// - `__WASI_EISDIR` +/// If `fd` is a directory +/// - `__WASI_EBADF` +/// If `fd` is invalid or not open (TODO: consider __WASI_EINVAL) pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { - unimplemented!() + // FD is too large + return __WASI_EMFILE; + // FD is a directory (due to user input) + return __WASI_EISDIR; + // FD is invalid + return __WASI_EBADF; + __WASI_ESUCCESS } + pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } @@ -293,7 +311,9 @@ pub fn fd_prestat_dir_name( let memory = ctx.memory(0); if let Some(path_chars) = path.deref(memory, 0, path_len) { - if true /* check if dir */ { + if true + /* check if dir */ + { // get name // write name // if overflow __WASI_EOVERFLOW @@ -357,6 +377,21 @@ pub fn fd_tell( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_write()` +/// Write data to the file descriptor +/// Inputs: +/// - `__wasi_fd_t` +/// File descriptor (opened with writing) to write to +/// - `const __wasi_ciovec_t *iovs` +/// List of vectors to read data from +/// - `u32 iovs_len` +/// Length of data in `iovs` +/// Output: +/// - `u32 *nwritten` +/// Number of bytes written +/// Errors: +/// pub fn fd_write( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -364,8 +399,18 @@ pub fn fd_write( iovs_len: u32, nwritten: WasmPtr, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + // TODO: check __WASI_RIGHT_FD_WRITE + // return __WASI_EISDIR if dir (probably) + if let (Some(iovs_arr_cell), Some(nwritten_cell)) = + (iovs.deref(memory, 0, iovs_len), nwritten.deref(memory)) + { + unimplemented!() + } else { + __WASI_EFAULT + } } + pub fn path_create_directory( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -408,6 +453,31 @@ pub fn path_link( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `path_open()` +/// Open file located at the given path +/// Inputs: +/// - `__wasi_fd_t dirfd` +/// The fd corresponding to the directory that the file is in +/// - `__wasi_lookupflags_t dirflags` +/// Flags specifying how the path will be resolved +/// - `char *path` +/// The path of the file or directory to open +/// - `u32 path_len` +/// The length of the `path` string +/// - `__wasi_oflags_t o_flags` +/// How the file will be opened +/// - `__wasi_rights_t fs_rights_base` +/// The rights of the created file descriptor +/// - `__wasi_rights_t fs_rightsinheriting` +/// The rights of file descriptors derived from the created file descriptor +/// - `__wasi_fdflags_t fs_flags` +/// The flags of the file descriptor +/// Output: +/// - `__wasi_fd_t* fd` +/// The new file descriptor +/// Possible Errors: +/// - `__WASI_EACCES`, `__WASI_EBADF`, `__WASI_EFAULT`, `__WASI_EFBIG?`, `__WASI_EINVAL`, `__WASI_EIO`, `__WASI_ELOOP`, `__WASI_EMFILE`, `__WASI_ENAMETOOLONG?`, `__WASI_ENFILE`, `__WASI_ENOENT`, `__WASI_ENOTDIR`, `__WASI_EROFS`, and `__WASI_ENOTCAPABLE` pub fn path_open( ctx: &mut Ctx, dirfd: __wasi_fd_t, @@ -420,8 +490,32 @@ pub fn path_open( fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t>, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + if path_len > 1024 + /* TODO: find actual upper bound on name size (also this is a path, not a name :think-fish:) */ + { + return __WASI_ENAMETOOLONG; + } + + // check for __WASI_RIGHT_PATH_OPEN somewhere, probably via dirfd + + if let (Some(fd_cell), Some(path_cell)) = (fd.deref(memory), path.deref(memory, 0, path_len)) { + // o_flags: + // - __WASI_O_FLAG_CREAT (create if it does not exist) + // - __WASI_O_DIRECTORY (fail if not dir) + // - __WASI_O_EXCL (fail if file exists) + // - __WASI_O_TRUNC (truncate size to 0) + if (o_flags & __WASI_O_DIRECTORY) != 0 { + // fail if fd is not a dir + // need to check and be able to clean up + } + + unimplemented!(); + } else { + __WASI_EFAULT + } } + pub fn path_readlink( ctx: &mut Ctx, fd: __wasi_fd_t, diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 368b2fe49d2..20d9d95fb22 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -19,6 +19,25 @@ pub struct __wasi_ciovec_t { pub buf_len: u32, } +impl ValueType for __wasi_ciovec_t { + fn into_le(self, buffer: &mut [u8]) { + self.buf + .into_le(&mut buffer[..mem::size_of::>()]); + self.buf_len + .into_le(&mut buffer[mem::size_of::>()..]); + } + + fn from_le(buffer: &[u8]) -> Result { + if buffer.len() >= mem::size_of::<__wasi_ciovec_t>() { + let buf = ValueType::from_le(&buffer[..mem::size_of::>()])?; + let buf_len = ValueType::from_le(&buffer[mem::size_of::>()..])?; + Ok(Self { buf, buf_len }) + } else { + Err(ValueError::BufferTooSmall) + } + } +} + pub type __wasi_clockid_t = u32; pub const __WASI_CLOCK_MONOTONIC: u32 = 0; pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 1; From 5b6856df6b9a22ba949a6c15cdc37407ed6e5202 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 1 Apr 2019 14:04:58 -0700 Subject: [PATCH 40/73] add lots of doc comments --- lib/wasi/src/syscalls/mod.rs | 168 ++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index a0bb8d78085..18ee35606b8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -336,6 +336,19 @@ pub fn fd_pwrite( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_read()` +/// Read data from file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// File descriptor from which data will be read +/// - `const __wasi_iovec_t *iovs` +/// Vectors where data will be stored +/// - `u32 iovs_len` +/// Length of data in `iovs` +/// Output: +/// - `u32 *nread` +/// Number of bytes read pub fn fd_read( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -343,8 +356,34 @@ pub fn fd_read( iovs_len: u32, nread: WasmPtr, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + + // check __WASI_RIGHT_FD_READ + + if let (Some(iovs_arr_cell), Some(nwritten_cell)) = + (iovs.deref(memory, 0, iovs_len), nread.deref(memory)) + { + unimplemented!() + } else { + __WASI_EFAULT + } } + +/// ### `fd_readdir()` +/// Read data from directory specified by file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// File descriptor from which directory data will be read +/// - `void *buf` +/// Buffer where directory entries are stored +/// - `u32 buf_len` +/// Length of data in `buf` +/// - `__wasi_dircookie_t cookie` +/// Where the directory reading should start from +/// Output: +/// - `u32 *bufused` +/// The Number of bytes stored in `buf`; if less than `buf_len` then entire +/// directory has been read pub fn fd_readdir( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -353,11 +392,40 @@ pub fn fd_readdir( cookie: __wasi_dircookie_t, bufused: WasmPtr, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + + if let (Some(buf_arr_cell), Some(bufused_cell)) = + (buf.deref(memory, 0, buf_len), bufused.deref(memory)) + { + unimplemented!() + } else { + __WASI_EFAULT + } } + +/// ### `fd_renumber()` +/// Atomically copy file descriptor +/// Inputs: +/// - `__wasi_fd_t from` +/// File descriptor to copy +/// - `__wasi_fd_t to` +/// Location to copy file descriptor to pub fn fd_renumber(ctx: &mut Ctx, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_seek()` +/// Update file descriptor offset +/// Inputs: +/// - `__wasi_fd_t fd` +/// File descriptor to mutate +/// - `__wasi_filedelta_t offset` +/// Number of bytes to adjust offset by +/// - `__wasi_whence_t whence` +/// What the offset is relative to +/// Output: +/// - `__wasi_filesize_t *fd` +/// The new offset relative to the start of the file pub fn fd_seek( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -365,16 +433,44 @@ pub fn fd_seek( whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t>, ) -> __wasi_errno_t { - unimplemented!() + let memory = ctx.memory(0); + // TODO: check __WASI_RIGHT_FD_SEEK + // TODO: handle directory input + if let Some(new_offset_cell) = newoffset.deref(memory) { + unimplemented!() + } else { + __WASI_EFAULT + } } + +/// ### `fd_sync()` +/// Synchronize file and metadata to disk (TODO: expand upon what this means in our system) +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor to sync +/// Errors: +/// TODO: figure out which errors this should return +/// - `__WASI_EPERM` +/// - `__WAIS_ENOTCAPABLE` pub fn fd_sync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { + // TODO: check __WASI_RIGHT_FD_SYNC unimplemented!() } + +/// ### `fd_tell()` +/// Get the offset of the file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor to access +/// Output: +/// - `__wasi_filesize_t *offset` +/// The offset of `fd` relative to the start of the file pub fn fd_tell( ctx: &mut Ctx, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t>, ) -> __wasi_errno_t { + // TODO: check __WASI_RIGHT_FD_TELL unimplemented!() } @@ -411,14 +507,43 @@ pub fn fd_write( } } +/// ### `path_create_directory()` +/// Create directory at a path +/// Inputs: +/// - `__wasi_fd_t fd` +/// The directory that the path is relative to +/// - `const char *path` +/// String containing path data +/// - `u32 path_len` +/// The length of `path` +/// Errors: +/// Required Rights: +/// - __WASI_RIGHT_PATH_CREATE_DIRECTORY +/// This right must be set on the directory that the file is created in (TODO: verify that this is true) pub fn path_create_directory( ctx: &mut Ctx, fd: __wasi_fd_t, path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { + // check __WASI_RIGHT_PATH_CREATE_DIRECTORY unimplemented!() } + +/// ### `path_filestat_get()` +/// Access metadata about a file or directory +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file to acces +/// - `__wasi_lookupflags_t flags` +/// Flags to control how the path is understood +/// - `const char *path` +/// String containing the file path +/// - `u32 path_len` +/// The length of the `path` string +/// Output: +/// - `__wasi_file_stat_t *buf` +/// The location where the metadata will be stored pub fn path_filestat_get( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -427,8 +552,27 @@ pub fn path_filestat_get( path_len: u32, buf: WasmPtr<__wasi_filestat_t>, ) -> __wasi_errno_t { + // check __WASI_RIGHT_PATH_FILESTAT_GET unimplemented!() } + +/// ### `path_filestat_set_times()` +/// Update time metadata on a file or directory +/// Inputs: +/// - `__wasi_fd_t fd` +/// The directory relative to which the path is resolved +/// - `__wasi_lookupflags_t flags` +/// Flags to control how the path is understood +/// - `const char *path` +/// String containing the file path +/// - `u32 path_len` +/// The length of the `path` string +/// - `__wasi_timestamp_t st_atim` +/// The timestamp that the last accessed time attribute is set to +/// - `__wasi_timestamp_t st_mtim` +/// The timestamp that the last modified time attribute is set to +/// - `__wasi_fstflags_t fst_flags` +/// A bitmask controlling which attributes are set pub fn path_filestat_set_times( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -441,6 +585,24 @@ pub fn path_filestat_set_times( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `path_link()` +/// Create a hard link +/// Inputs: +/// - `__wasi_fd_t old_fd` +/// The directory relative to which the `old_path` is +/// - `__wasi_lookupflags_t old_flags` +/// Flags to control how `old_path` is understood +/// - `const char *old_path` +/// String containing the old file path +/// - `u32 old_path_len` +/// Length of the `old_path` string +/// - `__wasi_fd_t new_fd` +/// The directory relative to which the `new_path` is +/// - `const char *new_path` +/// String containing the new file path +/// - `u32 old_path_len` +/// Length of the `new_path` string pub fn path_link( ctx: &mut Ctx, old_fd: __wasi_fd_t, From 68f1123ad6fc70e2a4f28fb0b28dcebbfbaad82e Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 1 Apr 2019 15:15:20 -0700 Subject: [PATCH 41/73] Add start of wasi fs --- lib/wasi/Cargo.toml | 7 +- lib/wasi/src/lib.rs | 7 +- lib/wasi/src/state.rs | 179 ++++++++++++++++++++++++++++++++++- lib/wasi/src/syscalls/mod.rs | 17 +++- 4 files changed, 205 insertions(+), 5 deletions(-) diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 17a2f14f429..8657fa92d10 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -5,4 +5,9 @@ authors = ["The Wasmer Engineering Team "] edition = "2018" [dependencies] -wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } \ No newline at end of file +wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } +# wasmer-runtime-abi = { path = "../runtime-abi" } +hashbrown = "0.1.8" +generational-arena = "0.2.2" +zbox = "0.6.1" +log = "0.4.6" \ No newline at end of file diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 3dcb2f7cb7e..27e9455029e 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,9 +1,13 @@ + +#[macro_use] +extern crate log; + mod ptr; mod state; mod syscalls; mod utils; -use self::state::WasiState; +use self::state::{WasiState, WasiFs}; use self::syscalls::*; use std::ffi::c_void; @@ -21,6 +25,7 @@ pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportO } let state = Box::new(WasiState { + fs: WasiFs::new().unwrap(), args: &args[..], envs: &envs[..], }); diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index e7cafc1baf7..3dd97b39b35 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -1,5 +1,182 @@ +// use wasmer_runtime_abi::vfs::{ +// vfs::Vfs, +// file_like::{FileLike, Metadata}; +// }; +use std::{ + cell::{Cell, RefCell}, + ops::{Index, IndexMut}, + rc::Rc, + time::SystemTime, +}; +use generational_arena::{Arena, Index as Inode}; +use hashbrown::hash_map::{HashMap, Entry}; +use zbox::{ + RepoOpener, + Repo, + File, + FileType, + OpenOptions, +}; +use crate::syscalls::types::*; + +pub const MAX_SYMLINKS: usize = 100; + +pub struct InodeVal { + stat: __wasi_filestat_t, + is_preopened: bool, + name: String, + kind: Kind, +} + +pub enum Kind { + File { + handle: File, + }, + Dir { + handle: File, + /// The entries of a directory are lazily filled. + entries: Vec, + }, + Symlink { + forwarded: Inode, + }, + Buffer { + buffer: Vec, + }, +} + +pub struct Fd { + rights: __wasi_rights_t, + flags: __wasi_fdflags_t, + offset: u64, + inode: Inode, +} + +pub struct WasiFs { + repo: Repo, + name_map: HashMap, + inodes: Arena, + fd_map: HashMap, + next_fd: Cell, + inode_counter: Cell, +} + +impl WasiFs { + pub fn new() -> Result { + Ok(Self { + repo: RepoOpener::new().create(true).open("mem://📂", "very unsafe pwd").map_err(|e| e.to_string())?, + name_map: HashMap::new(), + inodes: Arena::new(), + fd_map: HashMap::new(), + next_fd: Cell::new(3), + inode_counter: Cell::new(1000), + }) + } + + fn get_inode(&mut self, path: &str) -> Option { + Some(match self.name_map.entry(path.to_string()) { + Entry::Occupied(o) => *o.get(), + Entry::Vacant(v) => { + let file = if let Ok(file) = OpenOptions::new().read(true).write(true).create(false).open(&mut self.repo, path) { + file + } else { + return None; + }; + + let metadata = file.metadata().unwrap(); + let inode_index = { + let index = self.inode_counter.get(); + self.inode_counter.replace(index + 1) + }; + + let systime_to_nanos = |systime: SystemTime| { + let duration = systime.duration_since(SystemTime::UNIX_EPOCH).expect("should always be after unix epoch"); + duration.as_nanos() as u64 + }; + + let inode = self.inodes.insert(InodeVal { + stat: __wasi_filestat_t { + st_dev: 0, + st_ino: inode_index, + st_filetype: match metadata.file_type() { + FileType::File => __WASI_FILETYPE_REGULAR_FILE, + FileType::Dir => __WASI_FILETYPE_DIRECTORY, + }, + st_nlink: 0, + st_size: metadata.len() as u64, + st_atim: systime_to_nanos(SystemTime::now()), + st_mtim: systime_to_nanos(metadata.modified()), + st_ctim: systime_to_nanos(metadata.created()), + }, + is_preopened: false, + name: path.to_string(), + kind: match metadata.file_type() { + FileType::File => Kind::File { + handle: file, + }, + FileType::Dir => Kind::Dir { + handle: file, + entries: Vec::new(), + }, + }, + }); + v.insert(inode); + inode + }, + }) + } + + fn filestat_inode(&self, inode: Inode, flags: __wasi_lookupflags_t) -> Result<__wasi_filestat_t, __wasi_errno_t> { + let inode_val = &self.inodes[inode]; + if let (true, Kind::Symlink { mut forwarded }) = (flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0, &inode_val.kind) { + // Time to follow the symlink. + let mut counter = 0; + + while counter <= MAX_SYMLINKS { + let inode_val = &self.inodes[forwarded]; + if let &Kind::Symlink { forwarded: new_forwarded } = &inode_val.kind { + counter += 1; + forwarded = new_forwarded; + } else { + return Ok(inode_val.stat); + } + } + + Err(__WASI_EMLINK) + } else { + Ok(inode_val.stat) + } + } + + pub fn filestat_path( + &mut self, + preopened_fd: __wasi_fd_t, + flags: __wasi_lookupflags_t, + path: &str, + ) -> Result<__wasi_filestat_t, __wasi_errno_t> { + warn!("Should use preopned_fd: {}", preopened_fd); + let inode = if let Some(inode) = self.get_inode(path) { + inode + } else { + return Err(__WASI_EINVAL); + }; + + self.filestat_inode(inode, flags) + } + + pub fn filestat_fd(&self, fd: __wasi_fd_t) -> Result<__wasi_filestat_t, __wasi_errno_t> { + let fd = if let Some(fd) = self.fd_map.get(&fd) { + fd + } else { + return Err(__WASI_EBADF); + }; + + self.filestat_inode(fd.inode, 0) + } +} + pub struct WasiState<'a> { - // vfs: Vfs, + pub fs: WasiFs, pub args: &'a [Vec], pub envs: &'a [Vec], } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d72cbf46610..3e5442b32e9 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,6 +1,6 @@ #![allow(unused)] -mod types; +pub mod types; use self::types::*; use crate::{ @@ -185,7 +185,20 @@ pub fn fd_fdstat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_fdstat_t>, ) -> __wasi_errno_t { - unimplemented!() + let mut state = get_wasi_state(ctx); + let memory = ctx.memory(0); + + let stat = match state.fs.filestat_fd(fd) { + Ok(stat) => stat, + Err(errno) => return errno, + }; + + if let Some(buf) = buf.deref(memory) { + buf.set(stat); + __WASI_ESUCCESS + } else { + __WASI_EFAULT + } } pub fn fd_fdstat_set_flags( ctx: &mut Ctx, From 61dd2e1df93d825aaf54b60628e9d73fa9b93f15 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 1 Apr 2019 15:22:30 -0700 Subject: [PATCH 42/73] add more doc comments --- lib/wasi/src/syscalls/mod.rs | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 18ee35606b8..efb22831aac 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -104,6 +104,14 @@ pub fn args_sizes_get( } } +/// ### `clock_res_get()` +/// Get the resolution of the specified clock +/// Input: +/// - `__wasi_clockid_t clock_id` +/// The ID of the clock to get the resolution of +/// Output: +/// - `__wasi_timestamp_t *resolution` +/// The resolution of the clock in nanoseconds pub fn clock_res_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, @@ -118,6 +126,16 @@ pub fn clock_res_get( } } +/// ### `clock_time_get()` +/// Get the time of the specified clock +/// Inputs: +/// - `__wasi_clockid_t clock_id` +/// The ID of the clock to query +/// - `__wasi_timestamp_t precision` +/// The maximum amount of error the reading may have +/// Output: +/// - `__wasi_timestamp_t *time` +/// The value of the clock in nanoseconds pub fn clock_time_get( ctx: &mut Ctx, clock_id: __wasi_clockid_t, @@ -180,6 +198,17 @@ pub fn environ_sizes_get( } } +/// ### `fd_advise()` +/// Advise the system about how a file will be used +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor the advice applies to +/// - `__wasi_filesize_t offset` +/// The offset from which the advice applies +/// - `__wasi_filesize_t len` +/// The length from the offset to which the advice applies +/// - `__wasi_advice_t advice` +/// The advice to give pub fn fd_advise( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -189,6 +218,16 @@ pub fn fd_advise( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_allocate` +/// Allocate extra space for a file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor to allocate for +/// - `__wasi_filesize_t offset` +/// The offset from the start marking the beginning of the allocation +/// - `__wasi_filesize_t len` +/// The length from the offset marking the end of the allocation pub fn fd_allocate( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -218,9 +257,23 @@ pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { __WASI_ESUCCESS } +/// ### `fd_datasync()` +/// Synchronize the file data to disk +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor to sync pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_fdstat_get()` +/// Get metadata of a file descriptor +/// Input: +/// - `__wasi_fd_t fd` +/// The file descriptor whose metadata will be accessed +/// Output: +/// - `__wasi_fdstat_t *buf` +/// The location where the metadata will be written pub fn fd_fdstat_get( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -228,6 +281,14 @@ pub fn fd_fdstat_get( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_fdstat_set_flags()` +/// Set file descriptor flags for a file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor to apply the new flags to +/// - `__wasi_fdflags_t flags` +/// The flags to apply to `fd` pub fn fd_fdstat_set_flags( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -235,6 +296,16 @@ pub fn fd_fdstat_set_flags( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_fdstat_set_rights()` +/// Set the rights of a file descriptor +/// Inputs: +/// - `__wasi_fd_t fd` +/// The file descriptor to apply the new rights to +/// - `__wasi_rights_t fs_rights_base` +/// The rights to apply to `fd` +/// - `__wasi_rights_t fs_rights_inheriting` +/// The inheriting rights to apply to `fd` pub fn fd_fdstat_set_rights( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -243,6 +314,15 @@ pub fn fd_fdstat_set_rights( ) -> __wasi_errno_t { unimplemented!() } + +/// ### `fd_filestat_get()` +/// Get the metadata of an open file +/// Input: +/// - `__wasi_fd_t fd` +/// The open file descriptor whose metadata will be read +/// Output: +/// - `__wasi_filestat_t *buf` +/// Where the metadata from `fd` will be written pub fn fd_filestat_get( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -250,6 +330,7 @@ pub fn fd_filestat_get( ) -> __wasi_errno_t { unimplemented!() } + pub fn fd_filestat_set_size( ctx: &mut Ctx, fd: __wasi_fd_t, From ce35e5794f71db5652ec9b19c5ccd5537e6ffb93 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 1 Apr 2019 15:52:35 -0700 Subject: [PATCH 43/73] Change ValueType trait and add basic fs --- Cargo.lock | 100 +++++++++++++++++++++++ lib/runtime-core/src/types.rs | 46 +---------- lib/wasi/Cargo.toml | 1 + lib/wasi/src/lib.rs | 3 +- lib/wasi/src/ptr.rs | 20 +---- lib/wasi/src/state.rs | 75 +++++++++++++----- lib/wasi/src/syscalls/mod.rs | 17 +++- lib/wasi/src/syscalls/types.rs | 141 +++------------------------------ 8 files changed, 186 insertions(+), 217 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35d9b9aea26..d34da510d23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,6 +121,11 @@ dependencies = [ "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bitflags" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.0.4" @@ -552,6 +557,18 @@ dependencies = [ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "env_logger" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "env_logger" version = "0.6.1" @@ -684,6 +701,14 @@ name = "gcc" version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "generational-arena" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "generic-array" version = "0.12.0" @@ -692,6 +717,14 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "getopts" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "glob" version = "0.2.11" @@ -948,6 +981,16 @@ dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lz4" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "lz4-sys 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "skeptic 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lz4" version = "1.23.1" @@ -957,6 +1000,15 @@ dependencies = [ "lz4-sys 1.8.3 (git+https://github.com/zboxfs/lz4-rs.git)", ] +[[package]] +name = "lz4-sys" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lz4-sys" version = "1.8.3" @@ -1295,6 +1347,15 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pulldown-cmark" +version = "0.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quick-error" version = "1.2.2" @@ -1720,6 +1781,15 @@ name = "siphasher" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "skeptic" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "slab" version = "0.4.2" @@ -2360,9 +2430,14 @@ dependencies = [ name = "wasmer-wasi" version = "0.1.0" dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", + "zbox 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2485,6 +2560,22 @@ dependencies = [ "tar 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "zbox" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", + "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "lz4 1.22.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rmp-serde 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "zstd" version = "0.4.22+zstd.1.3.8" @@ -2528,6 +2619,7 @@ dependencies = [ "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f7f7f0701772b17de73e4f5cbcb1dd6926f4706cba4c1ab62c5367f8bdc94e1" +"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce2571a6cd634670daa2977cc894c1cc2ba57c563c498e5a82c35446f34d056e" "checksum blob 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19803aa44ff8b43123bbe369efaddcb638ea7dc332e543972dd95ac7cb148b92" @@ -2575,6 +2667,7 @@ dependencies = [ "checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" "checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed" "checksum enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7798e7da2d4cb0d6d6fc467e8d6b5bf247e9e989f786dde1732d79899c32bb10" +"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" @@ -2592,7 +2685,9 @@ dependencies = [ "checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" +"checksum generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4024f96ffa0ebaaf36aa589cd41f2fd69f3a5e6fd02c86e11e12cdf41d5b46a3" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" +"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "84473a5302fa5094d3d9911c2f312f522f9a37462a777f195f63fae1bf7faf4d" "checksum h2 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "910a5e7be6283a9c91b3982fa5188368c8719cce2a3cf3b86048673bf9d9c36b" @@ -2621,7 +2716,9 @@ dependencies = [ "checksum llvm-sys 70.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60a9ee82fe0fa72ae6ef6d018b407296085863836451c7a97384f84ed7e26b9f" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum lz4 1.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe55d2ebbc2e4fc987e6fbfc13f416d97b06d06e50bc1124d613aa790842f80c" "checksum lz4 1.23.1 (git+https://github.com/zboxfs/lz4-rs.git)" = "" +"checksum lz4-sys 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a59044c3ba3994f3d2aa2270ddd6c5947922219501e67efde5604d36aad462b5" "checksum lz4-sys 1.8.3 (git+https://github.com/zboxfs/lz4-rs.git)" = "" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" @@ -2660,6 +2757,7 @@ dependencies = [ "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" +"checksum pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1058d7bb927ca067656537eec4e02c2b4b70eaaa129664c5b90c111e20326f41" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" @@ -2707,6 +2805,7 @@ dependencies = [ "checksum serde_test 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "70807e147558b5253cb70f55d343db1d07204d773087c96d0f35fced295dba82" "checksum serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d48f9f99cd749a2de71d29da5f948de7f2764cc5a9d7f3c97e3514d4ee6eabf2" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" +"checksum skeptic 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd7d8dc1315094150052d0ab767840376335a98ac66ef313ff911cdf439a5b69" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -2776,6 +2875,7 @@ dependencies = [ "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" "checksum zbox 0.6.1 (git+https://github.com/wasmerio/zbox?branch=bundle-libsodium)" = "" +"checksum zbox 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4a969b504de4ee47ac68bbd035b0c5a53818edb1edd6737131de001de2a09e64" "checksum zstd 0.4.22+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6f042dd18d52854d302d3d92f66d0a63c2d520d7b7034a9d43cde7441d1b4ddd" "checksum zstd-safe 1.4.7+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "63febf0b0dcd076db81e6b3110ed254cfb8ed54378a4c3cfbb68956e839d4f59" "checksum zstd-sys 1.4.8+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4cb187d624025a7d9878ecf13437491869423426183ded2fa40d4651b85f7ae7" diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index d9e983f34dc..7a51c1c6f80 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -126,34 +126,14 @@ unsafe impl WasmExternType for f64 { // fn swap(&self, other: Self::Primitive) -> Self::Primitive; // } -pub enum ValueError { - BufferTooSmall, -} - -pub trait ValueType: Copy +pub unsafe trait ValueType: Copy where Self: Sized, -{ - fn into_le(self, buffer: &mut [u8]); - fn from_le(buffer: &[u8]) -> Result; -} +{} macro_rules! convert_value_impl { ($t:ty) => { - impl ValueType for $t { - fn into_le(self, buffer: &mut [u8]) { - buffer[..mem::size_of::()].copy_from_slice(&self.to_le_bytes()); - } - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::() { - let mut array = [0u8; mem::size_of::()]; - array.copy_from_slice(&buffer[..mem::size_of::()]); - Ok(Self::from_le_bytes(array)) - } else { - Err(ValueError::BufferTooSmall) - } - } - } + unsafe impl ValueType for $t {} }; ( $($t:ty),* ) => { $( @@ -162,25 +142,7 @@ macro_rules! convert_value_impl { }; } -convert_value_impl!(u8, i8, u16, i16, u32, i32, u64, i64); - -impl ValueType for f32 { - fn into_le(self, buffer: &mut [u8]) { - self.to_bits().into_le(buffer); - } - fn from_le(buffer: &[u8]) -> Result { - Ok(f32::from_bits(::from_le(buffer)?)) - } -} - -impl ValueType for f64 { - fn into_le(self, buffer: &mut [u8]) { - self.to_bits().into_le(buffer); - } - fn from_le(buffer: &[u8]) -> Result { - Ok(f64::from_bits(::from_le(buffer)?)) - } -} +convert_value_impl!(u8, i8, u16, i16, u32, i32, u64, i64, f32, f64); #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] pub enum ElementType { diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 0352ce1e1bd..da41195598f 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -13,3 +13,4 @@ hashbrown = "0.1.8" generational-arena = "0.2.2" zbox = "0.6.1" log = "0.4.6" +byteorder = "1.3.1" diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 27e9455029e..ba91b2aa637 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,4 +1,3 @@ - #[macro_use] extern crate log; @@ -7,7 +6,7 @@ mod state; mod syscalls; mod utils; -use self::state::{WasiState, WasiFs}; +use self::state::{WasiFs, WasiState}; use self::syscalls::*; use std::ffi::c_void; diff --git a/lib/wasi/src/ptr.rs b/lib/wasi/src/ptr.rs index f6d1c4ce4f8..b4fc7a9a5cd 100644 --- a/lib/wasi/src/ptr.rs +++ b/lib/wasi/src/ptr.rs @@ -1,7 +1,7 @@ use std::{cell::Cell, fmt, marker::PhantomData, mem}; use wasmer_runtime_core::{ memory::Memory, - types::{Type, ValueError, ValueType, WasmExternType}, + types::{Type, ValueType, WasmExternType}, }; pub struct Array; @@ -68,23 +68,7 @@ unsafe impl WasmExternType for WasmPtr { const TYPE: Type = Type::I32; } -impl ValueType for WasmPtr { - fn into_le(self, buffer: &mut [u8]) { - buffer[..mem::size_of::()].copy_from_slice(&self.offset.to_le_bytes()); - } - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::() { - let mut array = [0u8; mem::size_of::()]; - array.copy_from_slice(&buffer[..mem::size_of::()]); - Ok(Self { - offset: u32::from_le_bytes(array), - _phantom: PhantomData, - }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for WasmPtr {} impl Clone for WasmPtr { fn clone(&self) -> Self { diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 3dd97b39b35..3a243860b9a 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -2,22 +2,16 @@ // vfs::Vfs, // file_like::{FileLike, Metadata}; // }; +use crate::syscalls::types::*; +use generational_arena::{Arena, Index as Inode}; +use hashbrown::hash_map::{Entry, HashMap}; use std::{ cell::{Cell, RefCell}, ops::{Index, IndexMut}, rc::Rc, time::SystemTime, }; -use generational_arena::{Arena, Index as Inode}; -use hashbrown::hash_map::{HashMap, Entry}; -use zbox::{ - RepoOpener, - Repo, - File, - FileType, - OpenOptions, -}; -use crate::syscalls::types::*; +use zbox::{File, FileType, OpenOptions, Repo, RepoOpener}; pub const MAX_SYMLINKS: usize = 100; @@ -64,7 +58,10 @@ pub struct WasiFs { impl WasiFs { pub fn new() -> Result { Ok(Self { - repo: RepoOpener::new().create(true).open("mem://📂", "very unsafe pwd").map_err(|e| e.to_string())?, + repo: RepoOpener::new() + .create(true) + .open("mem://📂", "very unsafe pwd") + .map_err(|e| e.to_string())?, name_map: HashMap::new(), inodes: Arena::new(), fd_map: HashMap::new(), @@ -77,12 +74,17 @@ impl WasiFs { Some(match self.name_map.entry(path.to_string()) { Entry::Occupied(o) => *o.get(), Entry::Vacant(v) => { - let file = if let Ok(file) = OpenOptions::new().read(true).write(true).create(false).open(&mut self.repo, path) { + let file = if let Ok(file) = OpenOptions::new() + .read(true) + .write(true) + .create(false) + .open(&mut self.repo, path) + { file } else { return None; }; - + let metadata = file.metadata().unwrap(); let inode_index = { let index = self.inode_counter.get(); @@ -90,7 +92,9 @@ impl WasiFs { }; let systime_to_nanos = |systime: SystemTime| { - let duration = systime.duration_since(SystemTime::UNIX_EPOCH).expect("should always be after unix epoch"); + let duration = systime + .duration_since(SystemTime::UNIX_EPOCH) + .expect("should always be after unix epoch"); duration.as_nanos() as u64 }; @@ -111,9 +115,7 @@ impl WasiFs { is_preopened: false, name: path.to_string(), kind: match metadata.file_type() { - FileType::File => Kind::File { - handle: file, - }, + FileType::File => Kind::File { handle: file }, FileType::Dir => Kind::Dir { handle: file, entries: Vec::new(), @@ -122,19 +124,28 @@ impl WasiFs { }); v.insert(inode); inode - }, + } }) } - fn filestat_inode(&self, inode: Inode, flags: __wasi_lookupflags_t) -> Result<__wasi_filestat_t, __wasi_errno_t> { + fn filestat_inode( + &self, + inode: Inode, + flags: __wasi_lookupflags_t, + ) -> Result<__wasi_filestat_t, __wasi_errno_t> { let inode_val = &self.inodes[inode]; - if let (true, Kind::Symlink { mut forwarded }) = (flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0, &inode_val.kind) { + if let (true, Kind::Symlink { mut forwarded }) = + (flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0, &inode_val.kind) + { // Time to follow the symlink. let mut counter = 0; while counter <= MAX_SYMLINKS { let inode_val = &self.inodes[forwarded]; - if let &Kind::Symlink { forwarded: new_forwarded } = &inode_val.kind { + if let &Kind::Symlink { + forwarded: new_forwarded, + } = &inode_val.kind + { counter += 1; forwarded = new_forwarded; } else { @@ -171,7 +182,27 @@ impl WasiFs { return Err(__WASI_EBADF); }; - self.filestat_inode(fd.inode, 0) + Ok(self.inodes[fd.inode].stat) + } + + pub fn fdstat(&self, fd: __wasi_fd_t) -> Result<__wasi_fdstat_t, __wasi_errno_t> { + let fd = if let Some(fd) = self.fd_map.get(&fd) { + fd + } else { + return Err(__WASI_EBADF); + }; + + Ok(__wasi_fdstat_t { + fs_filetype: match self.inodes[fd.inode].kind { + Kind::File { .. } => __WASI_FILETYPE_REGULAR_FILE, + Kind::Dir { .. } => __WASI_FILETYPE_DIRECTORY, + Kind::Symlink { .. } => __WASI_FILETYPE_SYMBOLIC_LINK, + _ => __WASI_FILETYPE_UNKNOWN, + }, + fs_flags: fd.flags, + fs_rights_base: fd.rights, + fs_rights_inheriting: fd.rights, // TODO(lachlan): Is this right? + }) } } diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index c3b827a398e..3b1824e0199 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -229,7 +229,7 @@ pub fn fd_fdstat_get( let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); - let stat = match state.fs.filestat_fd(fd) { + let stat = match state.fs.fdstat(fd) { Ok(stat) => stat, Err(errno) => return errno, }; @@ -261,7 +261,20 @@ pub fn fd_filestat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t>, ) -> __wasi_errno_t { - unimplemented!() + let mut state = get_wasi_state(ctx); + let memory = ctx.memory(0); + + let stat = match state.fs.filestat_fd(fd) { + Ok(stat) => stat, + Err(errno) => return errno, + }; + + if let Some(buf) = buf.deref(memory) { + buf.set(stat); + __WASI_ESUCCESS + } else { + __WASI_EFAULT + } } pub fn fd_filestat_set_size( ctx: &mut Ctx, diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 20d9d95fb22..17098aacf0c 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -1,8 +1,9 @@ #![allow(non_camel_case_types)] use crate::ptr::{Array, WasmPtr}; +use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use std::mem; -use wasmer_runtime_core::types::{ValueError, ValueType}; +use wasmer_runtime_core::types::ValueType; pub type __wasi_advice_t = u8; pub const __WASI_ADVICE_DONTNEED: u8 = 0; @@ -19,24 +20,7 @@ pub struct __wasi_ciovec_t { pub buf_len: u32, } -impl ValueType for __wasi_ciovec_t { - fn into_le(self, buffer: &mut [u8]) { - self.buf - .into_le(&mut buffer[..mem::size_of::>()]); - self.buf_len - .into_le(&mut buffer[mem::size_of::>()..]); - } - - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_ciovec_t>() { - let buf = ValueType::from_le(&buffer[..mem::size_of::>()])?; - let buf_len = ValueType::from_le(&buffer[mem::size_of::>()..])?; - Ok(Self { buf, buf_len }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for __wasi_ciovec_t {} pub type __wasi_clockid_t = u32; pub const __WASI_CLOCK_MONOTONIC: u32 = 0; @@ -190,21 +174,7 @@ pub struct __wasi_prestat_u_dir_t { pr_name_len: u32, } -impl ValueType for __wasi_prestat_u_dir_t { - fn into_le(self, buffer: &mut [u8]) { - self.pr_name_len - .into_le(&mut buffer[..mem::size_of::()]); - } - - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_prestat_u_dir_t>() { - let pr_name_len = ValueType::from_le(&buffer[..mem::size_of::()])?; - Ok(Self { pr_name_len }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for __wasi_prestat_u_dir_t {} #[derive(Copy, Clone)] #[repr(C)] @@ -212,23 +182,7 @@ pub union __wasi_prestat_u { dir: __wasi_prestat_u_dir_t, } -impl ValueType for __wasi_prestat_u { - fn into_le(self, buffer: &mut [u8]) { - unsafe { - self.dir - .into_le(&mut buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()]) - }; - } - - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_prestat_u>() { - let dir = ValueType::from_le(&buffer[..mem::size_of::<__wasi_prestat_u_dir_t>()])?; - Ok(Self { dir }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for __wasi_prestat_u {} #[derive(Copy, Clone)] #[repr(C)] @@ -237,24 +191,7 @@ pub struct __wasi_prestat_t { u: __wasi_prestat_u, } -impl ValueType for __wasi_prestat_t { - fn into_le(self, buffer: &mut [u8]) { - self.pr_type - .into_le(&mut buffer[..mem::size_of::<__wasi_preopentype_t>()]); - self.u - .into_le(&mut buffer[mem::size_of::<__wasi_preopentype_t>()..]); - } - - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_prestat_t>() { - let pr_type = ValueType::from_le(&buffer[..mem::size_of::<__wasi_preopentype_t>()])?; - let u = ValueType::from_le(&buffer[mem::size_of::<__wasi_preopentype_t>()..])?; - Ok(Self { pr_type, u }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for __wasi_prestat_t {} #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(C)] @@ -265,50 +202,7 @@ pub struct __wasi_fdstat_t { pub fs_rights_inheriting: __wasi_rights_t, } -impl ValueType for __wasi_fdstat_t { - fn into_le(self, buffer: &mut [u8]) { - self.fs_filetype - .into_le(&mut buffer[..mem::size_of::<__wasi_filetype_t>()]); - self.fs_flags.into_le( - &mut buffer[mem::size_of::<__wasi_filetype_t>()..mem::size_of::<__wasi_fdflags_t>()], - ); - self.fs_rights_base.into_le( - &mut buffer[(mem::size_of::<__wasi_filetype_t>() + mem::size_of::<__wasi_fdflags_t>()) - ..mem::size_of::<__wasi_rights_t>()], - ); - self.fs_rights_inheriting.into_le( - &mut buffer[(mem::size_of::<__wasi_filetype_t>() - + mem::size_of::<__wasi_fdflags_t>() - + mem::size_of::<__wasi_rights_t>())..], - ); - } - - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_fdstat_t>() { - let fs_filetype = ValueType::from_le(&buffer[..mem::size_of::<__wasi_filetype_t>()])?; - let fs_flags = ValueType::from_le( - &buffer[mem::size_of::<__wasi_filetype_t>()..mem::size_of::<__wasi_fdflags_t>()], - )?; - let fs_rights_base = ValueType::from_le( - &buffer[(mem::size_of::<__wasi_filetype_t>() + mem::size_of::<__wasi_fdflags_t>()) - ..mem::size_of::<__wasi_rights_t>()], - )?; - let fs_rights_inheriting = ValueType::from_le( - &buffer[(mem::size_of::<__wasi_filetype_t>() - + mem::size_of::<__wasi_fdflags_t>() - + mem::size_of::<__wasi_rights_t>())..], - )?; - Ok(Self { - fs_filetype, - fs_flags, - fs_rights_base, - fs_rights_inheriting, - }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for __wasi_fdstat_t {} pub type __wasi_filedelta_t = i64; @@ -327,6 +221,8 @@ pub struct __wasi_filestat_t { pub st_ctim: __wasi_timestamp_t, } +unsafe impl ValueType for __wasi_filestat_t {} + pub type __wasi_filetype_t = u8; pub const __WASI_FILETYPE_UNKNOWN: u8 = 0; pub const __WASI_FILETYPE_BLOCK_DEVICE: u8 = 1; @@ -352,24 +248,7 @@ pub struct __wasi_iovec_t { pub buf_len: u32, } -impl ValueType for __wasi_iovec_t { - fn into_le(self, buffer: &mut [u8]) { - self.buf - .into_le(&mut buffer[..mem::size_of::>()]); - self.buf_len - .into_le(&mut buffer[mem::size_of::>()..]); - } - - fn from_le(buffer: &[u8]) -> Result { - if buffer.len() >= mem::size_of::<__wasi_iovec_t>() { - let buf = ValueType::from_le(&buffer[..mem::size_of::>()])?; - let buf_len = ValueType::from_le(&buffer[mem::size_of::>()..])?; - Ok(Self { buf, buf_len }) - } else { - Err(ValueError::BufferTooSmall) - } - } -} +unsafe impl ValueType for __wasi_iovec_t {} pub type __wasi_linkcount_t = u32; From 92ec71974bbc8278359cb472a172c86e6f69db41 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 1 Apr 2019 16:34:18 -0700 Subject: [PATCH 44/73] Add wasi_try macro --- lib/wasi/src/lib.rs | 2 + lib/wasi/src/macros.rs | 13 ++++ lib/wasi/src/ptr.rs | 18 ++++-- lib/wasi/src/state.rs | 18 +----- lib/wasi/src/syscalls/mod.rs | 111 +++++++++++++---------------------- 5 files changed, 72 insertions(+), 90 deletions(-) create mode 100644 lib/wasi/src/macros.rs diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index ba91b2aa637..c6908988c59 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,6 +1,8 @@ #[macro_use] extern crate log; +#[macro_use] +mod macros; mod ptr; mod state; mod syscalls; diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs new file mode 100644 index 00000000000..0e00e77b319 --- /dev/null +++ b/lib/wasi/src/macros.rs @@ -0,0 +1,13 @@ +macro_rules! wasi_try { + ($expr:expr) => {{ + let res: Result<_, crate::syscalls::types::__wasi_errno_t> = $expr; + match res { + Ok(val) => val, + Err(err) => return err, + } + }}; + ($expr:expr; $e:expr) => {{ + let opt: Option<_> = $expr; + wasi_try!(opt.ok_or($e)) + }}; +} diff --git a/lib/wasi/src/ptr.rs b/lib/wasi/src/ptr.rs index b4fc7a9a5cd..56abb3b2d1f 100644 --- a/lib/wasi/src/ptr.rs +++ b/lib/wasi/src/ptr.rs @@ -1,3 +1,4 @@ +use crate::syscalls::types::{__wasi_errno_t, __WASI_EFAULT}; use std::{cell::Cell, fmt, marker::PhantomData, mem}; use wasmer_runtime_core::{ memory::Memory, @@ -30,27 +31,32 @@ impl WasmPtr { impl WasmPtr { #[inline] - pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell> { + pub fn deref<'a>(self, memory: &'a Memory) -> Result<&'a Cell, __wasi_errno_t> { if (self.offset as usize) + mem::size_of::() >= memory.size().bytes().0 { - return None; + return Err(__WASI_EFAULT); } unsafe { let cell_ptr = memory .view::() .get_unchecked((self.offset() as usize) / mem::size_of::()) as *const _; - Some(&*cell_ptr) + Ok(&*cell_ptr) } } } impl WasmPtr { #[inline] - pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell]> { + pub fn deref<'a>( + self, + memory: &'a Memory, + index: u32, + length: u32, + ) -> Result<&'a [Cell], __wasi_errno_t> { if (self.offset as usize) + (mem::size_of::() * ((index + length) as usize)) >= memory.size().bytes().0 { - return None; + return Err(__WASI_EFAULT); } unsafe { @@ -59,7 +65,7 @@ impl WasmPtr { ..((self.offset() as usize) / mem::size_of::()) + ((index + length) as usize), ) as *const _; - Some(&*cell_ptrs) + Ok(&*cell_ptrs) } } } diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 3a243860b9a..d02ff5693fa 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -166,31 +166,19 @@ impl WasiFs { path: &str, ) -> Result<__wasi_filestat_t, __wasi_errno_t> { warn!("Should use preopned_fd: {}", preopened_fd); - let inode = if let Some(inode) = self.get_inode(path) { - inode - } else { - return Err(__WASI_EINVAL); - }; + let inode = self.get_inode(path).ok_or(__WASI_EINVAL)?; self.filestat_inode(inode, flags) } pub fn filestat_fd(&self, fd: __wasi_fd_t) -> Result<__wasi_filestat_t, __wasi_errno_t> { - let fd = if let Some(fd) = self.fd_map.get(&fd) { - fd - } else { - return Err(__WASI_EBADF); - }; + let fd = self.fd_map.get(&fd).ok_or(__WASI_EBADF)?; Ok(self.inodes[fd.inode].stat) } pub fn fdstat(&self, fd: __wasi_fd_t) -> Result<__wasi_fdstat_t, __wasi_errno_t> { - let fd = if let Some(fd) = self.fd_map.get(&fd) { - fd - } else { - return Err(__WASI_EBADF); - }; + let fd = self.fd_map.get(&fd).ok_or(__WASI_EBADF)?; Ok(__wasi_fdstat_t { fs_filetype: match self.inodes[fd.inode].kind { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index b04506c51d5..fcca2cf40a8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -31,23 +31,13 @@ fn write_buffer_array( ptr_buffer: WasmPtr, Array>, buffer: WasmPtr, ) -> __wasi_errno_t { - let ptrs = if let Some(cells) = ptr_buffer.deref(memory, 0, from.len() as u32) { - cells - } else { - return __WASI_EOVERFLOW; - }; + let ptrs = wasi_try!(ptr_buffer.deref(memory, 0, from.len() as u32)); let mut current_buffer_offset = 0; for ((i, sub_buffer), ptr) in from.iter().enumerate().zip(ptrs.iter()) { ptr.set(WasmPtr::new(buffer.offset() + current_buffer_offset)); - let cells = if let Some(cells) = - buffer.deref(memory, current_buffer_offset, sub_buffer.len() as u32) - { - cells - } else { - return __WASI_EOVERFLOW; - }; + let cells = wasi_try!(buffer.deref(memory, current_buffer_offset, sub_buffer.len() as u32)); for (cell, &byte) in cells.iter().zip(sub_buffer.iter()) { cell.set(byte); @@ -92,16 +82,15 @@ pub fn args_sizes_get( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let (Some(argc), Some(argv_buf_size)) = (argc.deref(memory), argv_buf_size.deref(memory)) { - let state = get_wasi_state(ctx); + let argc = wasi_try!(argc.deref(memory)); + let argv_buf_size = wasi_try!(argv_buf_size.deref(memory)); - argc.set(state.args.len() as u32); - argv_buf_size.set(state.args.iter().map(|v| v.len() as u32).sum()); + let state = get_wasi_state(ctx); - __WASI_ESUCCESS - } else { - __WASI_EOVERFLOW - } + argc.set(state.args.len() as u32); + argv_buf_size.set(state.args.iter().map(|v| v.len() as u32).sum()); + + __WASI_ESUCCESS } /// ### `clock_res_get()` @@ -119,11 +108,8 @@ pub fn clock_res_get( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let Some(out_addr) = resolution.deref(memory) { - platform_clock_res_get(clock_id, out_addr) - } else { - __WASI_EFAULT - } + let out_addr = wasi_try!(resolution.deref(memory)); + platform_clock_res_get(clock_id, out_addr) } /// ### `clock_time_get()` @@ -144,11 +130,8 @@ pub fn clock_time_get( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let Some(out_addr) = time.deref(memory) { - platform_clock_time_get(clock_id, precision, out_addr) - } else { - __WASI_EFAULT - } + let out_addr = wasi_try!(time.deref(memory)); + platform_clock_time_get(clock_id, precision, out_addr) } /// ### `environ_get()` @@ -184,18 +167,15 @@ pub fn environ_sizes_get( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let (Some(environ_count), Some(environ_buf_size)) = - (environ_count.deref(memory), environ_buf_size.deref(memory)) - { - let state = get_wasi_state(ctx); + let environ_count = wasi_try!(environ_count.deref(memory)); + let environ_buf_size = wasi_try!(environ_buf_size.deref(memory)); - environ_count.set(state.envs.len() as u32); - environ_buf_size.set(state.envs.iter().map(|v| v.len() as u32).sum()); + let state = get_wasi_state(ctx); - __WASI_ESUCCESS - } else { - __WASI_EOVERFLOW - } + environ_count.set(state.envs.len() as u32); + environ_buf_size.set(state.envs.iter().map(|v| v.len() as u32).sum()); + + __WASI_EOVERFLOW } /// ### `fd_advise()` @@ -282,17 +262,12 @@ pub fn fd_fdstat_get( let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); - let stat = match state.fs.fdstat(fd) { - Ok(stat) => stat, - Err(errno) => return errno, - }; + let stat = wasi_try!(state.fs.fdstat(fd)); - if let Some(buf) = buf.deref(memory) { - buf.set(stat); - __WASI_ESUCCESS - } else { - __WASI_EFAULT - } + let buf = wasi_try!(buf.deref(memory)); + buf.set(stat); + + __WASI_EFAULT } /// ### `fd_fdstat_set_flags()` @@ -344,17 +319,12 @@ pub fn fd_filestat_get( let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); - let stat = match state.fs.filestat_fd(fd) { - Ok(stat) => stat, - Err(errno) => return errno, - }; + let stat = wasi_try!(state.fs.filestat_fd(fd)); - if let Some(buf) = buf.deref(memory) { - buf.set(stat); - __WASI_ESUCCESS - } else { - __WASI_EFAULT - } + let buf = wasi_try!(buf.deref(memory)); + buf.set(stat); + + __WASI_ESUCCESS } pub fn fd_filestat_set_size( @@ -384,7 +354,7 @@ pub fn fd_pread( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let ((Some(iov_cells), Some(nread_cell))) = + if let ((Ok(iov_cells), Ok(nread_cell))) = (iovs.deref(memory, 0, iovs_len), nread.deref(memory)) { platform_fd_pread(fd, iov_cells, iovs_len, offset, nread_cell) @@ -400,7 +370,7 @@ pub fn fd_prestat_get( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let Some(prestat_ptr) = buf.deref(memory) { + if let Ok(prestat_ptr) = buf.deref(memory) { // open fd // write info to prestat_ptr __WASI_ESUCCESS @@ -417,7 +387,7 @@ pub fn fd_prestat_dir_name( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let Some(path_chars) = path.deref(memory, 0, path_len) { + if let Ok(path_chars) = path.deref(memory, 0, path_len) { if true /* check if dir */ { @@ -467,7 +437,7 @@ pub fn fd_read( // check __WASI_RIGHT_FD_READ - if let (Some(iovs_arr_cell), Some(nwritten_cell)) = + if let (Ok(iovs_arr_cell), Ok(nwritten_cell)) = (iovs.deref(memory, 0, iovs_len), nread.deref(memory)) { unimplemented!() @@ -501,7 +471,7 @@ pub fn fd_readdir( ) -> __wasi_errno_t { let memory = ctx.memory(0); - if let (Some(buf_arr_cell), Some(bufused_cell)) = + if let (Ok(buf_arr_cell), Ok(bufused_cell)) = (buf.deref(memory, 0, buf_len), bufused.deref(memory)) { unimplemented!() @@ -543,7 +513,7 @@ pub fn fd_seek( let memory = ctx.memory(0); // TODO: check __WASI_RIGHT_FD_SEEK // TODO: handle directory input - if let Some(new_offset_cell) = newoffset.deref(memory) { + if let Ok(new_offset_cell) = newoffset.deref(memory) { unimplemented!() } else { __WASI_EFAULT @@ -605,7 +575,7 @@ pub fn fd_write( let memory = ctx.memory(0); // TODO: check __WASI_RIGHT_FD_WRITE // return __WASI_EISDIR if dir (probably) - if let (Some(iovs_arr_cell), Some(nwritten_cell)) = + if let (Ok(iovs_arr_cell), Ok(nwritten_cell)) = (iovs.deref(memory, 0, iovs_len), nwritten.deref(memory)) { unimplemented!() @@ -659,6 +629,9 @@ pub fn path_filestat_get( path_len: u32, buf: WasmPtr<__wasi_filestat_t>, ) -> __wasi_errno_t { + let mut state = get_wasi_state(ctx); + let memory = ctx.memory(0); + // check __WASI_RIGHT_PATH_FILESTAT_GET unimplemented!() } @@ -768,7 +741,7 @@ pub fn path_open( // check for __WASI_RIGHT_PATH_OPEN somewhere, probably via dirfd - if let (Some(fd_cell), Some(path_cell)) = (fd.deref(memory), path.deref(memory, 0, path_len)) { + if let (Ok(fd_cell), Ok(path_cell)) = (fd.deref(memory), path.deref(memory, 0, path_len)) { // o_flags: // - __WASI_O_FLAG_CREAT (create if it does not exist) // - __WASI_O_DIRECTORY (fail if not dir) @@ -860,7 +833,7 @@ pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __was let mut rng = thread_rng(); let memory = ctx.memory(0); - if let Some(buf) = buf.deref(memory, 0, buf_len) { + if let Ok(buf) = buf.deref(memory, 0, buf_len) { for i in 0..(buf_len as usize) { let random_byte = rng.gen::(); buf[i].set(random_byte); From 2dd7ec8b72212838791aff3a02e3597834b575a2 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 1 Apr 2019 16:36:41 -0700 Subject: [PATCH 45/73] fix it up --- Cargo.lock | 88 +----------------------------------- lib/wasi/Cargo.toml | 6 ++- lib/wasi/src/state.rs | 8 ++-- lib/wasi/src/syscalls/mod.rs | 1 + 4 files changed, 11 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d34da510d23..8883ae32c36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,11 +121,6 @@ dependencies = [ "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "bitflags" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "bitflags" version = "1.0.4" @@ -557,18 +552,6 @@ dependencies = [ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "env_logger" -version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "env_logger" version = "0.6.1" @@ -717,14 +700,6 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "getopts" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "glob" version = "0.2.11" @@ -981,16 +956,6 @@ dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "lz4" -version = "1.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "lz4-sys 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "skeptic 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "lz4" version = "1.23.1" @@ -1000,15 +965,6 @@ dependencies = [ "lz4-sys 1.8.3 (git+https://github.com/zboxfs/lz4-rs.git)", ] -[[package]] -name = "lz4-sys" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "lz4-sys" version = "1.8.3" @@ -1347,15 +1303,6 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "pulldown-cmark" -version = "0.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "quick-error" version = "1.2.2" @@ -1781,15 +1728,6 @@ name = "siphasher" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "skeptic" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "slab" version = "0.4.2" @@ -2437,7 +2375,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", - "zbox 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "zbox 0.6.1 (git+https://github.com/wasmerio/zbox?branch=bundle-libsodium)", ] [[package]] @@ -2560,22 +2498,6 @@ dependencies = [ "tar 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "zbox" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lz4 1.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rmp-serde 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "zstd" version = "0.4.22+zstd.1.3.8" @@ -2619,7 +2541,6 @@ dependencies = [ "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f7f7f0701772b17de73e4f5cbcb1dd6926f4706cba4c1ab62c5367f8bdc94e1" -"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce2571a6cd634670daa2977cc894c1cc2ba57c563c498e5a82c35446f34d056e" "checksum blob 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19803aa44ff8b43123bbe369efaddcb638ea7dc332e543972dd95ac7cb148b92" @@ -2667,7 +2588,6 @@ dependencies = [ "checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" "checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed" "checksum enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7798e7da2d4cb0d6d6fc467e8d6b5bf247e9e989f786dde1732d79899c32bb10" -"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" @@ -2687,7 +2607,6 @@ dependencies = [ "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4024f96ffa0ebaaf36aa589cd41f2fd69f3a5e6fd02c86e11e12cdf41d5b46a3" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" -"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "84473a5302fa5094d3d9911c2f312f522f9a37462a777f195f63fae1bf7faf4d" "checksum h2 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "910a5e7be6283a9c91b3982fa5188368c8719cce2a3cf3b86048673bf9d9c36b" @@ -2716,9 +2635,7 @@ dependencies = [ "checksum llvm-sys 70.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60a9ee82fe0fa72ae6ef6d018b407296085863836451c7a97384f84ed7e26b9f" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" -"checksum lz4 1.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe55d2ebbc2e4fc987e6fbfc13f416d97b06d06e50bc1124d613aa790842f80c" "checksum lz4 1.23.1 (git+https://github.com/zboxfs/lz4-rs.git)" = "" -"checksum lz4-sys 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a59044c3ba3994f3d2aa2270ddd6c5947922219501e67efde5604d36aad462b5" "checksum lz4-sys 1.8.3 (git+https://github.com/zboxfs/lz4-rs.git)" = "" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" @@ -2757,7 +2674,6 @@ dependencies = [ "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1058d7bb927ca067656537eec4e02c2b4b70eaaa129664c5b90c111e20326f41" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" @@ -2805,7 +2721,6 @@ dependencies = [ "checksum serde_test 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "70807e147558b5253cb70f55d343db1d07204d773087c96d0f35fced295dba82" "checksum serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d48f9f99cd749a2de71d29da5f948de7f2764cc5a9d7f3c97e3514d4ee6eabf2" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" -"checksum skeptic 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd7d8dc1315094150052d0ab767840376335a98ac66ef313ff911cdf439a5b69" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -2875,7 +2790,6 @@ dependencies = [ "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" "checksum zbox 0.6.1 (git+https://github.com/wasmerio/zbox?branch=bundle-libsodium)" = "" -"checksum zbox 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4a969b504de4ee47ac68bbd035b0c5a53818edb1edd6737131de001de2a09e64" "checksum zstd 0.4.22+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6f042dd18d52854d302d3d92f66d0a63c2d520d7b7034a9d43cde7441d1b4ddd" "checksum zstd-safe 1.4.7+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "63febf0b0dcd076db81e6b3110ed254cfb8ed54378a4c3cfbb68956e839d4f59" "checksum zstd-sys 1.4.8+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4cb187d624025a7d9878ecf13437491869423426183ded2fa40d4651b85f7ae7" diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index da41195598f..c3b56c65c3f 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -11,6 +11,10 @@ rand = "0.6.5" # wasmer-runtime-abi = { path = "../runtime-abi" } hashbrown = "0.1.8" generational-arena = "0.2.2" -zbox = "0.6.1" log = "0.4.6" byteorder = "1.3.1" + +[target.'cfg(unix)'.dependencies.zbox] +git = "https://github.com/wasmerio/zbox" +branch = "bundle-libsodium" +features = ["libsodium-bundled"] \ No newline at end of file diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 3a243860b9a..df1c751b441 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -60,7 +60,7 @@ impl WasiFs { Ok(Self { repo: RepoOpener::new() .create(true) - .open("mem://📂", "very unsafe pwd") + .open("mem://not-an-emoji", "very unsafe pwd") .map_err(|e| e.to_string())?, name_map: HashMap::new(), inodes: Arena::new(), @@ -107,10 +107,10 @@ impl WasiFs { FileType::Dir => __WASI_FILETYPE_DIRECTORY, }, st_nlink: 0, - st_size: metadata.len() as u64, + st_size: metadata.content_len() as u64, st_atim: systime_to_nanos(SystemTime::now()), - st_mtim: systime_to_nanos(metadata.modified()), - st_ctim: systime_to_nanos(metadata.created()), + st_mtim: systime_to_nanos(metadata.modified_at()), + st_ctim: systime_to_nanos(metadata.created_at()), }, is_preopened: false, name: path.to_string(), diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index b04506c51d5..551bc4d6266 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -875,6 +875,7 @@ pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __was /// ### `sched_yield()` /// Yields execution of the thread pub fn sched_yield(ctx: &mut Ctx) -> __wasi_errno_t { + ::std::thread::yield_now(); __WASI_ESUCCESS } From d164c7a93b2016fdffee882072b2100451cc0d31 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 1 Apr 2019 17:21:48 -0700 Subject: [PATCH 46/73] update wasi Cargo.toml --- Cargo.lock | 4 ++-- lib/wasi/Cargo.toml | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8883ae32c36..b44432dce5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2209,7 +2209,7 @@ dependencies = [ "wasmer-runtime 0.2.1", "wasmer-runtime-abi 0.2.1", "wasmer-runtime-core 0.2.1", - "wasmer-wasi 0.1.0", + "wasmer-wasi 0.2.1", ] [[package]] @@ -2366,7 +2366,7 @@ dependencies = [ [[package]] name = "wasmer-wasi" -version = "0.1.0" +version = "0.2.1" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index c3b56c65c3f..cbb5652867f 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -1,7 +1,9 @@ [package] name = "wasmer-wasi" -version = "0.1.0" +version = "0.2.1" +license = "MIT" authors = ["The Wasmer Engineering Team "] +repository = "https://github.com/wasmerio/wasmer" edition = "2018" [dependencies] From 8bab9f1bea622532ab903591af41a40c4ad9d591 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 1 Apr 2019 17:25:45 -0700 Subject: [PATCH 47/73] init zbox first --- lib/wasi/src/state.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index ce4139e01fb..ae2ef12afe0 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -10,8 +10,9 @@ use std::{ ops::{Index, IndexMut}, rc::Rc, time::SystemTime, + path::PathBuf, }; -use zbox::{File, FileType, OpenOptions, Repo, RepoOpener}; +use zbox::{File, FileType, OpenOptions, Repo, RepoOpener, init_env as zbox_init_env}; pub const MAX_SYMLINKS: usize = 100; @@ -57,10 +58,11 @@ pub struct WasiFs { impl WasiFs { pub fn new() -> Result { + zbox_init_env(); Ok(Self { repo: RepoOpener::new() .create(true) - .open("mem://not-an-emoji", "very unsafe pwd") + .open("mem://foo", "") .map_err(|e| e.to_string())?, name_map: HashMap::new(), inodes: Arena::new(), From 287c81d7a51d8e06848a6f61af361b2a66a24dd6 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Mon, 1 Apr 2019 17:50:53 -0700 Subject: [PATCH 48/73] Misc fixes --- lib/runtime-core/src/error.rs | 29 ++++++++++++++++++++++++++--- lib/runtime-core/src/types.rs | 3 ++- lib/wasi/src/state.rs | 4 ++-- lib/wasi/src/syscalls/mod.rs | 16 +++++++--------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index 46fae102e62..090214834cf 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -119,7 +119,6 @@ impl std::error::Error for LinkError {} /// The main way to do this is `Instance.call`. /// /// Comparing two `RuntimeError`s always evaluates to false. -#[derive(Debug)] pub enum RuntimeError { Trap { msg: Box }, Exception { data: Box<[Value]> }, @@ -141,11 +140,27 @@ impl std::fmt::Display for RuntimeError { RuntimeError::Exception { ref data } => { write!(f, "Uncaught WebAssembly exception: {:?}", data) } - RuntimeError::Panic { data: _ } => write!(f, "User-defined \"panic\""), + RuntimeError::Panic { data } => { + let msg = if let Some(s) = data.downcast_ref::() { + s + } else if let Some(s) = data.downcast_ref::<&str>() { + s + } else { + "user-defined, opaque" + }; + + write!(f, "{}", msg) + } } } } +impl std::fmt::Debug for RuntimeError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", self) + } +} + impl std::error::Error for RuntimeError {} /// This error type is produced by resolving a wasm function @@ -197,7 +212,6 @@ impl std::error::Error for ResolveError {} /// be the `CallError::Runtime(RuntimeError)` variant. /// /// Comparing two `CallError`s always evaluates to false. -#[derive(Debug)] pub enum CallError { Resolve(ResolveError), Runtime(RuntimeError), @@ -218,6 +232,15 @@ impl std::fmt::Display for CallError { } } +impl std::fmt::Debug for CallError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + CallError::Resolve(resolve_err) => write!(f, "ResolveError: {:?}", resolve_err), + CallError::Runtime(runtime_err) => write!(f, "RuntimeError: {:?}", runtime_err), + } + } +} + impl std::error::Error for CallError {} /// This error type is produced when creating something, diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 7a51c1c6f80..933a7a5bd92 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -129,7 +129,8 @@ unsafe impl WasmExternType for f64 { pub unsafe trait ValueType: Copy where Self: Sized, -{} +{ +} macro_rules! convert_value_impl { ($t:ty) => { diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index ae2ef12afe0..49d8335b36a 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -8,11 +8,11 @@ use hashbrown::hash_map::{Entry, HashMap}; use std::{ cell::{Cell, RefCell}, ops::{Index, IndexMut}, + path::PathBuf, rc::Rc, time::SystemTime, - path::PathBuf, }; -use zbox::{File, FileType, OpenOptions, Repo, RepoOpener, init_env as zbox_init_env}; +use zbox::{init_env as zbox_init_env, File, FileType, OpenOptions, Repo, RepoOpener}; pub const MAX_SYMLINKS: usize = 100; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 1848563583c..76e77d81837 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -815,8 +815,8 @@ pub fn poll_oneoff( ) -> __wasi_errno_t { unimplemented!() } -pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) { - unimplemented!() +pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) -> Result<(), &'static str> { + Err("Instance exited") } pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t { unimplemented!() @@ -833,13 +833,11 @@ pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __was let mut rng = thread_rng(); let memory = ctx.memory(0); - if let Ok(buf) = buf.deref(memory, 0, buf_len) { - for i in 0..(buf_len as usize) { - let random_byte = rng.gen::(); - buf[i].set(random_byte); - } - } else { - return __WASI_EFAULT; + let buf = wasi_try!(buf.deref(memory, 0, buf_len)); + + unsafe { + let u8_buffer = &mut *(buf as *const [_] as *mut [_] as *mut [u8]); + thread_rng().fill(u8_buffer); } __WASI_ESUCCESS From 6cec356a742acf66247e278fb9731536b4864b58 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 09:47:45 -0700 Subject: [PATCH 49/73] add debug lines to all wasi syscalls --- lib/wasi/src/syscalls/mod.rs | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 76e77d81837..3d2dc5ee35e 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -62,6 +62,7 @@ pub fn args_get( argv: WasmPtr, Array>, argv_buf: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::args_get"); let state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -80,6 +81,7 @@ pub fn args_sizes_get( argc: WasmPtr, argv_buf_size: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::args_sizes_get"); let memory = ctx.memory(0); let argc = wasi_try!(argc.deref(memory)); @@ -106,6 +108,7 @@ pub fn clock_res_get( clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t>, ) -> __wasi_errno_t { + debug!("wasi::clock_res_get"); let memory = ctx.memory(0); let out_addr = wasi_try!(resolution.deref(memory)); @@ -128,6 +131,7 @@ pub fn clock_time_get( precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t>, ) -> __wasi_errno_t { + debug!("wasi::clock_time_get"); let memory = ctx.memory(0); let out_addr = wasi_try!(time.deref(memory)); @@ -147,6 +151,7 @@ pub fn environ_get( environ: WasmPtr, Array>, environ_buf: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::environ_get"); let state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -165,6 +170,7 @@ pub fn environ_sizes_get( environ_count: WasmPtr, environ_buf_size: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::environ_sizes_get"); let memory = ctx.memory(0); let environ_count = wasi_try!(environ_count.deref(memory)); @@ -196,6 +202,7 @@ pub fn fd_advise( len: __wasi_filesize_t, advice: __wasi_advice_t, ) -> __wasi_errno_t { + debug!("wasi::fd_advise"); unimplemented!() } @@ -214,6 +221,7 @@ pub fn fd_allocate( offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> __wasi_errno_t { + debug!("wasi::fd_allocate"); unimplemented!() } @@ -228,6 +236,7 @@ pub fn fd_allocate( /// - `__WASI_EBADF` /// If `fd` is invalid or not open (TODO: consider __WASI_EINVAL) pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { + debug!("wasi::fd_close"); // FD is too large return __WASI_EMFILE; // FD is a directory (due to user input) @@ -243,6 +252,7 @@ pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { /// - `__wasi_fd_t fd` /// The file descriptor to sync pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { + debug!("wasi::fd_datasync"); unimplemented!() } @@ -259,6 +269,7 @@ pub fn fd_fdstat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_fdstat_t>, ) -> __wasi_errno_t { + debug!("wasi::fd_fdstat_get"); let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -282,6 +293,7 @@ pub fn fd_fdstat_set_flags( fd: __wasi_fd_t, flags: __wasi_fdflags_t, ) -> __wasi_errno_t { + debug!("wasi::fd_fdstat_set_flags"); unimplemented!() } @@ -300,6 +312,7 @@ pub fn fd_fdstat_set_rights( fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, ) -> __wasi_errno_t { + debug!("wasi::fd_fdstat_set_rights"); unimplemented!() } @@ -316,6 +329,7 @@ pub fn fd_filestat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t>, ) -> __wasi_errno_t { + debug!("wasi::fd_filestat_get"); let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -332,6 +346,7 @@ pub fn fd_filestat_set_size( fd: __wasi_fd_t, st_size: __wasi_filesize_t, ) -> __wasi_errno_t { + debug!("wasi::fd_filestat_set_size"); unimplemented!() } pub fn fd_filestat_set_times( @@ -341,6 +356,7 @@ pub fn fd_filestat_set_times( st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { + debug!("wasi::fd_filestat_set_times"); unimplemented!() } @@ -352,6 +368,7 @@ pub fn fd_pread( offset: __wasi_filesize_t, nread: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::fd_pread"); let memory = ctx.memory(0); if let ((Ok(iov_cells), Ok(nread_cell))) = @@ -368,6 +385,7 @@ pub fn fd_prestat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t>, ) -> __wasi_errno_t { + debug!("wasi::fd_prestat_get"); let memory = ctx.memory(0); if let Ok(prestat_ptr) = buf.deref(memory) { @@ -385,6 +403,7 @@ pub fn fd_prestat_dir_name( path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::fd_prestat_dir_name"); let memory = ctx.memory(0); if let Ok(path_chars) = path.deref(memory, 0, path_len) { @@ -411,6 +430,7 @@ pub fn fd_pwrite( offset: __wasi_filesize_t, nwritten: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::fd_pwrite"); unimplemented!() } @@ -433,6 +453,7 @@ pub fn fd_read( iovs_len: u32, nread: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::fd_read"); let memory = ctx.memory(0); // check __WASI_RIGHT_FD_READ @@ -469,6 +490,7 @@ pub fn fd_readdir( cookie: __wasi_dircookie_t, bufused: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::fd_readdir"); let memory = ctx.memory(0); if let (Ok(buf_arr_cell), Ok(bufused_cell)) = @@ -488,6 +510,7 @@ pub fn fd_readdir( /// - `__wasi_fd_t to` /// Location to copy file descriptor to pub fn fd_renumber(ctx: &mut Ctx, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { + debug!("wasi::fd_renumber"); unimplemented!() } @@ -510,6 +533,7 @@ pub fn fd_seek( whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t>, ) -> __wasi_errno_t { + debug!("wasi::fd_seek"); let memory = ctx.memory(0); // TODO: check __WASI_RIGHT_FD_SEEK // TODO: handle directory input @@ -530,6 +554,7 @@ pub fn fd_seek( /// - `__WASI_EPERM` /// - `__WAIS_ENOTCAPABLE` pub fn fd_sync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { + debug!("wasi::fd_sync"); // TODO: check __WASI_RIGHT_FD_SYNC unimplemented!() } @@ -547,6 +572,7 @@ pub fn fd_tell( fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t>, ) -> __wasi_errno_t { + debug!("wasi::fd_tell"); // TODO: check __WASI_RIGHT_FD_TELL unimplemented!() } @@ -572,6 +598,7 @@ pub fn fd_write( iovs_len: u32, nwritten: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::fd_write"); let memory = ctx.memory(0); // TODO: check __WASI_RIGHT_FD_WRITE // return __WASI_EISDIR if dir (probably) @@ -603,6 +630,7 @@ pub fn path_create_directory( path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::path_create_directory"); // check __WASI_RIGHT_PATH_CREATE_DIRECTORY unimplemented!() } @@ -629,6 +657,7 @@ pub fn path_filestat_get( path_len: u32, buf: WasmPtr<__wasi_filestat_t>, ) -> __wasi_errno_t { + debug!("wasi::path_filestat_get"); let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -663,6 +692,7 @@ pub fn path_filestat_set_times( st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { + debug!("wasi::path_filestat_set_times"); unimplemented!() } @@ -693,6 +723,7 @@ pub fn path_link( new_path: WasmPtr, new_path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::path_link"); unimplemented!() } @@ -732,6 +763,7 @@ pub fn path_open( fs_flags: __wasi_fdflags_t, fd: WasmPtr<__wasi_fd_t>, ) -> __wasi_errno_t { + debug!("wasi::path_open"); let memory = ctx.memory(0); if path_len > 1024 /* TODO: find actual upper bound on name size (also this is a path, not a name :think-fish:) */ @@ -767,6 +799,7 @@ pub fn path_readlink( buf_len: u32, bufused: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::path_readlink"); unimplemented!() } pub fn path_remove_directory( @@ -775,6 +808,7 @@ pub fn path_remove_directory( path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::path_remove_directory"); unimplemented!() } pub fn path_rename( @@ -786,6 +820,7 @@ pub fn path_rename( new_path: WasmPtr, new_path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::path_rename"); unimplemented!() } pub fn path_symlink( @@ -796,6 +831,7 @@ pub fn path_symlink( new_path: WasmPtr, new_path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::path_symlink"); unimplemented!() } pub fn path_unlink_file( @@ -804,6 +840,7 @@ pub fn path_unlink_file( path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { + debug!("wasi::path_unlink_file"); unimplemented!() } pub fn poll_oneoff( @@ -813,12 +850,15 @@ pub fn poll_oneoff( nsubscriptions: u32, nevents: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::poll_oneoff"); unimplemented!() } pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) -> Result<(), &'static str> { + debug!("wasi::proc_exit"); Err("Instance exited") } pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t { + debug!("wasi::proc_raise"); unimplemented!() } @@ -830,6 +870,7 @@ pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t { /// - `size_t buf_len` /// The number of bytes that will be written pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __wasi_errno_t { + debug!("wasi::random_get"); let mut rng = thread_rng(); let memory = ctx.memory(0); @@ -846,6 +887,7 @@ pub fn random_get(ctx: &mut Ctx, buf: WasmPtr, buf_len: u32) -> __was /// ### `sched_yield()` /// Yields execution of the thread pub fn sched_yield(ctx: &mut Ctx) -> __wasi_errno_t { + debug!("wasi::sched_yield"); ::std::thread::yield_now(); __WASI_ESUCCESS } @@ -859,6 +901,7 @@ pub fn sock_recv( ro_datalen: WasmPtr, ro_flags: WasmPtr<__wasi_roflags_t>, ) -> __wasi_errno_t { + debug!("wasi::sock_recv"); unimplemented!() } pub fn sock_send( @@ -869,8 +912,10 @@ pub fn sock_send( si_flags: __wasi_siflags_t, so_datalen: WasmPtr, ) -> __wasi_errno_t { + debug!("wasi::sock_send"); unimplemented!() } pub fn sock_shutdown(ctx: &mut Ctx, sock: __wasi_fd_t, how: __wasi_sdflags_t) -> __wasi_errno_t { + debug!("wasi::sock_shutdown"); unimplemented!() } From 435629300ba7e047dd799b1b192bd17b2d59ed18 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 10:22:45 -0700 Subject: [PATCH 50/73] get debug statements working; add some extra info --- lib/wasi/src/lib.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index c6908988c59..5183dc511e1 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -15,7 +15,7 @@ use std::ffi::c_void; pub use self::utils::is_wasi_module; -use wasmer_runtime_core::{func, import::ImportObject, imports}; +use wasmer_runtime_core::{debug, func, import::ImportObject, imports}; pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportObject { let state_gen = move || { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 3d2dc5ee35e..1a6a1d45eba 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -11,7 +11,7 @@ use crate::{ state::WasiState, }; use rand::{thread_rng, Rng}; -use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +use wasmer_runtime_core::{debug, memory::Memory, vm::Ctx}; #[cfg(any(target_os = "linux", target_os = "macos"))] pub use unix::*; @@ -269,7 +269,7 @@ pub fn fd_fdstat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_fdstat_t>, ) -> __wasi_errno_t { - debug!("wasi::fd_fdstat_get"); + debug!("wasi::fd_fdstat_get: fd={}", fd); let mut state = get_wasi_state(ctx); let memory = ctx.memory(0); @@ -385,7 +385,7 @@ pub fn fd_prestat_get( fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t>, ) -> __wasi_errno_t { - debug!("wasi::fd_prestat_get"); + debug!("wasi::fd_prestat_get: fd={}", fd); let memory = ctx.memory(0); if let Ok(prestat_ptr) = buf.deref(memory) { @@ -403,10 +403,20 @@ pub fn fd_prestat_dir_name( path: WasmPtr, path_len: u32, ) -> __wasi_errno_t { - debug!("wasi::fd_prestat_dir_name"); + debug!( + "wasi::fd_prestat_dir_name: fd={}, path_len={}", + fd, path_len + ); let memory = ctx.memory(0); if let Ok(path_chars) = path.deref(memory, 0, path_len) { + debug!( + "=> path: {}", + path_chars + .iter() + .map(|c| c.get() as char) + .collect::() + ); if true /* check if dir */ { @@ -854,7 +864,7 @@ pub fn poll_oneoff( unimplemented!() } pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) -> Result<(), &'static str> { - debug!("wasi::proc_exit"); + debug!("wasi::proc_exit, {}", rval); Err("Instance exited") } pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t { From d421e91407270dcf2c0647ebd5e82456a77fc91a Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 10:58:22 -0700 Subject: [PATCH 51/73] implement some of fd_prestat_get --- lib/wasi/src/lib.rs | 2 +- lib/wasi/src/state.rs | 15 +++++++++++++++ lib/wasi/src/syscalls/mod.rs | 21 ++++++++++++++------- lib/wasi/src/syscalls/types.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 5183dc511e1..c6908988c59 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -15,7 +15,7 @@ use std::ffi::c_void; pub use self::utils::is_wasi_module; -use wasmer_runtime_core::{debug, func, import::ImportObject, imports}; +use wasmer_runtime_core::{func, import::ImportObject, imports}; pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportObject { let state_gen = move || { diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 49d8335b36a..2f7cb8ef5f1 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -194,6 +194,21 @@ impl WasiFs { fs_rights_inheriting: fd.rights, // TODO(lachlan): Is this right? }) } + + pub fn prestat_fd(&self, fd: __wasi_fd_t) -> Result<__wasi_prestat_t, __wasi_errno_t> { + let fd = self.fd_map.get(&fd).ok_or(__WASI_EBADF)?; + + let inode_val = &self.inodes[fd.inode]; + + if inode_val.is_preopened { + Ok(PrestatEnum::PreOpenDir { + pr_name_len: inode_val.name.len() as u32, + } + .get_untagged()) + } else { + Err(__WASI_EBADF) + } + } } pub struct WasiState<'a> { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 1a6a1d45eba..4e86d4d12b7 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -380,6 +380,14 @@ pub fn fd_pread( } } +/// ### `fd_prestat_get()` +/// Get metadata about a preopened file descriptor +/// Input: +/// - `__wasi_fd_t fd` +/// The preopened file descriptor to query +/// Output: +/// - `__wasi_prestat *buf` +/// Where the metadata will be written pub fn fd_prestat_get( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -388,13 +396,12 @@ pub fn fd_prestat_get( debug!("wasi::fd_prestat_get: fd={}", fd); let memory = ctx.memory(0); - if let Ok(prestat_ptr) = buf.deref(memory) { - // open fd - // write info to prestat_ptr - __WASI_ESUCCESS - } else { - __WASI_EFAULT - } + let prestat_ptr = wasi_try!(buf.deref(memory)); + + let state = get_wasi_state(ctx); + prestat_ptr.set(wasi_try!(state.fs.prestat_fd(fd))); + + __WASI_ESUCCESS } pub fn fd_prestat_dir_name( diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 17098aacf0c..15772067527 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -191,6 +191,37 @@ pub struct __wasi_prestat_t { u: __wasi_prestat_u, } +#[derive(Copy, Clone)] +pub enum PrestatEnum { + PreOpenDir { pr_name_len: u32 }, +} + +impl __wasi_prestat_t { + pub fn get_tagged(&self) -> PrestatEnum { + match self.pr_type { + __WASI_PREOPENTYPE_DIR => PrestatEnum::PreOpenDir { + pr_name_len: unsafe { self.u.dir.pr_name_len }, + }, + _ => panic!("Invalid enum variant in __wasi_prestat_t: {}", self.pr_type), + } + } +} + +impl PrestatEnum { + pub fn get_untagged(&self) -> __wasi_prestat_t { + match self { + PrestatEnum::PreOpenDir { pr_name_len } => __wasi_prestat_t { + pr_type: __WASI_PREOPENTYPE_DIR, + u: __wasi_prestat_u { + dir: __wasi_prestat_u_dir_t { + pr_name_len: *pr_name_len, + }, + }, + }, + } + } +} + unsafe impl ValueType for __wasi_prestat_t {} #[derive(Debug, Copy, Clone, PartialEq, Eq)] From 242f9f679d8bf7e84f5d178bf3913e3f8f95bf81 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 11:43:04 -0700 Subject: [PATCH 52/73] add hacked together impl of write for stdout and stderr --- lib/wasi/src/syscalls/mod.rs | 53 ++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 4e86d4d12b7..20586a92459 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -11,6 +11,7 @@ use crate::{ state::WasiState, }; use rand::{thread_rng, Rng}; +use std::io::{self, Write}; use wasmer_runtime_core::{debug, memory::Memory, vm::Ctx}; #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -181,7 +182,7 @@ pub fn environ_sizes_get( environ_count.set(state.envs.len() as u32); environ_buf_size.set(state.envs.iter().map(|v| v.len() as u32).sum()); - __WASI_EOVERFLOW + __WASI_ESUCCESS } /// ### `fd_advise()` @@ -615,17 +616,53 @@ pub fn fd_write( iovs_len: u32, nwritten: WasmPtr, ) -> __wasi_errno_t { - debug!("wasi::fd_write"); + debug!("wasi::fd_write: fd={}", fd); let memory = ctx.memory(0); // TODO: check __WASI_RIGHT_FD_WRITE // return __WASI_EISDIR if dir (probably) - if let (Ok(iovs_arr_cell), Ok(nwritten_cell)) = - (iovs.deref(memory, 0, iovs_len), nwritten.deref(memory)) - { - unimplemented!() - } else { - __WASI_EFAULT + let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); + let nwritten_cell = wasi_try!(nwritten.deref(memory)); + let mut bytes_written = 0; + + match fd { + 0 => unimplemented!(), + 1 => { + let stdout = io::stdout(); + let mut handle = stdout.lock(); + + for iov in iovs_arr_cell { + let iov_inner = iov.get(); + let bytes = wasi_try!(iov_inner.buf.deref(memory, 0, iov_inner.buf_len)); + wasi_try!(handle + .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) + .map_err(|_| __WASI_EIO)); + + // TODO: handle failure more accurately + bytes_written += iov_inner.buf_len; + } + } + 2 => { + let stderr = io::stderr(); + let mut handle = stderr.lock(); + + // TODO: abstract this + for iov in iovs_arr_cell { + let iov_inner = iov.get(); + let bytes = wasi_try!(iov_inner.buf.deref(memory, 0, iov_inner.buf_len)); + wasi_try!(handle + .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) + .map_err(|_| __WASI_EIO)); + + // TODO: handle failure more accurately + bytes_written += iov_inner.buf_len; + } + } + other => unimplemented!(), } + + nwritten_cell.set(bytes_written); + + __WASI_ESUCCESS } /// ### `path_create_directory()` From 3a6e2c9c37fdc8cd06a314c399805daf968da6a8 Mon Sep 17 00:00:00 2001 From: Lachlan Sneff Date: Tue, 2 Apr 2019 11:49:05 -0700 Subject: [PATCH 53/73] Change tagged and untagged methods --- lib/wasi/src/state.rs | 11 +++-- lib/wasi/src/syscalls/types.rs | 86 +++++++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 25 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 2f7cb8ef5f1..6fda1b8a3b8 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -201,10 +201,13 @@ impl WasiFs { let inode_val = &self.inodes[fd.inode]; if inode_val.is_preopened { - Ok(PrestatEnum::PreOpenDir { - pr_name_len: inode_val.name.len() as u32, - } - .get_untagged()) + Ok(__wasi_prestat_t { + pr_type: __WASI_PREOPENTYPE_DIR, + u: PrestatEnum::Dir { + pr_name_len: inode_val.name.len() as u32, + } + .untagged(), + }) } else { Err(__WASI_EBADF) } diff --git a/lib/wasi/src/syscalls/types.rs b/lib/wasi/src/syscalls/types.rs index 15772067527..b6f7bada2d2 100644 --- a/lib/wasi/src/syscalls/types.rs +++ b/lib/wasi/src/syscalls/types.rs @@ -134,6 +134,24 @@ pub union __wasi_event_u { fd_readwrite: __wasi_event_fd_readwrite_t, } +#[derive(Copy, Clone)] +pub enum EventEnum { + FdReadWrite { + nbytes: __wasi_filesize_t, + flags: __wasi_eventrwflags_t, + }, +} + +impl EventEnum { + pub fn untagged(self) -> __wasi_event_u { + match self { + EventEnum::FdReadWrite { nbytes, flags } => __wasi_event_u { + fd_readwrite: __wasi_event_fd_readwrite_t { nbytes, flags }, + }, + } + } +} + #[derive(Copy, Clone)] #[repr(C)] pub struct __wasi_event_t { @@ -143,6 +161,18 @@ pub struct __wasi_event_t { pub u: __wasi_event_u, } +impl __wasi_event_t { + pub fn tagged(&self) -> Option { + match self.type_ { + __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => Some(EventEnum::FdReadWrite { + nbytes: unsafe { self.u.fd_readwrite.nbytes }, + flags: unsafe { self.u.fd_readwrite.flags }, + }), + _ => None, + } + } +} + pub type __wasi_eventrwflags_t = u16; pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 1 << 0; @@ -171,7 +201,7 @@ pub const __WASI_PREOPENTYPE_DIR: u8 = 0; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(C)] pub struct __wasi_prestat_u_dir_t { - pr_name_len: u32, + pub pr_name_len: u32, } unsafe impl ValueType for __wasi_prestat_u_dir_t {} @@ -187,37 +217,32 @@ unsafe impl ValueType for __wasi_prestat_u {} #[derive(Copy, Clone)] #[repr(C)] pub struct __wasi_prestat_t { - pr_type: __wasi_preopentype_t, - u: __wasi_prestat_u, + pub pr_type: __wasi_preopentype_t, + pub u: __wasi_prestat_u, } #[derive(Copy, Clone)] pub enum PrestatEnum { - PreOpenDir { pr_name_len: u32 }, + Dir { pr_name_len: u32 }, } -impl __wasi_prestat_t { - pub fn get_tagged(&self) -> PrestatEnum { - match self.pr_type { - __WASI_PREOPENTYPE_DIR => PrestatEnum::PreOpenDir { - pr_name_len: unsafe { self.u.dir.pr_name_len }, +impl PrestatEnum { + pub fn untagged(self) -> __wasi_prestat_u { + match self { + PrestatEnum::Dir { pr_name_len } => __wasi_prestat_u { + dir: __wasi_prestat_u_dir_t { pr_name_len }, }, - _ => panic!("Invalid enum variant in __wasi_prestat_t: {}", self.pr_type), } } } -impl PrestatEnum { - pub fn get_untagged(&self) -> __wasi_prestat_t { - match self { - PrestatEnum::PreOpenDir { pr_name_len } => __wasi_prestat_t { - pr_type: __WASI_PREOPENTYPE_DIR, - u: __wasi_prestat_u { - dir: __wasi_prestat_u_dir_t { - pr_name_len: *pr_name_len, - }, - }, - }, +impl __wasi_prestat_t { + pub fn tagged(&self) -> Option { + match self.pr_type { + __WASI_PREOPENTYPE_DIR => Some(PrestatEnum::Dir { + pr_name_len: unsafe { self.u.dir.pr_name_len }, + }), + _ => None, } } } @@ -398,6 +423,25 @@ pub struct __wasi_subscription_t { pub u: __wasi_subscription_u, } +pub enum SubscriptionEnum { + Clock(__wasi_subscription_clock_t), + FdReadWrite(__wasi_subscription_fs_readwrite_t), +} + +impl __wasi_subscription_t { + pub fn tagged(&self) -> Option { + match self.type_ { + __WASI_EVENTTYPE_CLOCK => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })), + __WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => { + Some(SubscriptionEnum::FdReadWrite(unsafe { + self.u.fd_readwrite + })) + } + _ => None, + } + } +} + pub type __wasi_timestamp_t = u64; pub type __wasi_userdata_t = u64; From 6278ced7fc596e66b07fc2836d9efb795e18cc31 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 12:06:35 -0700 Subject: [PATCH 54/73] implement fd_write for files --- lib/wasi/src/state.rs | 28 +++++++------- lib/wasi/src/syscalls/mod.rs | 72 +++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 2f7cb8ef5f1..367c948f6f5 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -17,10 +17,10 @@ use zbox::{init_env as zbox_init_env, File, FileType, OpenOptions, Repo, RepoOpe pub const MAX_SYMLINKS: usize = 100; pub struct InodeVal { - stat: __wasi_filestat_t, - is_preopened: bool, - name: String, - kind: Kind, + pub stat: __wasi_filestat_t, + pub is_preopened: bool, + pub name: String, + pub kind: Kind, } pub enum Kind { @@ -41,19 +41,19 @@ pub enum Kind { } pub struct Fd { - rights: __wasi_rights_t, - flags: __wasi_fdflags_t, - offset: u64, - inode: Inode, + pub rights: __wasi_rights_t, + pub flags: __wasi_fdflags_t, + pub offset: u64, + pub inode: Inode, } pub struct WasiFs { - repo: Repo, - name_map: HashMap, - inodes: Arena, - fd_map: HashMap, - next_fd: Cell, - inode_counter: Cell, + pub repo: Repo, + pub name_map: HashMap, + pub inodes: Arena, + pub fd_map: HashMap, + pub next_fd: Cell, + pub inode_counter: Cell, } impl WasiFs { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 20586a92459..f347a85cbcc 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -8,9 +8,10 @@ pub mod windows; use self::types::*; use crate::{ ptr::{Array, WasmPtr}, - state::WasiState, + state::{Kind, WasiState}, }; use rand::{thread_rng, Rng}; +use std::cell::Cell; use std::io::{self, Write}; use wasmer_runtime_core::{debug, memory::Memory, vm::Ctx}; @@ -619,46 +620,65 @@ pub fn fd_write( debug!("wasi::fd_write: fd={}", fd); let memory = ctx.memory(0); // TODO: check __WASI_RIGHT_FD_WRITE - // return __WASI_EISDIR if dir (probably) let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); let nwritten_cell = wasi_try!(nwritten.deref(memory)); - let mut bytes_written = 0; - match fd { - 0 => unimplemented!(), + fn write_bytes( + mut write_loc: T, + memory: &Memory, + iovs_arr_cell: &[Cell<__wasi_ciovec_t>], + ) -> Result { + let mut bytes_written = 0; + for iov in iovs_arr_cell { + let iov_inner = iov.get(); + let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?; + write_loc + .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) + .map_err(|_| __WASI_EIO)?; + + // TODO: handle failure more accurately + bytes_written += iov_inner.buf_len; + } + Ok(bytes_written) + } + + let bytes_written = match fd { + 0 => return __WASI_EINVAL, 1 => { let stdout = io::stdout(); let mut handle = stdout.lock(); - for iov in iovs_arr_cell { - let iov_inner = iov.get(); - let bytes = wasi_try!(iov_inner.buf.deref(memory, 0, iov_inner.buf_len)); - wasi_try!(handle - .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) - .map_err(|_| __WASI_EIO)); - - // TODO: handle failure more accurately - bytes_written += iov_inner.buf_len; - } + wasi_try!(write_bytes(handle, memory, iovs_arr_cell)) } + 2 => { let stderr = io::stderr(); let mut handle = stderr.lock(); - // TODO: abstract this - for iov in iovs_arr_cell { - let iov_inner = iov.get(); - let bytes = wasi_try!(iov_inner.buf.deref(memory, 0, iov_inner.buf_len)); - wasi_try!(handle - .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) - .map_err(|_| __WASI_EIO)); + wasi_try!(write_bytes(handle, memory, iovs_arr_cell)) + } + _ => { + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF)); - // TODO: handle failure more accurately - bytes_written += iov_inner.buf_len; + if fd_entry.rights & __WASI_RIGHT_FD_WRITE == 0 { + // TODO: figure out the error to return when lacking rights + return __WASI_EACCES; + } + + let inode = &mut state.fs.inodes[fd_entry.inode]; + + match &mut inode.kind { + Kind::File { handle } => wasi_try!(write_bytes(handle, memory, iovs_arr_cell)), + Kind::Dir { .. } => { + // TODO: verify + return __WASI_EISDIR; + } + Kind::Symlink { .. } => unimplemented!(), + Kind::Buffer { buffer } => wasi_try!(write_bytes(buffer, memory, iovs_arr_cell)), } } - other => unimplemented!(), - } + }; nwritten_cell.set(bytes_written); From a4547e36e29d43c66d301493f1f37a465f896587 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 12:11:05 -0700 Subject: [PATCH 55/73] update cursor in file when writing to it --- lib/wasi/src/syscalls/mod.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index f347a85cbcc..76097436e44 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -619,7 +619,6 @@ pub fn fd_write( ) -> __wasi_errno_t { debug!("wasi::fd_write: fd={}", fd); let memory = ctx.memory(0); - // TODO: check __WASI_RIGHT_FD_WRITE let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); let nwritten_cell = wasi_try!(nwritten.deref(memory)); @@ -659,24 +658,31 @@ pub fn fd_write( } _ => { let state = get_wasi_state(ctx); - let fd_entry = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF)); + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); if fd_entry.rights & __WASI_RIGHT_FD_WRITE == 0 { // TODO: figure out the error to return when lacking rights return __WASI_EACCES; } + let offset = fd_entry.offset as usize; let inode = &mut state.fs.inodes[fd_entry.inode]; - match &mut inode.kind { + let bytes_written = match &mut inode.kind { Kind::File { handle } => wasi_try!(write_bytes(handle, memory, iovs_arr_cell)), Kind::Dir { .. } => { // TODO: verify return __WASI_EISDIR; } Kind::Symlink { .. } => unimplemented!(), - Kind::Buffer { buffer } => wasi_try!(write_bytes(buffer, memory, iovs_arr_cell)), - } + Kind::Buffer { buffer } => { + wasi_try!(write_bytes(&mut buffer[offset..], memory, iovs_arr_cell)) + } + }; + + fd_entry.offset += bytes_written as u64; + + bytes_written } }; From 0b9fc5ab457369320426859ed50992396315e464 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 14:13:03 -0700 Subject: [PATCH 56/73] add null termination to args for wasi --- lib/wasi/src/syscalls/mod.rs | 39 +++++++++++++++++++++++++----------- src/bin/wasmer.rs | 4 ++-- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 76097436e44..c9ef0b5521f 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -39,12 +39,13 @@ fn write_buffer_array( for ((i, sub_buffer), ptr) in from.iter().enumerate().zip(ptrs.iter()) { ptr.set(WasmPtr::new(buffer.offset() + current_buffer_offset)); - let cells = wasi_try!(buffer.deref(memory, current_buffer_offset, sub_buffer.len() as u32)); + let cells = + wasi_try!(buffer.deref(memory, current_buffer_offset, sub_buffer.len() as u32 + 1)); - for (cell, &byte) in cells.iter().zip(sub_buffer.iter()) { + for (cell, &byte) in cells.iter().zip(sub_buffer.iter().chain([0].iter())) { cell.set(byte); } - current_buffer_offset += sub_buffer.len() as u32; + current_buffer_offset += sub_buffer.len() as u32 + 1; } __WASI_ESUCCESS @@ -92,7 +93,7 @@ pub fn args_sizes_get( let state = get_wasi_state(ctx); argc.set(state.args.len() as u32); - argv_buf_size.set(state.args.iter().map(|v| v.len() as u32).sum()); + argv_buf_size.set(state.args.iter().map(|v| v.len() as u32 + 1).sum()); __WASI_ESUCCESS } @@ -472,18 +473,32 @@ pub fn fd_read( iovs_len: u32, nread: WasmPtr, ) -> __wasi_errno_t { - debug!("wasi::fd_read"); + debug!("wasi::fd_read: fd={}", fd); let memory = ctx.memory(0); + let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); + let nwritten_cell = wasi_try!(nread.deref(memory)); // check __WASI_RIGHT_FD_READ - if let (Ok(iovs_arr_cell), Ok(nwritten_cell)) = - (iovs.deref(memory, 0, iovs_len), nread.deref(memory)) - { - unimplemented!() - } else { - __WASI_EFAULT - } + /*fn read_bytes( + mut reader: T, + memory: &Memory, + iovs_arr_cell: &[Cell<__wasi_iovec_t>], + ) -> Result { + let mut bytes_read = 0; + + for iov in iovs_arr_cell { + let iov_inner = iov.get(); + let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?; + let raw_bytes = unsafe { bytes as &mut [u8]}; + reader.read(raw_bytes) + + // TODO: handle failure more accurately + bytes_written += iov_inner.buf_len; + } + Ok(bytes_written) + }*/ + __WASI_ESUCCESS } /// ### `fd_readdir()` diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index ceb6604d634..4b17f50eff4 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -224,9 +224,9 @@ fn execute_wasm(options: &Run) -> Result<(), String> { ( InstanceABI::WASI, wasmer_wasi::generate_import_object( - options - .args + [options.path.to_str().unwrap().to_owned()] .iter() + .chain(options.args.iter()) .cloned() .map(|arg| arg.into_bytes()) .collect(), From e61c03a17648de70febe809c260d75f22418fe00 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 15:14:19 -0700 Subject: [PATCH 57/73] impl fd_read (untested) --- lib/wasi/src/syscalls/mod.rs | 58 +++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index c9ef0b5521f..7db14045337 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -12,7 +12,7 @@ use crate::{ }; use rand::{thread_rng, Rng}; use std::cell::Cell; -use std::io::{self, Write}; +use std::io::{self, Read, Write}; use wasmer_runtime_core::{debug, memory::Memory, vm::Ctx}; #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -477,10 +477,9 @@ pub fn fd_read( let memory = ctx.memory(0); let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); - let nwritten_cell = wasi_try!(nread.deref(memory)); - // check __WASI_RIGHT_FD_READ + let nread_cell = wasi_try!(nread.deref(memory)); - /*fn read_bytes( + fn read_bytes( mut reader: T, memory: &Memory, iovs_arr_cell: &[Cell<__wasi_iovec_t>], @@ -490,14 +489,53 @@ pub fn fd_read( for iov in iovs_arr_cell { let iov_inner = iov.get(); let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?; - let raw_bytes = unsafe { bytes as &mut [u8]}; - reader.read(raw_bytes) + let mut raw_bytes: &mut [u8] = + unsafe { &mut *(bytes as *const [_] as *mut [_] as *mut [u8]) }; + bytes_read += reader.read(raw_bytes).map_err(|_| __WASI_EIO)? as u32; + } + Ok(bytes_read) + } - // TODO: handle failure more accurately - bytes_written += iov_inner.buf_len; + let bytes_read = match fd { + 0 => { + let stdin = io::stdin(); + let mut handle = stdin.lock(); + + wasi_try!(read_bytes(handle, memory, iovs_arr_cell)) } - Ok(bytes_written) - }*/ + 1 | 2 => return __WASI_EINVAL, + _ => { + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + if fd_entry.rights & __WASI_RIGHT_FD_READ == 0 { + // TODO: figure out the error to return when lacking rights + return __WASI_EACCES; + } + + let offset = fd_entry.offset as usize; + let inode = &mut state.fs.inodes[fd_entry.inode]; + + let bytes_read = match &mut inode.kind { + Kind::File { handle } => wasi_try!(read_bytes(handle, memory, iovs_arr_cell)), + Kind::Dir { .. } => { + // TODO: verify + return __WASI_EISDIR; + } + Kind::Symlink { .. } => unimplemented!(), + Kind::Buffer { buffer } => { + wasi_try!(read_bytes(&buffer[offset..], memory, iovs_arr_cell)) + } + }; + + fd_entry.offset += bytes_read as u64; + + bytes_read + } + }; + + nread_cell.set(bytes_read); + __WASI_ESUCCESS } From 2de5a5da2ba00a4252be96d45a67662122f146ab Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 15:29:32 -0700 Subject: [PATCH 58/73] implement datasync --- lib/wasi/src/state.rs | 26 ++++++++++++++++++++++++++ lib/wasi/src/syscalls/mod.rs | 8 +++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 556df8319c2..80ba38bd8d9 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -7,6 +7,7 @@ use generational_arena::{Arena, Index as Inode}; use hashbrown::hash_map::{Entry, HashMap}; use std::{ cell::{Cell, RefCell}, + io::{self, Write}, ops::{Index, IndexMut}, path::PathBuf, rc::Rc, @@ -212,6 +213,31 @@ impl WasiFs { Err(__WASI_EBADF) } } + + pub fn flush(&mut self, fd: __wasi_fd_t) -> Result<(), __wasi_errno_t> { + match fd { + 0 => (), + 1 => io::stdout().flush().map_err(|_| __WASI_EIO)?, + 2 => io::stderr().flush().map_err(|_| __WASI_EIO)?, + _ => { + let fd = self.fd_map.get(&fd).ok_or(__WASI_EBADF)?; + if fd.rights & __WASI_RIGHT_FD_DATASYNC == 0 { + return Err(__WASI_EACCES); + } + + let inode = &mut self.inodes[fd.inode]; + + match &mut inode.kind { + Kind::File { handle } => handle.flush().map_err(|_| __WASI_EIO)?, + // TODO: verify this behavior + Kind::Dir { .. } => return Err(__WASI_EISDIR), + Kind::Symlink { .. } => unimplemented!(), + Kind::Buffer { .. } => (), + } + } + } + Ok(()) + } } pub struct WasiState<'a> { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 7db14045337..f1845482e7d 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -256,7 +256,13 @@ pub fn fd_close(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { /// The file descriptor to sync pub fn fd_datasync(ctx: &mut Ctx, fd: __wasi_fd_t) -> __wasi_errno_t { debug!("wasi::fd_datasync"); - unimplemented!() + let state = get_wasi_state(ctx); + + if let Err(e) = state.fs.flush(fd) { + e + } else { + __WASI_ESUCCESS + } } /// ### `fd_fdstat_get()` From e180fd1d1a6da7cbc621d1088ec55990873774fd Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 15:40:46 -0700 Subject: [PATCH 59/73] add set_rights syscall --- lib/wasi/src/state.rs | 1 + lib/wasi/src/syscalls/mod.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 80ba38bd8d9..dc994e92c61 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -43,6 +43,7 @@ pub enum Kind { pub struct Fd { pub rights: __wasi_rights_t, + pub rights_inheriting: __wasi_rights_t, pub flags: __wasi_fdflags_t, pub offset: u64, pub inode: Inode, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index f1845482e7d..79df807b513 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -307,7 +307,7 @@ pub fn fd_fdstat_set_flags( } /// ### `fd_fdstat_set_rights()` -/// Set the rights of a file descriptor +/// Set the rights of a file descriptor. This can only be used to remove rights /// Inputs: /// - `__wasi_fd_t fd` /// The file descriptor to apply the new rights to @@ -322,7 +322,20 @@ pub fn fd_fdstat_set_rights( fs_rights_inheriting: __wasi_rights_t, ) -> __wasi_errno_t { debug!("wasi::fd_fdstat_set_rights"); - unimplemented!() + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + // ensure new rights are a subset of current rights + if fd_entry.rights | fs_rights_base != fd_entry.rights + || fd_entry.rights_inheriting | fs_rights_inheriting != fd_entry.rights_inheriting + { + return __WASI_ENOTCAPABLE; + } + + fd_entry.rights = fs_rights_base; + fd_entry.rights_inheriting = fs_rights_inheriting; + + __WASI_ESUCCESS } /// ### `fd_filestat_get()` From fe4195fff60b997c804feb8efc0f29e260949de5 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 15:45:12 -0700 Subject: [PATCH 60/73] impl set_flags on fd --- lib/wasi/src/syscalls/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 79df807b513..21bc1c57f2f 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -303,7 +303,15 @@ pub fn fd_fdstat_set_flags( flags: __wasi_fdflags_t, ) -> __wasi_errno_t { debug!("wasi::fd_fdstat_set_flags"); - unimplemented!() + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + if fd_entry.rights & __WASI_RIGHT_FD_FDSTAT_SET_FLAGS == 0 { + return __WASI_EACCES; + } + + fd_entry.flags = flags; + __WASI_ESUCCESS } /// ### `fd_fdstat_set_rights()` From 697bdc7d46780013847696c53e61062a3f548c57 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 15:51:49 -0700 Subject: [PATCH 61/73] add rights checking fn for future-proofing reasons --- lib/wasi/src/syscalls/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 21bc1c57f2f..3235c5f8201 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,6 +26,11 @@ fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } } +/// checks that `rights_check_set` is a subset of `rights_set` +fn has_rights(rights_set: __wasi_rights_t, rights_check_set: __wasi_rights_t) -> bool { + rights_set | rights_check_set == rights_set +} + #[must_use] fn write_buffer_array( memory: &Memory, @@ -306,7 +311,7 @@ pub fn fd_fdstat_set_flags( let state = get_wasi_state(ctx); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); - if fd_entry.rights & __WASI_RIGHT_FD_FDSTAT_SET_FLAGS == 0 { + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS) { return __WASI_EACCES; } @@ -535,7 +540,7 @@ pub fn fd_read( let state = get_wasi_state(ctx); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); - if fd_entry.rights & __WASI_RIGHT_FD_READ == 0 { + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_READ) { // TODO: figure out the error to return when lacking rights return __WASI_EACCES; } @@ -740,7 +745,7 @@ pub fn fd_write( let state = get_wasi_state(ctx); let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); - if fd_entry.rights & __WASI_RIGHT_FD_WRITE == 0 { + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) { // TODO: figure out the error to return when lacking rights return __WASI_EACCES; } From 37371eba6e84f60d62591e38208194b80c8e3135 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 16:01:39 -0700 Subject: [PATCH 62/73] implement most of fd_filestat_set_times --- lib/wasi/src/syscalls/mod.rs | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 3235c5f8201..bae7325e176 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -384,6 +384,16 @@ pub fn fd_filestat_set_size( debug!("wasi::fd_filestat_set_size"); unimplemented!() } + +/// ### `fd_filestat_set_times()` +/// Set timestamp metadata on a file +/// Inputs: +/// - `__wasi_timestamp_t st_atim` +/// Last accessed time +/// - `__wasi_timestamp_t st_mtim` +/// Last modified time +/// - `__wasi_fstflags_t fst_flags` +/// Bit-vector for controlling which times get set pub fn fd_filestat_set_times( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -392,7 +402,37 @@ pub fn fd_filestat_set_times( fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { debug!("wasi::fd_filestat_set_times"); - unimplemented!() + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_FILESTAT_SET_TIMES) { + return __WASI_EACCES; + } + + if (fst_flags & __WASI_FILESTAT_SET_ATIM != 0 && fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0) + || (fst_flags & __WASI_FILESTAT_SET_MTIM != 0 + && fst_flags & __WASI_FILESTAT_SET_MTIM_NOW != 0) + { + return __WASI_EINVAL; + } + + let inode = &mut state.fs.inodes[fd_entry.inode]; + + if fst_flags & __WASI_FILESTAT_SET_ATIM != 0 { + inode.stat.st_atim = st_atim; + } else if fst_flags & __WASI_FILESTAT_SET_ATIM_NOW != 0 { + // set to current real time + unimplemented!(); + } + + if fst_flags & __WASI_FILESTAT_SET_MTIM != 0 { + inode.stat.st_mtim = st_mtim; + } else if fst_flags & __WASI_FILESTAT_SET_MTIM_NOW != 0 { + // set to current real time + unimplemented!(); + } + + __WASI_ESUCCESS } pub fn fd_pread( From 7d07b6f0b4afe5dd78017e22c3eaa60674aa3724 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 16:16:06 -0700 Subject: [PATCH 63/73] impl fd_seek --- lib/wasi/src/syscalls/mod.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index bae7325e176..be8cf19630d 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -210,8 +210,11 @@ pub fn fd_advise( len: __wasi_filesize_t, advice: __wasi_advice_t, ) -> __wasi_errno_t { - debug!("wasi::fd_advise"); - unimplemented!() + debug!("wasi::fd_advise: fd={}", fd); + + // this is used for our own benefit, so just returning success is a valid + // implementation for now + __WASI_ESUCCESS } /// ### `fd_allocate` @@ -677,15 +680,26 @@ pub fn fd_seek( whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t>, ) -> __wasi_errno_t { - debug!("wasi::fd_seek"); + debug!("wasi::fd_seek: fd={}", fd); let memory = ctx.memory(0); - // TODO: check __WASI_RIGHT_FD_SEEK - // TODO: handle directory input - if let Ok(new_offset_cell) = newoffset.deref(memory) { - unimplemented!() - } else { - __WASI_EFAULT + let state = get_wasi_state(ctx); + let new_offset_cell = wasi_try!(newoffset.deref(memory)); + + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_SEEK) { + return __WASI_EACCES; } + + // TODO: handle case if fd is a dir? + match whence { + __WASI_WHENCE_CUR => fd_entry.offset = (fd_entry.offset as i64 + offset) as u64, + __WASI_WHENCE_END => unimplemented!(), + __WASI_WHENCE_SET => fd_entry.offset = offset as u64, + _ => return __WASI_EINVAL, + } + + __WASI_ESUCCESS } /// ### `fd_sync()` From dd7cfac5058754305d371aeacb66114dec5646e5 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 16:23:33 -0700 Subject: [PATCH 64/73] implement fd_tell --- lib/wasi/src/syscalls/mod.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index be8cf19630d..bcb22b072d6 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -699,6 +699,8 @@ pub fn fd_seek( _ => return __WASI_EINVAL, } + new_offset_cell.set(fd_entry.offset); + __WASI_ESUCCESS } @@ -731,8 +733,19 @@ pub fn fd_tell( offset: WasmPtr<__wasi_filesize_t>, ) -> __wasi_errno_t { debug!("wasi::fd_tell"); - // TODO: check __WASI_RIGHT_FD_TELL - unimplemented!() + let memory = ctx.memory(0); + let state = get_wasi_state(ctx); + let offset_cell = wasi_try!(offset.deref(memory)); + + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_TELL) { + return __WASI_EACCES; + } + + offset_cell.set(fd_entry.offset); + + __WASI_ESUCCESS } /// ### `fd_write()` From ce4676d46956561dff30041d7baef0d8283152de Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 16:26:54 -0700 Subject: [PATCH 65/73] implement fd_renumber --- lib/wasi/src/state.rs | 1 + lib/wasi/src/syscalls/mod.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index dc994e92c61..1adc41970c5 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -41,6 +41,7 @@ pub enum Kind { }, } +#[derive(Clone)] pub struct Fd { pub rights: __wasi_rights_t, pub rights_inheriting: __wasi_rights_t, diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index bcb22b072d6..6bdead8fa68 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -657,8 +657,12 @@ pub fn fd_readdir( /// - `__wasi_fd_t to` /// Location to copy file descriptor to pub fn fd_renumber(ctx: &mut Ctx, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { - debug!("wasi::fd_renumber"); - unimplemented!() + debug!("wasi::fd_renumber: from={}, to={}", from, to); + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get(&from).ok_or(__WASI_EBADF)); + + state.fs.fd_map.insert(to, fd_entry.clone()); + __WASI_ESUCCESS } /// ### `fd_seek()` From f70b75e552c15ccad7e7c5bb83488cb4e00b97a7 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 2 Apr 2019 16:35:05 -0700 Subject: [PATCH 66/73] kind of implement fd_pwrite --- lib/wasi/src/syscalls/mod.rs | 108 ++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 20 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 6bdead8fa68..d650d9ea35a 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -26,6 +26,25 @@ fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } } +fn write_bytes( + mut write_loc: T, + memory: &Memory, + iovs_arr_cell: &[Cell<__wasi_ciovec_t>], +) -> Result { + let mut bytes_written = 0; + for iov in iovs_arr_cell { + let iov_inner = iov.get(); + let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?; + write_loc + .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) + .map_err(|_| __WASI_EIO)?; + + // TODO: handle failure more accurately + bytes_written += iov_inner.buf_len; + } + Ok(bytes_written) +} + /// checks that `rights_check_set` is a subset of `rights_set` fn has_rights(rights_set: __wasi_rights_t, rights_check_set: __wasi_rights_t) -> bool { rights_set | rights_check_set == rights_set @@ -517,6 +536,20 @@ pub fn fd_prestat_dir_name( } } +/// ### `fd_pwrite()` +/// Write to a file without adjusting its offset +/// Inputs: +/// - `__wasi_fd_t` +/// File descriptor (opened with writing) to write to +/// - `const __wasi_ciovec_t *iovs` +/// List of vectors to read data from +/// - `u32 iovs_len` +/// Length of data in `iovs` +/// - `__wasi_filesize_t offset` +/// The offset to write at +/// Output: +/// - `u32 *nwritten` +/// Number of bytes written pub fn fd_pwrite( ctx: &mut Ctx, fd: __wasi_fd_t, @@ -526,7 +559,61 @@ pub fn fd_pwrite( nwritten: WasmPtr, ) -> __wasi_errno_t { debug!("wasi::fd_pwrite"); - unimplemented!() + // TODO: refactor, this is just copied from `fd_write`... + let memory = ctx.memory(0); + let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); + let nwritten_cell = wasi_try!(nwritten.deref(memory)); + + let bytes_written = match fd { + 0 => return __WASI_EINVAL, + 1 => { + let stdout = io::stdout(); + let mut handle = stdout.lock(); + + wasi_try!(write_bytes(handle, memory, iovs_arr_cell)) + } + + 2 => { + let stderr = io::stderr(); + let mut handle = stderr.lock(); + + wasi_try!(write_bytes(handle, memory, iovs_arr_cell)) + } + _ => { + let state = get_wasi_state(ctx); + let fd_entry = wasi_try!(state.fs.fd_map.get_mut(&fd).ok_or(__WASI_EBADF)); + + if !has_rights(fd_entry.rights, __WASI_RIGHT_FD_WRITE) { + // TODO: figure out the error to return when lacking rights + return __WASI_EACCES; + } + + let inode = &mut state.fs.inodes[fd_entry.inode]; + + let bytes_written = match &mut inode.kind { + Kind::File { handle } => { + // TODO: adjust by offset + wasi_try!(write_bytes(handle, memory, iovs_arr_cell)) + } + Kind::Dir { .. } => { + // TODO: verify + return __WASI_EISDIR; + } + Kind::Symlink { .. } => unimplemented!(), + Kind::Buffer { buffer } => wasi_try!(write_bytes( + &mut buffer[(offset as usize)..], + memory, + iovs_arr_cell + )), + }; + + bytes_written + } + }; + + nwritten_cell.set(bytes_written); + + __WASI_ESUCCESS } /// ### `fd_read()` @@ -778,25 +865,6 @@ pub fn fd_write( let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len)); let nwritten_cell = wasi_try!(nwritten.deref(memory)); - fn write_bytes( - mut write_loc: T, - memory: &Memory, - iovs_arr_cell: &[Cell<__wasi_ciovec_t>], - ) -> Result { - let mut bytes_written = 0; - for iov in iovs_arr_cell { - let iov_inner = iov.get(); - let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?; - write_loc - .write(&bytes.iter().map(|b_cell| b_cell.get()).collect::>()) - .map_err(|_| __WASI_EIO)?; - - // TODO: handle failure more accurately - bytes_written += iov_inner.buf_len; - } - Ok(bytes_written) - } - let bytes_written = match fd { 0 => return __WASI_EINVAL, 1 => { From b80dd072a1e7ca04b2771b0488863ef7a00ac4ef Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 3 Apr 2019 11:56:45 -0700 Subject: [PATCH 67/73] implement happy path of fd_open --- lib/wasi/src/state.rs | 26 ++++++++- lib/wasi/src/syscalls/mod.rs | 106 ++++++++++++++++++++++++++++++----- 2 files changed, 117 insertions(+), 15 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 1adc41970c5..4f0102ccf95 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -31,7 +31,7 @@ pub enum Kind { Dir { handle: File, /// The entries of a directory are lazily filled. - entries: Vec, + entries: HashMap, }, Symlink { forwarded: Inode, @@ -123,7 +123,7 @@ impl WasiFs { FileType::File => Kind::File { handle: file }, FileType::Dir => Kind::Dir { handle: file, - entries: Vec::new(), + entries: HashMap::new(), }, }, }); @@ -240,6 +240,28 @@ impl WasiFs { } Ok(()) } + + pub fn create_fd( + &mut self, + rights: __wasi_rights_t, + rights_inheriting: __wasi_rights_t, + flags: __wasi_fdflags_t, + inode: Inode, + ) -> Result { + let idx = self.next_fd.get(); + self.next_fd.set(idx + 1); + self.fd_map.insert( + idx, + Fd { + rights, + rights_inheriting, + flags, + offset: 0, + inode, + }, + ); + Ok(idx) + } } pub struct WasiState<'a> { diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index d650d9ea35a..b6262d1f4d8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1076,22 +1076,102 @@ pub fn path_open( } // check for __WASI_RIGHT_PATH_OPEN somewhere, probably via dirfd + let fd_cell = wasi_try!(fd.deref(memory)); + let path_cells = wasi_try!(path.deref(memory, 0, path_len)); + let state = get_wasi_state(ctx); - if let (Ok(fd_cell), Ok(path_cell)) = (fd.deref(memory), path.deref(memory, 0, path_len)) { - // o_flags: - // - __WASI_O_FLAG_CREAT (create if it does not exist) - // - __WASI_O_DIRECTORY (fail if not dir) - // - __WASI_O_EXCL (fail if file exists) - // - __WASI_O_TRUNC (truncate size to 0) - if (o_flags & __WASI_O_DIRECTORY) != 0 { - // fail if fd is not a dir - // need to check and be able to clean up - } + // o_flags: + // - __WASI_O_FLAG_CREAT (create if it does not exist) + // - __WASI_O_DIRECTORY (fail if not dir) + // - __WASI_O_EXCL (fail if file exists) + // - __WASI_O_TRUNC (truncate size to 0) - unimplemented!(); - } else { - __WASI_EFAULT + let working_dir = wasi_try!(state.fs.fd_map.get(&dirfd).ok_or(__WASI_EBADF)); + + // ASSUMPTION: open rights cascade down + if !has_rights(working_dir.rights, __WASI_RIGHT_PATH_OPEN) { + return __WASI_EACCES; } + + let path_vec = + wasi_try!( + ::std::str::from_utf8(unsafe { &*(path_cells as *const [_] as *const [u8]) }) + .map_err(|_| __WASI_EINVAL) + ) + .split('/') + .map(|str| str.to_string()) + .collect::>(); + + if path_vec.is_empty() { + return __WASI_EINVAL; + } + + let working_dir_inode = &mut state.fs.inodes[working_dir.inode]; + + let mut cur_dir = working_dir; + + // TODO: refactor single path segment logic out and do traversing before + // as necessary + let out_fd = if path_vec.len() == 1 { + // just the file or dir + if let Kind::Dir { entries, .. } = &mut working_dir_inode.kind { + if let Some(child) = entries.get(&path_vec[0]).cloned() { + let child_inode_val = &state.fs.inodes[child]; + // early return based on flags + if o_flags & __WASI_O_EXCL != 0 { + return __WASI_EEXIST; + } + if o_flags & __WASI_O_DIRECTORY != 0 { + match &child_inode_val.kind { + Kind::Dir { .. } => (), + Kind::Symlink { .. } => unimplemented!(), + _ => return __WASI_ENOTDIR, + } + } + // do logic on child + wasi_try!(state + .fs + .create_fd(fs_rights_base, fs_rights_inheriting, fs_flags, child)) + } else { + // entry does not exist in parent directory + // check to see if we should create it + if o_flags & __WASI_O_CREAT != 0 { + // insert in to directory and set values + //entries.insert(path_segment[0], ) + unimplemented!() + } else { + // no entry and can't create it + return __WASI_ENOENT; + } + } + } else { + // working_dir is not a directory + return __WASI_ENOTDIR; + } + } else { + // traverse the pieces of the path + // TODO: lots of testing on this + for path_segment in &path_vec[..(path_vec.len() - 1)] { + match &working_dir_inode.kind { + Kind::Dir { entries, .. } => { + if let Some(child) = entries.get(path_segment) { + unimplemented!(); + } else { + // Is __WASI_O_FLAG_CREAT recursive? + // ASSUMPTION: it's not + return __WASI_EINVAL; + } + } + Kind::Symlink { .. } => unimplemented!(), + _ => return __WASI_ENOTDIR, + } + } + unimplemented!() + }; + + fd_cell.set(out_fd); + + __WASI_ESUCCESS } pub fn path_readlink( From 7d728fc4cc2bff0b8e7eb2e4c95ebab61d003fdc Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 3 Apr 2019 12:48:27 -0700 Subject: [PATCH 68/73] implement path_filestat_get --- lib/wasi/src/syscalls/mod.rs | 58 ++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index b6262d1f4d8..9d6768da1f4 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -8,7 +8,7 @@ pub mod windows; use self::types::*; use crate::{ ptr::{Array, WasmPtr}, - state::{Kind, WasiState}, + state::{Kind, WasiState, MAX_SYMLINKS}, }; use rand::{thread_rng, Rng}; use std::cell::Cell; @@ -943,9 +943,9 @@ pub fn path_create_directory( /// Access metadata about a file or directory /// Inputs: /// - `__wasi_fd_t fd` -/// The file to acces +/// The directory that `path` is relative to /// - `__wasi_lookupflags_t flags` -/// Flags to control how the path is understood +/// Flags to control how `path` is understood /// - `const char *path` /// String containing the file path /// - `u32 path_len` @@ -962,11 +962,57 @@ pub fn path_filestat_get( buf: WasmPtr<__wasi_filestat_t>, ) -> __wasi_errno_t { debug!("wasi::path_filestat_get"); - let mut state = get_wasi_state(ctx); + let state = get_wasi_state(ctx); let memory = ctx.memory(0); - // check __WASI_RIGHT_PATH_FILESTAT_GET - unimplemented!() + let root_dir = wasi_try!(state.fs.fd_map.get(&fd).ok_or(__WASI_EBADF)); + + if !has_rights(root_dir.rights, __WASI_RIGHT_PATH_FILESTAT_GET) { + return __WASI_EACCES; + } + + let path_vec = wasi_try!(::std::str::from_utf8(unsafe { + &*(wasi_try!(path.deref(memory, 0, path_len)) as *const [_] as *const [u8]) + }) + .map_err(|_| __WASI_EINVAL)) + .split('/') + .map(|str| str.to_string()) + .collect::>(); + let buf_cell = wasi_try!(buf.deref(memory)); + + // find the inode by traversing the path + let mut inode = root_dir.inode; + 'outer: for segment in path_vec { + // loop to traverse symlinks + // TODO: proper cycle detection + let mut sym_count = 0; + loop { + match &state.fs.inodes[inode].kind { + Kind::Dir { entries, .. } => { + if let Some(entry) = entries.get(&segment) { + inode = entry.clone(); + continue 'outer; + } else { + return __WASI_ENOENT; + } + } + Kind::Symlink { forwarded } => { + sym_count += 1; + inode = forwarded.clone(); + if sym_count > MAX_SYMLINKS { + return __WASI_ELOOP; + } + } + _ => return __WASI_ENOTDIR, + } + } + } + + let stat = state.fs.inodes[inode].stat; + + buf_cell.set(stat); + + __WASI_ESUCCESS } /// ### `path_filestat_set_times()` From d04d1bf2a9b54eb89c1c7f76bed9590774fcfca3 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 3 Apr 2019 14:59:24 -0700 Subject: [PATCH 69/73] improve debug statements for arg syscalls --- lib/wasi/src/syscalls/mod.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 9d6768da1f4..71b4cadae4e 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -93,7 +93,24 @@ pub fn args_get( let state = get_wasi_state(ctx); let memory = ctx.memory(0); - write_buffer_array(memory, &*state.args, argv, argv_buf) + let result = write_buffer_array(memory, &*state.args, argv, argv_buf); + + debug!( + "=> args:\n{}", + state + .args + .iter() + .enumerate() + .map(|(i, v)| format!( + "{:>20}: {}", + i, + ::std::str::from_utf8(v).unwrap().to_string() + )) + .collect::>() + .join("\n") + ); + + result } /// ### `args_sizes_get()` @@ -116,8 +133,12 @@ pub fn args_sizes_get( let state = get_wasi_state(ctx); - argc.set(state.args.len() as u32); - argv_buf_size.set(state.args.iter().map(|v| v.len() as u32 + 1).sum()); + let argc_val = state.args.len() as u32; + let argv_buf_size_val = state.args.iter().map(|v| v.len() as u32 + 1).sum(); + argc.set(argc_val); + argv_buf_size.set(argv_buf_size_val); + + debug!("=> argc={}, argv_buf_size={}", argc_val, argv_buf_size_val); __WASI_ESUCCESS } From 10696c484909cb8ae6034a027def8d03129a62d3 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 3 Apr 2019 16:21:26 -0700 Subject: [PATCH 70/73] clean up platform-specific syscall code --- lib/wasi/src/syscalls/mod.rs | 13 +++++------ lib/wasi/src/syscalls/unix/linux.rs | 36 ----------------------------- lib/wasi/src/syscalls/unix/macos.rs | 12 ---------- lib/wasi/src/syscalls/unix/mod.rs | 12 ---------- lib/wasi/src/syscalls/windows.rs | 10 -------- 5 files changed, 6 insertions(+), 77 deletions(-) delete mode 100644 lib/wasi/src/syscalls/unix/linux.rs delete mode 100644 lib/wasi/src/syscalls/unix/macos.rs diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 71b4cadae4e..068e4ed7801 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -489,13 +489,12 @@ pub fn fd_pread( debug!("wasi::fd_pread"); let memory = ctx.memory(0); - if let ((Ok(iov_cells), Ok(nread_cell))) = - (iovs.deref(memory, 0, iovs_len), nread.deref(memory)) - { - platform_fd_pread(fd, iov_cells, iovs_len, offset, nread_cell) - } else { - __WASI_EFAULT - } + let iov_cells = wasi_try!(iovs.deref(memory, 0, iovs_len)); + let nread_cell = wasi_try!(nread.deref(memory)); + + unimplemented!(); + + __WASI_ESUCCESS } /// ### `fd_prestat_get()` diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs deleted file mode 100644 index 627f95bf15c..00000000000 --- a/lib/wasi/src/syscalls/unix/linux.rs +++ /dev/null @@ -1,36 +0,0 @@ -use crate::syscalls::types::*; -use std::cell::Cell; -use std::mem; - -use libc::preadv; - -pub fn platform_fd_pread( - fd: __wasi_fd_t, - iovs: &[Cell<__wasi_iovec_t>], - iovs_len: u32, - offset: __wasi_filesize_t, - nread: &Cell, -) -> __wasi_errno_t { - let (result, iovec) = unsafe { - let mut iovec = vec![mem::uninitialized(); iovs_len as usize]; - ( - preadv( - fd as i32, - iovec.as_mut_ptr(), - iovs_len as i32, - offset as i64, - ), - iovec, - ) - }; - nread.set(result as u32); - /*for (i, arr_cell) in iovs.iter().enumerate() { - let wasi_iovec = __wasi_iovec_t { - buf: iovec[i] as _, - buf_len: iovec[i].iov_len as u32, - }; - arr_cell.set(wasi_iovec); - }*/ - - __WASI_ESUCCESS -} diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs deleted file mode 100644 index 748a58fb388..00000000000 --- a/lib/wasi/src/syscalls/unix/macos.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::syscalls::types::*; -use std::cell::Cell; - -pub fn platform_fd_pread( - fd: __wasi_fd_t, - iovs: &[Cell<__wasi_iovec_t>], - iovs_len: u32, - offset: __wasi_filesize_t, - nread: &Cell, -) -> __wasi_errno_t { - unimplemented!() -} diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs index 915699c24ec..4c9cfada321 100644 --- a/lib/wasi/src/syscalls/unix/mod.rs +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -1,15 +1,3 @@ -#[cfg(target_os = "linux")] -pub mod linux; - -#[cfg(target_os = "macos")] -pub mod macos; - -#[cfg(target_os = "linux")] -pub use linux::*; - -#[cfg(target_os = "macos")] -pub use macos::*; - use crate::syscalls::types::*; use libc::{ clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs index 5ea255f0a06..6273695d322 100644 --- a/lib/wasi/src/syscalls/windows.rs +++ b/lib/wasi/src/syscalls/windows.rs @@ -15,13 +15,3 @@ pub fn platform_clock_time_get( ) -> __wasi_errno_t { unimplemented!() } - -pub fn platform_fd_pread( - fd: __wasi_fd_t, - iovs: &[Cell<__wasi_iovec_t>], - iovs_len: u32, - offset: __wasi_filesize_t, - nread: &Cell, -) -> __wasi_errno_t { - unimplemented!() -} From e9e7a33317378dde433b6cd015f71e5767438f0f Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Wed, 3 Apr 2019 16:50:15 -0700 Subject: [PATCH 71/73] fix warnings and let it build on windows --- Cargo.lock | 400 +++++++++++++++++++++--------------------- lib/wasi/Cargo.toml | 4 +- lib/wasi/src/state.rs | 9 +- src/bin/wasmer.rs | 1 - 4 files changed, 207 insertions(+), 207 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b44432dce5c..ec8c7cd4c99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,7 +3,7 @@ name = "MacTypes-sys" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -13,7 +13,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "aho-corasick" -version = "0.6.10" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -39,7 +39,7 @@ name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -60,9 +60,9 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -72,15 +72,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -88,8 +88,8 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -117,7 +117,7 @@ dependencies = [ "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -143,7 +143,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -178,7 +178,7 @@ name = "capstone-sys" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -188,24 +188,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cbindgen" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" -version = "1.0.31" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -230,7 +230,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -258,10 +258,10 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.35" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -275,7 +275,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -283,7 +283,7 @@ name = "core-foundation-sys" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -389,8 +389,8 @@ dependencies = [ "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xoshiro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "tinytemplate 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -482,7 +482,7 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -517,7 +517,7 @@ dependencies = [ "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -532,7 +532,7 @@ dependencies = [ [[package]] name = "either" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -560,7 +560,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -570,8 +570,8 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -580,7 +580,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -588,7 +588,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -599,7 +599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -614,8 +614,8 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -624,7 +624,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -667,7 +667,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -675,7 +675,7 @@ name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -723,7 +723,7 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -739,7 +739,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -784,7 +784,7 @@ version = "0.12.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "h2 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -811,7 +811,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.25 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -837,10 +837,10 @@ name = "inkwell" version = "0.1.0" source = "git+https://github.com/wasmerio/inkwell?branch=llvm7-0#a14e62977504ef574dc2e933edc559cc79781ca7" dependencies = [ - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "inkwell_internal_macros 0.1.0 (git+https://github.com/wasmerio/inkwell?branch=llvm7-0)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "llvm-sys 70.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -850,7 +850,7 @@ version = "0.1.0" source = "git+https://github.com/wasmerio/inkwell?branch=llvm7-0#a14e62977504ef574dc2e933edc559cc79781ca7" dependencies = [ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -858,7 +858,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -867,7 +867,7 @@ name = "itertools" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -896,7 +896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.50" +version = "0.2.51" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -914,8 +914,8 @@ name = "libloading" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -923,8 +923,8 @@ name = "linked-hash-map" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_test 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_test 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -932,10 +932,10 @@ name = "llvm-sys" version = "70.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -961,7 +961,7 @@ name = "lz4" version = "1.23.1" source = "git+https://github.com/zboxfs/lz4-rs.git#4704144553d827a96d4fedeb683dbde1360e06e3" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "lz4-sys 1.8.3 (git+https://github.com/zboxfs/lz4-rs.git)", ] @@ -970,8 +970,8 @@ name = "lz4-sys" version = "1.8.3" source = "git+https://github.com/zboxfs/lz4-rs.git#4704144553d827a96d4fedeb683dbde1360e06e3" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -984,7 +984,7 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -992,8 +992,8 @@ name = "memmap" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1001,8 +1001,8 @@ name = "memmap" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1042,9 +1042,9 @@ name = "miniz_oxide_c_api" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1058,7 +1058,7 @@ dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1083,7 +1083,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1100,8 +1100,8 @@ version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1110,9 +1110,9 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1122,9 +1122,9 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1160,7 +1160,7 @@ name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1172,7 +1172,7 @@ dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1186,8 +1186,8 @@ name = "openssl-sys" version = "0.9.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1215,7 +1215,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1233,11 +1233,11 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1327,10 +1327,10 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1339,7 +1339,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1348,7 +1348,7 @@ dependencies = [ "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1394,9 +1394,9 @@ name = "rand_jitter" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1406,10 +1406,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1444,7 +1444,7 @@ version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1454,7 +1454,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1465,7 +1465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1479,7 +1479,7 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.51" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1487,24 +1487,24 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "1.1.2" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1515,19 +1515,19 @@ name = "remove_dir_all" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "reqwest" -version = "0.9.12" +version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.25 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1535,7 +1535,7 @@ dependencies = [ "mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1544,7 +1544,7 @@ dependencies = [ "tokio-threadpool 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "uuid 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1563,7 +1563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1598,7 +1598,7 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1622,7 +1622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1632,7 +1632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1643,7 +1643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1661,10 +1661,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1673,7 +1673,7 @@ version = "0.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1681,17 +1681,17 @@ name = "serde_bytes" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1701,15 +1701,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_test" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1719,7 +1719,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1770,7 +1770,7 @@ dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1785,7 +1785,7 @@ dependencies = [ [[package]] name = "syn" -version = "0.15.29" +version = "0.15.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1808,7 +1808,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1823,8 +1823,8 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)", "xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1853,11 +1853,11 @@ version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1873,8 +1873,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1899,9 +1899,9 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1909,7 +1909,7 @@ name = "tinytemplate" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1919,7 +1919,7 @@ version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1936,7 +1936,7 @@ name = "tokio-current-thread" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1946,7 +1946,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1955,7 +1955,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1965,7 +1965,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1983,7 +1983,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1992,7 +1992,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2007,7 +2007,7 @@ dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2021,7 +2021,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2039,7 +2039,7 @@ name = "toml" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2126,7 +2126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uuid" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2157,8 +2157,8 @@ name = "wabt" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "wabt-sys 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2168,8 +2168,8 @@ name = "wabt-sys" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "cmake 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2179,7 +2179,7 @@ version = "2.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2188,7 +2188,7 @@ name = "want" version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2222,18 +2222,18 @@ dependencies = [ "cranelift-native 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-wasm 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", "wasmer-win-exception-handler 0.2.0", "wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2245,7 +2245,7 @@ dependencies = [ "dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", "wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2258,7 +2258,7 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2273,14 +2273,14 @@ name = "wasmer-llvm-backend" version = "0.1.0" dependencies = [ "capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "inkwell 0.1.0 (git+https://github.com/wasmerio/inkwell?branch=llvm7-0)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2310,7 +2310,7 @@ version = "0.2.1" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", @@ -2323,8 +2323,8 @@ dependencies = [ name = "wasmer-runtime-c-api" version = "0.2.1" dependencies = [ - "cbindgen 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cbindgen 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime 0.2.1", "wasmer-runtime-core 0.2.1", ] @@ -2341,16 +2341,16 @@ dependencies = [ "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "wasmparser 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2371,7 +2371,7 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", @@ -2383,11 +2383,11 @@ name = "wasmer-win-exception-handler" version = "0.2.0" dependencies = [ "bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cmake 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.2.1", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2411,7 +2411,7 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2421,7 +2421,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2443,7 +2443,7 @@ name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2456,7 +2456,7 @@ name = "wincolor" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2474,13 +2474,13 @@ name = "xattr" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "zbox" version = "0.6.1" -source = "git+https://github.com/wasmerio/zbox?branch=bundle-libsodium#ada40126425cf4d1adb14ebbc08980d01a0d520b" +source = "git+https://github.com/wasmerio/zbox?branch=bundle-libsodium#c2a5a50317f587fd69585d1e8d9825daef24cc00" dependencies = [ "android_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2491,10 +2491,10 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lz4 1.23.1 (git+https://github.com/zboxfs/lz4-rs.git)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)", "rmp-serde 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2511,7 +2511,7 @@ name = "zstd-safe" version = "1.4.7+zstd.1.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "zstd-sys 1.4.8+zstd.1.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2521,15 +2521,15 @@ version = "1.4.8+zstd.1.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "blob 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] "checksum MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf9f0d0b1cc33a4d2aee14fb4b2eac03462ef4db29c8ac4057327d8a71ad86f" "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum android_log-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b8052e2d8aabbb8d556d6abbcce2a22b9590996c5f849b9c7ce4544a2e3b984e" "checksum android_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf44378e81264148f08e58336674542f82d0021f685d0be0320c82e1653dbe0b" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" @@ -2537,7 +2537,7 @@ dependencies = [ "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" +"checksum backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f106c02a3604afcdc0df5d36cc47b44b55917dbaf3d808f71c163a0ddba64637" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f7f7f0701772b17de73e4f5cbcb1dd6926f4706cba4c1ab62c5367f8bdc94e1" @@ -2550,14 +2550,14 @@ dependencies = [ "checksum capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00be9d203fa0e078b93b24603633fb081851dfe0c1086364431f52587a47157e" "checksum capstone-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2dc8d32bc5c1e6d0fcde10af411c98b07d93498d51654f678757f08fa2acd6a6" "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" -"checksum cbindgen 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f61c5411fe3ac196fae7ea397dd13959b1323edda046eec50d648a8e92015a53" -"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" +"checksum cbindgen 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "31f70db109be74a3dfcb0af4d0d191e52230351477f14c2ed10707c2b0dcfa2e" +"checksum cc 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "30f813bf45048a18eda9190fd3c6b78644146056740c43172a5a3699118588fd" "checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ef0c1bcf2e99c649104bd7a7012d8f8802684400e03db0ec0af48583c6fa0e4" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" +"checksum cmake 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "c11b79fbf026d6ec02704f7248c6da99be02068bf57f624bb08af72ad29f2c06" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980" "checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa" @@ -2585,7 +2585,7 @@ dependencies = [ "checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd" "checksum dynasm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b77e128faecc4d16cff7cae96c0c9e809f687f748a0dbc4d017996e48240a991" "checksum dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c408a211e7f5762829f5e46bdff0c14bc3b1517a21a4bb781c716bf88b0c68" -"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" +"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" "checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed" "checksum enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7798e7da2d4cb0d6d6fc467e8d6b5bf247e9e989f786dde1732d79899c32bb10" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" @@ -2602,7 +2602,7 @@ dependencies = [ "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" +"checksum futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "62941eff9507c8177d448bd83a44d9b9760856e184081d8cd79ba9f03dd24981" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4024f96ffa0ebaaf36aa589cd41f2fd69f3a5e6fd02c86e11e12cdf41d5b46a3" @@ -2628,7 +2628,7 @@ dependencies = [ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" +"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libflate 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "7346a83e8a2c3958d44d24225d905385dc31fc16e89dffb356c457b278914d20" "checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" @@ -2693,12 +2693,12 @@ dependencies = [ "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum redox_syscall 0.1.52 (registry+https://github.com/rust-lang/crates.io-index)" = "d32b3053e5ced86e4bc0411fec997389532bf56b000e66cb4884eeeb41413d69" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" -"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" +"checksum regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "559008764a17de49a3146b234641644ed37d118d1ef641a0bb573d146edc6ce0" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" -"checksum reqwest 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)" = "962fa64e670e70b9d3a81c3688832eb59293ef490e0af5ad169763f62016ac5e" +"checksum reqwest 0.9.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3c4ef83e0beb14bfe38b9f01330a5bc8e965a9f9628690aa28383746dac1e925" "checksum rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a3d45d7afc9b132b34a2479648863aa95c5c88e98b32285326a6ebadc80ec5c9" "checksum rmp-serde 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "011e1d58446e9fa3af7cdc1fb91295b10621d3ac4cb3a85cc86385ee9ca50cd3" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" @@ -2713,12 +2713,12 @@ dependencies = [ "checksum security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3d6696852716b589dff9e886ff83778bb635150168e83afa8ac6b8a78cb82abc" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" +"checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4" "checksum serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" "checksum serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "defbb8a83d7f34cc8380751eeb892b825944222888aff18996ea7901f24aec88" -"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" +"checksum serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc82bec244f168b23d1963b45c8bf5726e9a15a9d146a067f9081aeed2de79" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" -"checksum serde_test 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "70807e147558b5253cb70f55d343db1d07204d773087c96d0f35fced295dba82" +"checksum serde_test 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce17ed207fa61e7f4701a778a6c111da84a441ca9a8f50b92808f4223dd240b" "checksum serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d48f9f99cd749a2de71d29da5f948de7f2764cc5a9d7f3c97e3514d4ee6eabf2" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" @@ -2729,7 +2729,7 @@ dependencies = [ "checksum structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3d0760c312538987d363c36c42339b55f5ee176ea8808bbe4543d484a291c8d1" "checksum structopt-derive 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "528aeb7351d042e6ffbc2a6fb76a86f9b622fdf7c25932798e7a82cb03bc94c6" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2" +"checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" @@ -2767,7 +2767,7 @@ dependencies = [ "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum uuid 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "600ef8213e9f8a0ac1f876e470e90780ae0478eabce7f76aff41b0f4ef0fd5c0" +"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" @@ -2781,7 +2781,7 @@ dependencies = [ "checksum wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40f426b1929bd26517fb10702e2a8e520d1845c49567aa4d244f426f10b206c1" "checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index cbb5652867f..cdf1a45b444 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -16,7 +16,7 @@ generational-arena = "0.2.2" log = "0.4.6" byteorder = "1.3.1" -[target.'cfg(unix)'.dependencies.zbox] +[dependencies.zbox] git = "https://github.com/wasmerio/zbox" branch = "bundle-libsodium" -features = ["libsodium-bundled"] \ No newline at end of file +features = ["libsodium-bundled"] diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index 4f0102ccf95..d56f2f5bec2 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -6,11 +6,8 @@ use crate::syscalls::types::*; use generational_arena::{Arena, Index as Inode}; use hashbrown::hash_map::{Entry, HashMap}; use std::{ - cell::{Cell, RefCell}, + cell::Cell, io::{self, Write}, - ops::{Index, IndexMut}, - path::PathBuf, - rc::Rc, time::SystemTime, }; use zbox::{init_env as zbox_init_env, File, FileType, OpenOptions, Repo, RepoOpener}; @@ -24,6 +21,7 @@ pub struct InodeVal { pub kind: Kind, } +#[allow(dead_code)] pub enum Kind { File { handle: File, @@ -75,6 +73,7 @@ impl WasiFs { }) } + #[allow(dead_code)] fn get_inode(&mut self, path: &str) -> Option { Some(match self.name_map.entry(path.to_string()) { Entry::Occupied(o) => *o.get(), @@ -133,6 +132,7 @@ impl WasiFs { }) } + #[allow(dead_code)] fn filestat_inode( &self, inode: Inode, @@ -164,6 +164,7 @@ impl WasiFs { } } + #[allow(dead_code)] pub fn filestat_path( &mut self, preopened_fd: __wasi_fd_t, diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 4b17f50eff4..26e90a67372 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -12,7 +12,6 @@ use structopt::StructOpt; use wasmer::webassembly::InstanceABI; use wasmer::*; -use wasmer_emscripten; use wasmer_runtime::cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}; use wasmer_runtime_core::backend::CompilerConfig; #[cfg(feature = "wasi")] From c1c99dbff1886ed49148483e6a9ed6b2e0313a51 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 3 Apr 2019 17:01:02 -0700 Subject: [PATCH 72/73] rename fs and fix (probable) bug in renumber syscall --- lib/wasi/src/state.rs | 2 +- lib/wasi/src/syscalls/mod.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/wasi/src/state.rs b/lib/wasi/src/state.rs index d56f2f5bec2..5b42ba1c7f8 100644 --- a/lib/wasi/src/state.rs +++ b/lib/wasi/src/state.rs @@ -63,7 +63,7 @@ impl WasiFs { Ok(Self { repo: RepoOpener::new() .create(true) - .open("mem://foo", "") + .open("mem://wasmer-test-fs", "") .map_err(|e| e.to_string())?, name_map: HashMap::new(), inodes: Arena::new(), diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 068e4ed7801..15f0f26798a 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -8,7 +8,7 @@ pub mod windows; use self::types::*; use crate::{ ptr::{Array, WasmPtr}, - state::{Kind, WasiState, MAX_SYMLINKS}, + state::{Fd, Kind, WasiState, MAX_SYMLINKS}, }; use rand::{thread_rng, Rng}; use std::cell::Cell; @@ -768,7 +768,14 @@ pub fn fd_renumber(ctx: &mut Ctx, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_ let state = get_wasi_state(ctx); let fd_entry = wasi_try!(state.fs.fd_map.get(&from).ok_or(__WASI_EBADF)); - state.fs.fd_map.insert(to, fd_entry.clone()); + state.fs.fd_map.insert( + to, + Fd { + // TODO: verify this is correct + rights: fd_entry.rights_inheriting, + ..*fd_entry + }, + ); __WASI_ESUCCESS } From 207bd01400310b819b69ae990742434a160ffbf2 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Wed, 3 Apr 2019 17:13:50 -0700 Subject: [PATCH 73/73] rename to destructor --- lib/wasi/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index c6908988c59..dac093f5c6f 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -19,7 +19,7 @@ use wasmer_runtime_core::{func, import::ImportObject, imports}; pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportObject { let state_gen = move || { - fn state_dtor(data: *mut c_void) { + fn state_destructor(data: *mut c_void) { unsafe { drop(Box::from_raw(data as *mut WasiState)); } @@ -33,7 +33,7 @@ pub fn generate_import_object(args: Vec>, envs: Vec>) -> ImportO ( Box::leak(state) as *mut WasiState as *mut c_void, - state_dtor as fn(*mut c_void), + state_destructor as fn(*mut c_void), ) }; imports! {