diff --git a/lib/c-api/src/wasm_c_api/unstable/wasi.rs b/lib/c-api/src/wasm_c_api/unstable/wasi.rs index b3832669f55..793db9ce079 100644 --- a/lib/c-api/src/wasm_c_api/unstable/wasi.rs +++ b/lib/c-api/src/wasm_c_api/unstable/wasi.rs @@ -6,7 +6,7 @@ use super::super::{ wasi::wasi_env_t, }; use wasmer_api::{Exportable, Extern}; -use wasmer_wasi::{generate_import_object_from_env, get_wasi_version}; +use wasmer_wasi::{generate_import_object_from_ctx, get_wasi_version}; /// Unstable non-standard type wrapping `wasm_extern_t` with the /// addition of two `wasm_name_t` respectively for the module name and @@ -170,7 +170,7 @@ fn wasi_get_unordered_imports_inner( let version = c_try!(get_wasi_version(&module.inner, false) .ok_or("could not detect a WASI version on the given module")); - let import_object = generate_import_object_from_env(store, wasi_env.inner.clone(), version); + let import_object = generate_import_object_from_ctx(store, wasi_env.inner.clone(), version); imports.set_buffer( import_object diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 3daacd8e70e..3aa36fb48d0 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -16,7 +16,7 @@ use std::os::raw::c_char; use std::slice; use wasmer_api::{Exportable, Extern}; use wasmer_wasi::{ - generate_import_object_from_env, get_wasi_version, Pipe, WasiEnv, WasiFile, WasiState, + generate_import_object_from_ctx, get_wasi_version, Pipe, WasiEnv, WasiFile, WasiState, WasiStateBuilder, WasiVersion, }; @@ -343,7 +343,7 @@ fn wasi_get_imports_inner( let version = c_try!(get_wasi_version(&module.inner, false) .ok_or("could not detect a WASI version on the given module")); - let import_object = generate_import_object_from_env(store, wasi_env.inner.clone(), version); + let import_object = generate_import_object_from_ctx(store, wasi_env.inner.clone(), version); imports.set_buffer(c_try!(module .inner diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index acffae017db..2940817142c 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -64,8 +64,8 @@ use derivative::*; use std::ops::Deref; use thiserror::Error; use wasmer::{ - imports, AsContextMut, Function, Imports, LazyInit, Memory, Memory32, MemoryAccessError, - MemorySize, MemoryType, Module, Store, TypedFunction, WasmerEnv, + imports, namespace, AsContextMut, Exports, Function, Imports, Memory, Memory32, + MemoryAccessError, MemorySize, Module, TypedFunction, }; pub use runtime::{ @@ -144,8 +144,9 @@ impl WasiThread { } /// The environment provided to the WASI imports. -#[derive(Derivative, Clone, WasmerEnv)] +#[derive(Derivative, Clone)] #[derivative(Debug)] +#[allow(dead_code)] pub struct WasiEnv { /// ID of this thread (zero is the main thread) id: WasiThreadId, @@ -153,20 +154,15 @@ pub struct WasiEnv { memory: Option, /// If the module has it then map the thread start #[derivative(Debug = "ignore")] - #[wasmer(export(optional = true, name = "_thread_start"))] - thread_start: LazyInit>, + thread_start: Option>, #[derivative(Debug = "ignore")] - #[wasmer(export(optional = true, name = "_reactor_work"))] - reactor_work: LazyInit>, + reactor_work: Option>, #[derivative(Debug = "ignore")] - #[wasmer(export(optional = true, name = "_reactor_finish"))] - reactor_finish: LazyInit>, + reactor_finish: Option>, #[derivative(Debug = "ignore")] - #[wasmer(export(optional = true, name = "_malloc"))] - malloc: LazyInit>, + malloc: Option>, #[derivative(Debug = "ignore")] - #[wasmer(export(optional = true, name = "_free"))] - free: LazyInit>, + free: Option>, /// Shared state of the WASI system. Manages all the data that the /// executing WASI program can see. pub state: Arc, @@ -181,11 +177,11 @@ impl WasiEnv { id: 0u32.into(), state: Arc::new(state), memory: None, - thread_start: LazyInit::new(), - reactor_work: LazyInit::new(), - reactor_finish: LazyInit::new(), - malloc: LazyInit::new(), - free: LazyInit::new(), + thread_start: None, + reactor_work: None, + reactor_finish: None, + malloc: None, + free: None, runtime: Arc::new(PluggableRuntimeImplementation::default()), } } @@ -227,22 +223,6 @@ impl WasiEnv { thread } - /// Get the WASI state - /// - /// Be careful when using this in host functions that call into Wasm: - /// if the lock is held and the Wasm calls into a host function that tries - /// to lock this mutex, the program will deadlock. - pub fn state(&self) -> &WasiState { - self.state.deref() - } - - /// Get a reference to the memory - pub fn memory(&self) -> &Memory { - self.memory - .get_ref() - .expect("Memory should be set on `WasiEnv` first") - } - /// Copy the lazy reference so that when it's initialized during the /// export phase, all the other references get a copy of it pub fn memory_clone(&self) -> Option { @@ -252,9 +232,9 @@ impl WasiEnv { /// Get an `Imports` for a specific version of WASI detected in the module. pub fn import_object(&mut self, module: &Module) -> Result { let wasi_version = get_wasi_version(module, false).ok_or(WasiError::UnknownWasiVersion)?; - Ok(generate_import_object_from_env( - module.store(), - self.clone(), + let mut context = Context::new(module.store(), self.clone()); + Ok(generate_import_object_from_ctx( + &mut context.as_context_mut(), wasi_version, )) } @@ -269,9 +249,10 @@ impl WasiEnv { get_wasi_versions(module, false).ok_or(WasiError::UnknownWasiVersion)?; let mut resolver = Imports::new(); + let mut context = Context::new(module.store(), self.clone()); for version in wasi_versions.iter() { let new_import_object = - generate_import_object_from_env(module.store(), self.clone(), *version); + generate_import_object_from_ctx(&mut context.as_context_mut(), *version); for ((n, m), e) in new_import_object.into_iter() { resolver.define(&n, &m, e); } @@ -338,7 +319,7 @@ impl WasiEnv { /// Set the memory of the WasiEnv (can only be done once) pub fn set_memory(&mut self, memory: Memory) { - if !self.memory.is_none() { + if self.memory.is_some() { panic!("Memory of a WasiEnv can only be set once!"); } self.memory = Some(memory); @@ -388,110 +369,136 @@ pub fn generate_import_object_from_ctx( } } +fn wasi_unstable_exports(ctx: &mut ContextMut<'_, WasiEnv>) -> Exports { + let namespace = namespace! { + "args_get" => Function::new_native(ctx, args_get::), + "args_sizes_get" => Function::new_native(ctx, args_sizes_get::), + "clock_res_get" => Function::new_native(ctx, clock_res_get::), + "clock_time_get" => Function::new_native(ctx, clock_time_get::), + "environ_get" => Function::new_native(ctx, environ_get::), + "environ_sizes_get" => Function::new_native(ctx, environ_sizes_get::), + "fd_advise" => Function::new_native(ctx, fd_advise), + "fd_allocate" => Function::new_native(ctx, fd_allocate), + "fd_close" => Function::new_native(ctx, fd_close), + "fd_datasync" => Function::new_native(ctx, fd_datasync), + "fd_fdstat_get" => Function::new_native(ctx, fd_fdstat_get::), + "fd_fdstat_set_flags" => Function::new_native(ctx, fd_fdstat_set_flags), + "fd_fdstat_set_rights" => Function::new_native(ctx, fd_fdstat_set_rights), + "fd_filestat_get" => Function::new_native(ctx, legacy::snapshot0::fd_filestat_get), + "fd_filestat_set_size" => Function::new_native(ctx, fd_filestat_set_size), + "fd_filestat_set_times" => Function::new_native(ctx, fd_filestat_set_times), + "fd_pread" => Function::new_native(ctx, fd_pread::), + "fd_prestat_get" => Function::new_native(ctx, fd_prestat_get::), + "fd_prestat_dir_name" => Function::new_native(ctx, fd_prestat_dir_name::), + "fd_pwrite" => Function::new_native(ctx, fd_pwrite::), + "fd_read" => Function::new_native(ctx, fd_read::), + "fd_readdir" => Function::new_native(ctx, fd_readdir::), + "fd_renumber" => Function::new_native(ctx, fd_renumber), + "fd_seek" => Function::new_native(ctx, legacy::snapshot0::fd_seek), + "fd_sync" => Function::new_native(ctx, fd_sync), + "fd_tell" => Function::new_native(ctx, fd_tell::), + "fd_write" => Function::new_native(ctx, fd_write::), + "path_create_directory" => Function::new_native(ctx, path_create_directory::), + "path_filestat_get" => Function::new_native(ctx, legacy::snapshot0::path_filestat_get), + "path_filestat_set_times" => Function::new_native(ctx, path_filestat_set_times::), + "path_link" => Function::new_native(ctx, path_link::), + "path_open" => Function::new_native(ctx, path_open::), + "path_readlink" => Function::new_native(ctx, path_readlink::), + "path_remove_directory" => Function::new_native(ctx, path_remove_directory::), + "path_rename" => Function::new_native(ctx, path_rename::), + "path_symlink" => Function::new_native(ctx, path_symlink::), + "path_unlink_file" => Function::new_native(ctx, path_unlink_file::), + "poll_oneoff" => Function::new_native(ctx, legacy::snapshot0::poll_oneoff), + "proc_exit" => Function::new_native(ctx, proc_exit), + "proc_raise" => Function::new_native(ctx, proc_raise), + "random_get" => Function::new_native(ctx, random_get::), + "sched_yield" => Function::new_native(ctx, sched_yield), + "sock_recv" => Function::new_native(ctx, sock_recv::), + "sock_send" => Function::new_native(ctx, sock_send::), + "sock_shutdown" => Function::new_native(ctx, sock_shutdown), + }; + namespace +} + +fn wasi_snapshot_preview1_exports(ctx: &mut ContextMut<'_, WasiEnv>) -> Exports { + let namespace = namespace! { + "args_get" => Function::new_native(ctx, args_get::), + "args_sizes_get" => Function::new_native(ctx, args_sizes_get::), + "clock_res_get" => Function::new_native(ctx, clock_res_get::), + "clock_time_get" => Function::new_native(ctx, clock_time_get::), + "environ_get" => Function::new_native(ctx, environ_get::), + "environ_sizes_get" => Function::new_native(ctx, environ_sizes_get::), + "fd_advise" => Function::new_native(ctx, fd_advise), + "fd_allocate" => Function::new_native(ctx, fd_allocate), + "fd_close" => Function::new_native(ctx, fd_close), + "fd_datasync" => Function::new_native(ctx, fd_datasync), + "fd_fdstat_get" => Function::new_native(ctx, fd_fdstat_get::), + "fd_fdstat_set_flags" => Function::new_native(ctx, fd_fdstat_set_flags), + "fd_fdstat_set_rights" => Function::new_native(ctx, fd_fdstat_set_rights), + "fd_filestat_get" => Function::new_native(ctx, fd_filestat_get::), + "fd_filestat_set_size" => Function::new_native(ctx, fd_filestat_set_size), + "fd_filestat_set_times" => Function::new_native(ctx, fd_filestat_set_times), + "fd_pread" => Function::new_native(ctx, fd_pread::), + "fd_prestat_get" => Function::new_native(ctx, fd_prestat_get::), + "fd_prestat_dir_name" => Function::new_native(ctx, fd_prestat_dir_name::), + "fd_pwrite" => Function::new_native(ctx, fd_pwrite::), + "fd_read" => Function::new_native(ctx, fd_read::), + "fd_readdir" => Function::new_native(ctx, fd_readdir::), + "fd_renumber" => Function::new_native(ctx, fd_renumber), + "fd_seek" => Function::new_native(ctx, fd_seek::), + "fd_sync" => Function::new_native(ctx, fd_sync), + "fd_tell" => Function::new_native(ctx, fd_tell::), + "fd_write" => Function::new_native(ctx, fd_write::), + "path_create_directory" => Function::new_native(ctx, path_create_directory::), + "path_filestat_get" => Function::new_native(ctx, path_filestat_get::), + "path_filestat_set_times" => Function::new_native(ctx, path_filestat_set_times::), + "path_link" => Function::new_native(ctx, path_link::), + "path_open" => Function::new_native(ctx, path_open::), + "path_readlink" => Function::new_native(ctx, path_readlink::), + "path_remove_directory" => Function::new_native(ctx, path_remove_directory::), + "path_rename" => Function::new_native(ctx, path_rename::), + "path_symlink" => Function::new_native(ctx, path_symlink::), + "path_unlink_file" => Function::new_native(ctx, path_unlink_file::), + "poll_oneoff" => Function::new_native(ctx, poll_oneoff::), + "proc_exit" => Function::new_native(ctx, proc_exit), + "proc_raise" => Function::new_native(ctx, proc_raise), + "random_get" => Function::new_native(ctx, random_get::), + "sched_yield" => Function::new_native(ctx, sched_yield), + "sock_recv" => Function::new_native(ctx, sock_recv::), + "sock_send" => Function::new_native(ctx, sock_send::), + "sock_shutdown" => Function::new_native(ctx, sock_shutdown), + }; + namespace +} pub fn import_object_for_all_wasi_versions(ctx: &mut ContextMut<'_, WasiEnv>) -> Imports { + let wasi_unstable_exports = wasi_unstable_exports(ctx); + let wasi_snapshot_preview1_exports = wasi_snapshot_preview1_exports(ctx); imports! { - "wasi_unstable" => { - "args_get" => Function::new_native(ctx, args_get), - "args_sizes_get" => Function::new_native(ctx, args_sizes_get), - "clock_res_get" => Function::new_native(ctx, clock_res_get), - "clock_time_get" => Function::new_native(ctx, clock_time_get), - "environ_get" => Function::new_native(ctx, environ_get), - "environ_sizes_get" => Function::new_native(ctx, environ_sizes_get), - "fd_advise" => Function::new_native(ctx, fd_advise), - "fd_allocate" => Function::new_native(ctx, fd_allocate), - "fd_close" => Function::new_native(ctx, fd_close), - "fd_datasync" => Function::new_native(ctx, fd_datasync), - "fd_fdstat_get" => Function::new_native(ctx, fd_fdstat_get), - "fd_fdstat_set_flags" => Function::new_native(ctx, fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native(ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(ctx, legacy::snapshot0::fd_filestat_get), - "fd_filestat_set_size" => Function::new_native(ctx, fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native(ctx, fd_filestat_set_times), - "fd_pread" => Function::new_native(ctx, fd_pread), - "fd_prestat_get" => Function::new_native(ctx, fd_prestat_get), - "fd_prestat_dir_name" => Function::new_native(ctx, fd_prestat_dir_name), - "fd_pwrite" => Function::new_native(ctx, fd_pwrite), - "fd_read" => Function::new_native(ctx, fd_read), - "fd_readdir" => Function::new_native(ctx, fd_readdir), - "fd_renumber" => Function::new_native(ctx, fd_renumber), - "fd_seek" => Function::new_native(ctx, legacy::snapshot0::fd_seek), - "fd_sync" => Function::new_native(ctx, fd_sync), - "fd_tell" => Function::new_native(ctx, fd_tell), - "fd_write" => Function::new_native(ctx, fd_write), - "path_create_directory" => Function::new_native(ctx, path_create_directory), - "path_filestat_get" => Function::new_native(ctx, legacy::snapshot0::path_filestat_get), - "path_filestat_set_times" => Function::new_native(ctx, path_filestat_set_times), - "path_link" => Function::new_native(ctx, path_link), - "path_open" => Function::new_native(ctx, path_open), - "path_readlink" => Function::new_native(ctx, path_readlink), - "path_remove_directory" => Function::new_native(ctx, path_remove_directory), - "path_rename" => Function::new_native(ctx, path_rename), - "path_symlink" => Function::new_native(ctx, path_symlink), - "path_unlink_file" => Function::new_native(ctx, path_unlink_file), - "poll_oneoff" => Function::new_native(ctx, legacy::snapshot0::poll_oneoff), - "proc_exit" => Function::new_native(ctx, proc_exit), - "proc_raise" => Function::new_native(ctx, proc_raise), - "random_get" => Function::new_native(ctx, random_get), - "sched_yield" => Function::new_native(ctx, sched_yield), - "sock_recv" => Function::new_native(ctx, sock_recv), - "sock_send" => Function::new_native(ctx, sock_send), - "sock_shutdown" => Function::new_native(ctx, sock_shutdown), - }, - "wasi_snapshot_preview1" => { - "args_get" => Function::new_native(ctx, args_get), - "args_sizes_get" => Function::new_native(ctx, args_sizes_get), - "clock_res_get" => Function::new_native(ctx, clock_res_get), - "clock_time_get" => Function::new_native(ctx, clock_time_get), - "environ_get" => Function::new_native(ctx, environ_get), - "environ_sizes_get" => Function::new_native(ctx, environ_sizes_get), - "fd_advise" => Function::new_native(ctx, fd_advise), - "fd_allocate" => Function::new_native(ctx, fd_allocate), - "fd_close" => Function::new_native(ctx, fd_close), - "fd_datasync" => Function::new_native(ctx, fd_datasync), - "fd_fdstat_get" => Function::new_native(ctx, fd_fdstat_get), - "fd_fdstat_set_flags" => Function::new_native(ctx, fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native(ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(ctx, fd_filestat_get), - "fd_filestat_set_size" => Function::new_native(ctx, fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native(ctx, fd_filestat_set_times), - "fd_pread" => Function::new_native(ctx, fd_pread), - "fd_prestat_get" => Function::new_native(ctx, fd_prestat_get), - "fd_prestat_dir_name" => Function::new_native(ctx, fd_prestat_dir_name), - "fd_pwrite" => Function::new_native(ctx, fd_pwrite), - "fd_read" => Function::new_native(ctx, fd_read), - "fd_readdir" => Function::new_native(ctx, fd_readdir), - "fd_renumber" => Function::new_native(ctx, fd_renumber), - "fd_seek" => Function::new_native(ctx, fd_seek), - "fd_sync" => Function::new_native(ctx, fd_sync), - "fd_tell" => Function::new_native(ctx, fd_tell), - "fd_write" => Function::new_native(ctx, fd_write), - "path_create_directory" => Function::new_native(ctx, path_create_directory), - "path_filestat_get" => Function::new_native(ctx, path_filestat_get), - "path_filestat_set_times" => Function::new_native(ctx, path_filestat_set_times), - "path_link" => Function::new_native(ctx, path_link), - "path_open" => Function::new_native(ctx, path_open), - "path_readlink" => Function::new_native(ctx, path_readlink), - "path_remove_directory" => Function::new_native(ctx, path_remove_directory), - "path_rename" => Function::new_native(ctx, path_rename), - "path_symlink" => Function::new_native(ctx, path_symlink), - "path_unlink_file" => Function::new_native(ctx, path_unlink_file), - "poll_oneoff" => Function::new_native(ctx, poll_oneoff), - "proc_exit" => Function::new_native(ctx, proc_exit), - "proc_raise" => Function::new_native(ctx, proc_raise), - "random_get" => Function::new_native(ctx, random_get), - "sched_yield" => Function::new_native(ctx, sched_yield), - "sock_recv" => Function::new_native(ctx, sock_recv), - "sock_send" => Function::new_native(ctx, sock_send), - "sock_shutdown" => Function::new_native(ctx, sock_shutdown), - } + "wasi_unstable" => wasi_unstable_exports, + "wasi_snapshot_preview1" => wasi_snapshot_preview1_exports, } } /// Combines a state generating function with the import list for legacy WASI fn generate_import_object_snapshot0(ctx: &mut ContextMut<'_, WasiEnv>) -> Imports { - use self::wasi::*; + let wasi_unstable_exports = wasi_unstable_exports(ctx); + imports! { + "wasi_unstable" => wasi_unstable_exports + } +} + +fn generate_import_object_snapshot1(ctx: &mut ContextMut<'_, WasiEnv>) -> Imports { + let wasi_snapshot_preview1_exports = wasi_snapshot_preview1_exports(ctx); + imports! { + "wasi_snapshot_preview1" => wasi_snapshot_preview1_exports + } +} + +/// Combines a state generating function with the import list for snapshot 1 +fn generate_import_object_wasix32_v1(ctx: &mut ContextMut<'_, WasiEnv>) -> Imports { + use self::wasix32::*; imports! { - "wasi_unstable" => { + "wasix_32v1" => { "args_get" => Function::new_native(ctx, args_get), "args_sizes_get" => Function::new_native(ctx, args_sizes_get), "clock_res_get" => Function::new_native(ctx, clock_res_get), @@ -505,7 +512,7 @@ fn generate_import_object_snapshot0(ctx: &mut ContextMut<'_, WasiEnv>) -> Import "fd_fdstat_get" => Function::new_native(ctx, fd_fdstat_get), "fd_fdstat_set_flags" => Function::new_native(ctx, fd_fdstat_set_flags), "fd_fdstat_set_rights" => Function::new_native(ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(ctx, legacy::snapshot0::fd_filestat_get), + "fd_filestat_get" => Function::new_native(ctx, fd_filestat_get), "fd_filestat_set_size" => Function::new_native(ctx, fd_filestat_set_size), "fd_filestat_set_times" => Function::new_native(ctx, fd_filestat_set_times), "fd_pread" => Function::new_native(ctx, fd_pread), @@ -515,12 +522,15 @@ fn generate_import_object_snapshot0(ctx: &mut ContextMut<'_, WasiEnv>) -> Import "fd_read" => Function::new_native(ctx, fd_read), "fd_readdir" => Function::new_native(ctx, fd_readdir), "fd_renumber" => Function::new_native(ctx, fd_renumber), - "fd_seek" => Function::new_native(ctx, legacy::snapshot0::fd_seek), + "fd_dup" => Function::new_native(ctx, fd_dup), + "fd_event" => Function::new_native(ctx, fd_event), + "fd_seek" => Function::new_native(ctx, fd_seek), "fd_sync" => Function::new_native(ctx, fd_sync), "fd_tell" => Function::new_native(ctx, fd_tell), "fd_write" => Function::new_native(ctx, fd_write), + "fd_pipe" => Function::new_native(ctx, fd_pipe), "path_create_directory" => Function::new_native(ctx, path_create_directory), - "path_filestat_get" => Function::new_native(ctx, legacy::snapshot0::path_filestat_get), + "path_filestat_get" => Function::new_native(ctx, path_filestat_get), "path_filestat_set_times" => Function::new_native(ctx, path_filestat_set_times), "path_link" => Function::new_native(ctx, path_link), "path_open" => Function::new_native(ctx, path_open), @@ -529,22 +539,81 @@ fn generate_import_object_snapshot0(ctx: &mut ContextMut<'_, WasiEnv>) -> Import "path_rename" => Function::new_native(ctx, path_rename), "path_symlink" => Function::new_native(ctx, path_symlink), "path_unlink_file" => Function::new_native(ctx, path_unlink_file), - "poll_oneoff" => Function::new_native(ctx, legacy::snapshot0::poll_oneoff), + "poll_oneoff" => Function::new_native(ctx, poll_oneoff), "proc_exit" => Function::new_native(ctx, proc_exit), "proc_raise" => Function::new_native(ctx, proc_raise), "random_get" => Function::new_native(ctx, random_get), + "tty_get" => Function::new_native(ctx, tty_get), + "tty_set" => Function::new_native(ctx, tty_set), + "getcwd" => Function::new_native(ctx, getcwd), + "chdir" => Function::new_native(ctx, chdir), + "thread_spawn" => Function::new_native(ctx, thread_spawn), + "thread_sleep" => Function::new_native(ctx, thread_sleep), + "thread_id" => Function::new_native(ctx, thread_id), + "thread_join" => Function::new_native(ctx, thread_join), + "thread_parallelism" => Function::new_native(ctx, thread_parallelism), + "thread_exit" => Function::new_native(ctx, thread_exit), "sched_yield" => Function::new_native(ctx, sched_yield), + "getpid" => Function::new_native(ctx, getpid), + "process_spawn" => Function::new_native(ctx, process_spawn), + "bus_open_local" => Function::new_native(ctx, bus_open_local), + "bus_open_remote" => Function::new_native(ctx, bus_open_remote), + "bus_close" => Function::new_native(ctx, bus_close), + "bus_call" => Function::new_native(ctx, bus_call), + "bus_subcall" => Function::new_native(ctx, bus_subcall), + "bus_poll" => Function::new_native(ctx, bus_poll), + "call_reply" => Function::new_native(ctx, call_reply), + "call_fault" => Function::new_native(ctx, call_fault), + "call_close" => Function::new_native(ctx, call_close), + "ws_connect" => Function::new_native(ctx, ws_connect), + "http_request" => Function::new_native(ctx, http_request), + "http_status" => Function::new_native(ctx, http_status), + "port_bridge" => Function::new_native(ctx, port_bridge), + "port_unbridge" => Function::new_native(ctx, port_unbridge), + "port_dhcp_acquire" => Function::new_native(ctx, port_dhcp_acquire), + "port_addr_add" => Function::new_native(ctx, port_addr_add), + "port_addr_remove" => Function::new_native(ctx, port_addr_remove), + "port_addr_clear" => Function::new_native(ctx, port_addr_clear), + "port_addr_list" => Function::new_native(ctx, port_addr_list), + "port_mac" => Function::new_native(ctx, port_mac), + "port_gateway_set" => Function::new_native(ctx, port_gateway_set), + "port_route_add" => Function::new_native(ctx, port_route_add), + "port_route_remove" => Function::new_native(ctx, port_route_remove), + "port_route_clear" => Function::new_native(ctx, port_route_clear), + "port_route_list" => Function::new_native(ctx, port_route_list), + "sock_status" => Function::new_native(ctx, sock_status), + "sock_addr_local" => Function::new_native(ctx, sock_addr_local), + "sock_addr_peer" => Function::new_native(ctx, sock_addr_peer), + "sock_open" => Function::new_native(ctx, sock_open), + "sock_set_opt_flag" => Function::new_native(ctx, sock_set_opt_flag), + "sock_get_opt_flag" => Function::new_native(ctx, sock_get_opt_flag), + "sock_set_opt_time" => Function::new_native(ctx, sock_set_opt_time), + "sock_get_opt_time" => Function::new_native(ctx, sock_get_opt_time), + "sock_set_opt_size" => Function::new_native(ctx, sock_set_opt_size), + "sock_get_opt_size" => Function::new_native(ctx, sock_get_opt_size), + "sock_join_multicast_v4" => Function::new_native(ctx, sock_join_multicast_v4), + "sock_leave_multicast_v4" => Function::new_native(ctx, sock_leave_multicast_v4), + "sock_join_multicast_v6" => Function::new_native(ctx, sock_join_multicast_v6), + "sock_leave_multicast_v6" => Function::new_native(ctx, sock_leave_multicast_v6), + "sock_bind" => Function::new_native(ctx, sock_bind), + "sock_listen" => Function::new_native(ctx, sock_listen), + "sock_accept" => Function::new_native(ctx, sock_accept), + "sock_connect" => Function::new_native(ctx, sock_connect), "sock_recv" => Function::new_native(ctx, sock_recv), + "sock_recv_from" => Function::new_native(ctx, sock_recv_from), "sock_send" => Function::new_native(ctx, sock_send), + "sock_send_to" => Function::new_native(ctx, sock_send_to), + "sock_send_file" => Function::new_native(ctx, sock_send_file), "sock_shutdown" => Function::new_native(ctx, sock_shutdown), - }, + "resolve" => Function::new_native(ctx, resolve), + } } } -fn generate_import_object_snapshot1(ctx: &mut ContextMut<'_, WasiEnv>) -> Imports { - use self::wasi::*; +fn generate_import_object_wasix64_v1(ctx: &mut ContextMut<'_, WasiEnv>) -> Imports { + use self::wasix64::*; imports! { - "wasi_snapshot_preview1" => { + "wasix_64v1" => { "args_get" => Function::new_native(ctx, args_get), "args_sizes_get" => Function::new_native(ctx, args_sizes_get), "clock_res_get" => Function::new_native(ctx, clock_res_get), @@ -568,10 +637,13 @@ fn generate_import_object_snapshot1(ctx: &mut ContextMut<'_, WasiEnv>) -> Import "fd_read" => Function::new_native(ctx, fd_read), "fd_readdir" => Function::new_native(ctx, fd_readdir), "fd_renumber" => Function::new_native(ctx, fd_renumber), + "fd_dup" => Function::new_native(ctx, fd_dup), + "fd_event" => Function::new_native(ctx, fd_event), "fd_seek" => Function::new_native(ctx, fd_seek), "fd_sync" => Function::new_native(ctx, fd_sync), "fd_tell" => Function::new_native(ctx, fd_tell), "fd_write" => Function::new_native(ctx, fd_write), + "fd_pipe" => Function::new_native(ctx, fd_pipe), "path_create_directory" => Function::new_native(ctx, path_create_directory), "path_filestat_get" => Function::new_native(ctx, path_filestat_get), "path_filestat_set_times" => Function::new_native(ctx, path_filestat_set_times), @@ -586,241 +658,69 @@ fn generate_import_object_snapshot1(ctx: &mut ContextMut<'_, WasiEnv>) -> Import "proc_exit" => Function::new_native(ctx, proc_exit), "proc_raise" => Function::new_native(ctx, proc_raise), "random_get" => Function::new_native(ctx, random_get), + "tty_get" => Function::new_native(ctx, tty_get), + "tty_set" => Function::new_native(ctx, tty_set), + "getcwd" => Function::new_native(ctx, getcwd), + "chdir" => Function::new_native(ctx, chdir), + "thread_spawn" => Function::new_native(ctx, thread_spawn), + "thread_sleep" => Function::new_native(ctx, thread_sleep), + "thread_id" => Function::new_native(ctx, thread_id), + "thread_join" => Function::new_native(ctx, thread_join), + "thread_parallelism" => Function::new_native(ctx, thread_parallelism), + "thread_exit" => Function::new_native(ctx, thread_exit), "sched_yield" => Function::new_native(ctx, sched_yield), + "getpid" => Function::new_native(ctx, getpid), + "process_spawn" => Function::new_native(ctx, process_spawn), + "bus_open_local" => Function::new_native(ctx, bus_open_local), + "bus_open_remote" => Function::new_native(ctx, bus_open_remote), + "bus_close" => Function::new_native(ctx, bus_close), + "bus_call" => Function::new_native(ctx, bus_call), + "bus_subcall" => Function::new_native(ctx, bus_subcall), + "bus_poll" => Function::new_native(ctx, bus_poll), + "call_reply" => Function::new_native(ctx, call_reply), + "call_fault" => Function::new_native(ctx, call_fault), + "call_close" => Function::new_native(ctx, call_close), + "ws_connect" => Function::new_native(ctx, ws_connect), + "http_request" => Function::new_native(ctx, http_request), + "http_status" => Function::new_native(ctx, http_status), + "port_bridge" => Function::new_native(ctx, port_bridge), + "port_unbridge" => Function::new_native(ctx, port_unbridge), + "port_dhcp_acquire" => Function::new_native(ctx, port_dhcp_acquire), + "port_addr_add" => Function::new_native(ctx, port_addr_add), + "port_addr_remove" => Function::new_native(ctx, port_addr_remove), + "port_addr_clear" => Function::new_native(ctx, port_addr_clear), + "port_addr_list" => Function::new_native(ctx, port_addr_list), + "port_mac" => Function::new_native(ctx, port_mac), + "port_gateway_set" => Function::new_native(ctx, port_gateway_set), + "port_route_add" => Function::new_native(ctx, port_route_add), + "port_route_remove" => Function::new_native(ctx, port_route_remove), + "port_route_clear" => Function::new_native(ctx, port_route_clear), + "port_route_list" => Function::new_native(ctx, port_route_list), + "sock_status" => Function::new_native(ctx, sock_status), + "sock_addr_local" => Function::new_native(ctx, sock_addr_local), + "sock_addr_peer" => Function::new_native(ctx, sock_addr_peer), + "sock_open" => Function::new_native(ctx, sock_open), + "sock_set_opt_flag" => Function::new_native(ctx, sock_set_opt_flag), + "sock_get_opt_flag" => Function::new_native(ctx, sock_get_opt_flag), + "sock_set_opt_time" => Function::new_native(ctx, sock_set_opt_time), + "sock_get_opt_time" => Function::new_native(ctx, sock_get_opt_time), + "sock_set_opt_size" => Function::new_native(ctx, sock_set_opt_size), + "sock_get_opt_size" => Function::new_native(ctx, sock_get_opt_size), + "sock_join_multicast_v4" => Function::new_native(ctx, sock_join_multicast_v4), + "sock_leave_multicast_v4" => Function::new_native(ctx, sock_leave_multicast_v4), + "sock_join_multicast_v6" => Function::new_native(ctx, sock_join_multicast_v6), + "sock_leave_multicast_v6" => Function::new_native(ctx, sock_leave_multicast_v6), + "sock_bind" => Function::new_native(ctx, sock_bind), + "sock_listen" => Function::new_native(ctx, sock_listen), + "sock_accept" => Function::new_native(ctx, sock_accept), + "sock_connect" => Function::new_native(ctx, sock_connect), "sock_recv" => Function::new_native(ctx, sock_recv), + "sock_recv_from" => Function::new_native(ctx, sock_recv_from), "sock_send" => Function::new_native(ctx, sock_send), + "sock_send_to" => Function::new_native(ctx, sock_send_to), + "sock_send_file" => Function::new_native(ctx, sock_send_file), "sock_shutdown" => Function::new_native(ctx, sock_shutdown), - } - } -} - -/// Combines a state generating function with the import list for snapshot 1 -fn generate_import_object_wasix32_v1(store: &Store, env: WasiEnv) -> Imports { - use self::wasix32::*; - imports! { - "wasix_32v1" => { - "args_get" => Function::new_native_with_env(store, env.clone(), args_get), - "args_sizes_get" => Function::new_native_with_env(store, env.clone(), args_sizes_get), - "clock_res_get" => Function::new_native_with_env(store, env.clone(), clock_res_get), - "clock_time_get" => Function::new_native_with_env(store, env.clone(), clock_time_get), - "environ_get" => Function::new_native_with_env(store, env.clone(), environ_get), - "environ_sizes_get" => Function::new_native_with_env(store, env.clone(), environ_sizes_get), - "fd_advise" => Function::new_native_with_env(store, env.clone(), fd_advise), - "fd_allocate" => Function::new_native_with_env(store, env.clone(), fd_allocate), - "fd_close" => Function::new_native_with_env(store, env.clone(), fd_close), - "fd_datasync" => Function::new_native_with_env(store, env.clone(), fd_datasync), - "fd_fdstat_get" => Function::new_native_with_env(store, env.clone(), fd_fdstat_get), - "fd_fdstat_set_flags" => Function::new_native_with_env(store, env.clone(), fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native_with_env(store, env.clone(), fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native_with_env(store, env.clone(), fd_filestat_get), - "fd_filestat_set_size" => Function::new_native_with_env(store, env.clone(), fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native_with_env(store, env.clone(), fd_filestat_set_times), - "fd_pread" => Function::new_native_with_env(store, env.clone(), fd_pread), - "fd_prestat_get" => Function::new_native_with_env(store, env.clone(), fd_prestat_get), - "fd_prestat_dir_name" => Function::new_native_with_env(store, env.clone(), fd_prestat_dir_name), - "fd_pwrite" => Function::new_native_with_env(store, env.clone(), fd_pwrite), - "fd_read" => Function::new_native_with_env(store, env.clone(), fd_read), - "fd_readdir" => Function::new_native_with_env(store, env.clone(), fd_readdir), - "fd_renumber" => Function::new_native_with_env(store, env.clone(), fd_renumber), - "fd_dup" => Function::new_native_with_env(store, env.clone(), fd_dup), - "fd_event" => Function::new_native_with_env(store, env.clone(), fd_event), - "fd_seek" => Function::new_native_with_env(store, env.clone(), fd_seek), - "fd_sync" => Function::new_native_with_env(store, env.clone(), fd_sync), - "fd_tell" => Function::new_native_with_env(store, env.clone(), fd_tell), - "fd_write" => Function::new_native_with_env(store, env.clone(), fd_write), - "fd_pipe" => Function::new_native_with_env(store, env.clone(), fd_pipe), - "path_create_directory" => Function::new_native_with_env(store, env.clone(), path_create_directory), - "path_filestat_get" => Function::new_native_with_env(store, env.clone(), path_filestat_get), - "path_filestat_set_times" => Function::new_native_with_env(store, env.clone(), path_filestat_set_times), - "path_link" => Function::new_native_with_env(store, env.clone(), path_link), - "path_open" => Function::new_native_with_env(store, env.clone(), path_open), - "path_readlink" => Function::new_native_with_env(store, env.clone(), path_readlink), - "path_remove_directory" => Function::new_native_with_env(store, env.clone(), path_remove_directory), - "path_rename" => Function::new_native_with_env(store, env.clone(), path_rename), - "path_symlink" => Function::new_native_with_env(store, env.clone(), path_symlink), - "path_unlink_file" => Function::new_native_with_env(store, env.clone(), path_unlink_file), - "poll_oneoff" => Function::new_native_with_env(store, env.clone(), poll_oneoff), - "proc_exit" => Function::new_native_with_env(store, env.clone(), proc_exit), - "proc_raise" => Function::new_native_with_env(store, env.clone(), proc_raise), - "random_get" => Function::new_native_with_env(store, env.clone(), random_get), - "tty_get" => Function::new_native_with_env(store, env.clone(), tty_get), - "tty_set" => Function::new_native_with_env(store, env.clone(), tty_set), - "getcwd" => Function::new_native_with_env(store, env.clone(), getcwd), - "chdir" => Function::new_native_with_env(store, env.clone(), chdir), - "thread_spawn" => Function::new_native_with_env(store, env.clone(), thread_spawn), - "thread_sleep" => Function::new_native_with_env(store, env.clone(), thread_sleep), - "thread_id" => Function::new_native_with_env(store, env.clone(), thread_id), - "thread_join" => Function::new_native_with_env(store, env.clone(), thread_join), - "thread_parallelism" => Function::new_native_with_env(store, env.clone(), thread_parallelism), - "thread_exit" => Function::new_native_with_env(store, env.clone(), thread_exit), - "sched_yield" => Function::new_native_with_env(store, env.clone(), sched_yield), - "getpid" => Function::new_native_with_env(store, env.clone(), getpid), - "process_spawn" => Function::new_native_with_env(store, env.clone(), process_spawn), - "bus_open_local" => Function::new_native_with_env(store, env.clone(), bus_open_local), - "bus_open_remote" => Function::new_native_with_env(store, env.clone(), bus_open_remote), - "bus_close" => Function::new_native_with_env(store, env.clone(), bus_close), - "bus_call" => Function::new_native_with_env(store, env.clone(), bus_call), - "bus_subcall" => Function::new_native_with_env(store, env.clone(), bus_subcall), - "bus_poll" => Function::new_native_with_env(store, env.clone(), bus_poll), - "call_reply" => Function::new_native_with_env(store, env.clone(), call_reply), - "call_fault" => Function::new_native_with_env(store, env.clone(), call_fault), - "call_close" => Function::new_native_with_env(store, env.clone(), call_close), - "ws_connect" => Function::new_native_with_env(store, env.clone(), ws_connect), - "http_request" => Function::new_native_with_env(store, env.clone(), http_request), - "http_status" => Function::new_native_with_env(store, env.clone(), http_status), - "port_bridge" => Function::new_native_with_env(store, env.clone(), port_bridge), - "port_unbridge" => Function::new_native_with_env(store, env.clone(), port_unbridge), - "port_dhcp_acquire" => Function::new_native_with_env(store, env.clone(), port_dhcp_acquire), - "port_addr_add" => Function::new_native_with_env(store, env.clone(), port_addr_add), - "port_addr_remove" => Function::new_native_with_env(store, env.clone(), port_addr_remove), - "port_addr_clear" => Function::new_native_with_env(store, env.clone(), port_addr_clear), - "port_addr_list" => Function::new_native_with_env(store, env.clone(), port_addr_list), - "port_mac" => Function::new_native_with_env(store, env.clone(), port_mac), - "port_gateway_set" => Function::new_native_with_env(store, env.clone(), port_gateway_set), - "port_route_add" => Function::new_native_with_env(store, env.clone(), port_route_add), - "port_route_remove" => Function::new_native_with_env(store, env.clone(), port_route_remove), - "port_route_clear" => Function::new_native_with_env(store, env.clone(), port_route_clear), - "port_route_list" => Function::new_native_with_env(store, env.clone(), port_route_list), - "sock_status" => Function::new_native_with_env(store, env.clone(), sock_status), - "sock_addr_local" => Function::new_native_with_env(store, env.clone(), sock_addr_local), - "sock_addr_peer" => Function::new_native_with_env(store, env.clone(), sock_addr_peer), - "sock_open" => Function::new_native_with_env(store, env.clone(), sock_open), - "sock_set_opt_flag" => Function::new_native_with_env(store, env.clone(), sock_set_opt_flag), - "sock_get_opt_flag" => Function::new_native_with_env(store, env.clone(), sock_get_opt_flag), - "sock_set_opt_time" => Function::new_native_with_env(store, env.clone(), sock_set_opt_time), - "sock_get_opt_time" => Function::new_native_with_env(store, env.clone(), sock_get_opt_time), - "sock_set_opt_size" => Function::new_native_with_env(store, env.clone(), sock_set_opt_size), - "sock_get_opt_size" => Function::new_native_with_env(store, env.clone(), sock_get_opt_size), - "sock_join_multicast_v4" => Function::new_native_with_env(store, env.clone(), sock_join_multicast_v4), - "sock_leave_multicast_v4" => Function::new_native_with_env(store, env.clone(), sock_leave_multicast_v4), - "sock_join_multicast_v6" => Function::new_native_with_env(store, env.clone(), sock_join_multicast_v6), - "sock_leave_multicast_v6" => Function::new_native_with_env(store, env.clone(), sock_leave_multicast_v6), - "sock_bind" => Function::new_native_with_env(store, env.clone(), sock_bind), - "sock_listen" => Function::new_native_with_env(store, env.clone(), sock_listen), - "sock_accept" => Function::new_native_with_env(store, env.clone(), sock_accept), - "sock_connect" => Function::new_native_with_env(store, env.clone(), sock_connect), - "sock_recv" => Function::new_native_with_env(store, env.clone(), sock_recv), - "sock_recv_from" => Function::new_native_with_env(store, env.clone(), sock_recv_from), - "sock_send" => Function::new_native_with_env(store, env.clone(), sock_send), - "sock_send_to" => Function::new_native_with_env(store, env.clone(), sock_send_to), - "sock_send_file" => Function::new_native_with_env(store, env.clone(), sock_send_file), - "sock_shutdown" => Function::new_native_with_env(store, env.clone(), sock_shutdown), - "resolve" => Function::new_native_with_env(store, env, resolve), - } - } -} - -fn generate_import_object_wasix64_v1(store: &Store, env: WasiEnv) -> Imports { - use self::wasix64::*; - imports! { - "wasix_64v1" => { - "args_get" => Function::new_native_with_env(store, env.clone(), args_get), - "args_sizes_get" => Function::new_native_with_env(store, env.clone(), args_sizes_get), - "clock_res_get" => Function::new_native_with_env(store, env.clone(), clock_res_get), - "clock_time_get" => Function::new_native_with_env(store, env.clone(), clock_time_get), - "environ_get" => Function::new_native_with_env(store, env.clone(), environ_get), - "environ_sizes_get" => Function::new_native_with_env(store, env.clone(), environ_sizes_get), - "fd_advise" => Function::new_native_with_env(store, env.clone(), fd_advise), - "fd_allocate" => Function::new_native_with_env(store, env.clone(), fd_allocate), - "fd_close" => Function::new_native_with_env(store, env.clone(), fd_close), - "fd_datasync" => Function::new_native_with_env(store, env.clone(), fd_datasync), - "fd_fdstat_get" => Function::new_native_with_env(store, env.clone(), fd_fdstat_get), - "fd_fdstat_set_flags" => Function::new_native_with_env(store, env.clone(), fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native_with_env(store, env.clone(), fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native_with_env(store, env.clone(), fd_filestat_get), - "fd_filestat_set_size" => Function::new_native_with_env(store, env.clone(), fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native_with_env(store, env.clone(), fd_filestat_set_times), - "fd_pread" => Function::new_native_with_env(store, env.clone(), fd_pread), - "fd_prestat_get" => Function::new_native_with_env(store, env.clone(), fd_prestat_get), - "fd_prestat_dir_name" => Function::new_native_with_env(store, env.clone(), fd_prestat_dir_name), - "fd_pwrite" => Function::new_native_with_env(store, env.clone(), fd_pwrite), - "fd_read" => Function::new_native_with_env(store, env.clone(), fd_read), - "fd_readdir" => Function::new_native_with_env(store, env.clone(), fd_readdir), - "fd_renumber" => Function::new_native_with_env(store, env.clone(), fd_renumber), - "fd_dup" => Function::new_native_with_env(store, env.clone(), fd_dup), - "fd_event" => Function::new_native_with_env(store, env.clone(), fd_event), - "fd_seek" => Function::new_native_with_env(store, env.clone(), fd_seek), - "fd_sync" => Function::new_native_with_env(store, env.clone(), fd_sync), - "fd_tell" => Function::new_native_with_env(store, env.clone(), fd_tell), - "fd_write" => Function::new_native_with_env(store, env.clone(), fd_write), - "fd_pipe" => Function::new_native_with_env(store, env.clone(), fd_pipe), - "path_create_directory" => Function::new_native_with_env(store, env.clone(), path_create_directory), - "path_filestat_get" => Function::new_native_with_env(store, env.clone(), path_filestat_get), - "path_filestat_set_times" => Function::new_native_with_env(store, env.clone(), path_filestat_set_times), - "path_link" => Function::new_native_with_env(store, env.clone(), path_link), - "path_open" => Function::new_native_with_env(store, env.clone(), path_open), - "path_readlink" => Function::new_native_with_env(store, env.clone(), path_readlink), - "path_remove_directory" => Function::new_native_with_env(store, env.clone(), path_remove_directory), - "path_rename" => Function::new_native_with_env(store, env.clone(), path_rename), - "path_symlink" => Function::new_native_with_env(store, env.clone(), path_symlink), - "path_unlink_file" => Function::new_native_with_env(store, env.clone(), path_unlink_file), - "poll_oneoff" => Function::new_native_with_env(store, env.clone(), poll_oneoff), - "proc_exit" => Function::new_native_with_env(store, env.clone(), proc_exit), - "proc_raise" => Function::new_native_with_env(store, env.clone(), proc_raise), - "random_get" => Function::new_native_with_env(store, env.clone(), random_get), - "tty_get" => Function::new_native_with_env(store, env.clone(), tty_get), - "tty_set" => Function::new_native_with_env(store, env.clone(), tty_set), - "getcwd" => Function::new_native_with_env(store, env.clone(), getcwd), - "chdir" => Function::new_native_with_env(store, env.clone(), chdir), - "thread_spawn" => Function::new_native_with_env(store, env.clone(), thread_spawn), - "thread_sleep" => Function::new_native_with_env(store, env.clone(), thread_sleep), - "thread_id" => Function::new_native_with_env(store, env.clone(), thread_id), - "thread_join" => Function::new_native_with_env(store, env.clone(), thread_join), - "thread_parallelism" => Function::new_native_with_env(store, env.clone(), thread_parallelism), - "thread_exit" => Function::new_native_with_env(store, env.clone(), thread_exit), - "sched_yield" => Function::new_native_with_env(store, env.clone(), sched_yield), - "getpid" => Function::new_native_with_env(store, env.clone(), getpid), - "process_spawn" => Function::new_native_with_env(store, env.clone(), process_spawn), - "bus_open_local" => Function::new_native_with_env(store, env.clone(), bus_open_local), - "bus_open_remote" => Function::new_native_with_env(store, env.clone(), bus_open_remote), - "bus_close" => Function::new_native_with_env(store, env.clone(), bus_close), - "bus_call" => Function::new_native_with_env(store, env.clone(), bus_call), - "bus_subcall" => Function::new_native_with_env(store, env.clone(), bus_subcall), - "bus_poll" => Function::new_native_with_env(store, env.clone(), bus_poll), - "call_reply" => Function::new_native_with_env(store, env.clone(), call_reply), - "call_fault" => Function::new_native_with_env(store, env.clone(), call_fault), - "call_close" => Function::new_native_with_env(store, env.clone(), call_close), - "ws_connect" => Function::new_native_with_env(store, env.clone(), ws_connect), - "http_request" => Function::new_native_with_env(store, env.clone(), http_request), - "http_status" => Function::new_native_with_env(store, env.clone(), http_status), - "port_bridge" => Function::new_native_with_env(store, env.clone(), port_bridge), - "port_unbridge" => Function::new_native_with_env(store, env.clone(), port_unbridge), - "port_dhcp_acquire" => Function::new_native_with_env(store, env.clone(), port_dhcp_acquire), - "port_addr_add" => Function::new_native_with_env(store, env.clone(), port_addr_add), - "port_addr_remove" => Function::new_native_with_env(store, env.clone(), port_addr_remove), - "port_addr_clear" => Function::new_native_with_env(store, env.clone(), port_addr_clear), - "port_addr_list" => Function::new_native_with_env(store, env.clone(), port_addr_list), - "port_mac" => Function::new_native_with_env(store, env.clone(), port_mac), - "port_gateway_set" => Function::new_native_with_env(store, env.clone(), port_gateway_set), - "port_route_add" => Function::new_native_with_env(store, env.clone(), port_route_add), - "port_route_remove" => Function::new_native_with_env(store, env.clone(), port_route_remove), - "port_route_clear" => Function::new_native_with_env(store, env.clone(), port_route_clear), - "port_route_list" => Function::new_native_with_env(store, env.clone(), port_route_list), - "sock_status" => Function::new_native_with_env(store, env.clone(), sock_status), - "sock_addr_local" => Function::new_native_with_env(store, env.clone(), sock_addr_local), - "sock_addr_peer" => Function::new_native_with_env(store, env.clone(), sock_addr_peer), - "sock_open" => Function::new_native_with_env(store, env.clone(), sock_open), - "sock_set_opt_flag" => Function::new_native_with_env(store, env.clone(), sock_set_opt_flag), - "sock_get_opt_flag" => Function::new_native_with_env(store, env.clone(), sock_get_opt_flag), - "sock_set_opt_time" => Function::new_native_with_env(store, env.clone(), sock_set_opt_time), - "sock_get_opt_time" => Function::new_native_with_env(store, env.clone(), sock_get_opt_time), - "sock_set_opt_size" => Function::new_native_with_env(store, env.clone(), sock_set_opt_size), - "sock_get_opt_size" => Function::new_native_with_env(store, env.clone(), sock_get_opt_size), - "sock_join_multicast_v4" => Function::new_native_with_env(store, env.clone(), sock_join_multicast_v4), - "sock_leave_multicast_v4" => Function::new_native_with_env(store, env.clone(), sock_leave_multicast_v4), - "sock_join_multicast_v6" => Function::new_native_with_env(store, env.clone(), sock_join_multicast_v6), - "sock_leave_multicast_v6" => Function::new_native_with_env(store, env.clone(), sock_leave_multicast_v6), - "sock_bind" => Function::new_native_with_env(store, env.clone(), sock_bind), - "sock_listen" => Function::new_native_with_env(store, env.clone(), sock_listen), - "sock_accept" => Function::new_native_with_env(store, env.clone(), sock_accept), - "sock_connect" => Function::new_native_with_env(store, env.clone(), sock_connect), - "sock_recv" => Function::new_native_with_env(store, env.clone(), sock_recv), - "sock_recv_from" => Function::new_native_with_env(store, env.clone(), sock_recv_from), - "sock_send" => Function::new_native_with_env(store, env.clone(), sock_send), - "sock_send_to" => Function::new_native_with_env(store, env.clone(), sock_send_to), - "sock_send_file" => Function::new_native_with_env(store, env.clone(), sock_send_file), - "sock_shutdown" => Function::new_native_with_env(store, env.clone(), sock_shutdown), - "resolve" => Function::new_native_with_env(store, env, resolve), + "resolve" => Function::new_native(ctx, resolve), } } } diff --git a/lib/wasi/src/macros.rs b/lib/wasi/src/macros.rs index 2368b2c8d61..bd6e6566d41 100644 --- a/lib/wasi/src/macros.rs +++ b/lib/wasi/src/macros.rs @@ -104,7 +104,7 @@ macro_rules! get_input_str { } macro_rules! get_input_str_bus { - ($memory:expr, $data:expr, $len:expr) => {{ - wasi_try_mem_bus!($data.read_utf8_string($memory, $len)) + ($ctx:expr, $memory:expr, $data:expr, $len:expr) => {{ + wasi_try_mem_bus!($data.read_utf8_string($ctx, $memory, $len)) }}; } diff --git a/lib/wasi/src/state/pipe.rs b/lib/wasi/src/state/pipe.rs index b49e4040812..29ccb9373ba 100644 --- a/lib/wasi/src/state/pipe.rs +++ b/lib/wasi/src/state/pipe.rs @@ -1,5 +1,6 @@ use crate::syscalls::types::*; use crate::syscalls::{read_bytes, write_bytes}; +use crate::WasiEnv; use bytes::{Buf, Bytes}; use std::convert::TryInto; use std::io::{self, Read}; @@ -7,7 +8,7 @@ use std::ops::DerefMut; use std::sync::mpsc; use std::sync::Mutex; use wasmer::MemorySize; -use wasmer::{Memory, WasmSlice}; +use wasmer::{ContextMut, Memory, WasmSlice}; #[derive(Debug)] pub struct WasiPipe { @@ -41,6 +42,7 @@ impl WasiPipe { pub fn recv( &mut self, + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, iov: WasmSlice<__wasi_iovec_t>, ) -> Result { @@ -49,7 +51,7 @@ impl WasiPipe { let buf_len = buf.len(); if buf_len > 0 { let reader = buf.as_ref(); - let read = read_bytes(reader, memory, iov).map(|_| buf_len as usize)?; + let read = read_bytes(ctx, reader, memory, iov).map(|_| buf_len as usize)?; buf.advance(read); return Ok(read); } @@ -62,6 +64,7 @@ impl WasiPipe { pub fn send( &mut self, + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, iov: WasmSlice<__wasi_ciovec_t>, ) -> Result { @@ -72,7 +75,7 @@ impl WasiPipe { .sum(); let buf_len: usize = buf_len.try_into().map_err(|_| __WASI_EINVAL)?; let mut buf = Vec::with_capacity(buf_len); - write_bytes(&mut buf, memory, iov)?; + write_bytes(ctx, &mut buf, memory, iov)?; let tx = self.tx.lock().unwrap(); tx.send(buf).map_err(|_| __WASI_EIO)?; Ok(buf_len) diff --git a/lib/wasi/src/state/socket.rs b/lib/wasi/src/state/socket.rs index 290b154b766..d2ab0e7ae6a 100644 --- a/lib/wasi/src/state/socket.rs +++ b/lib/wasi/src/state/socket.rs @@ -1,6 +1,7 @@ use super::types::net_error_into_wasi_err; use crate::syscalls::types::*; use crate::syscalls::{read_bytes, write_bytes}; +use crate::WasiEnv; use bytes::{Buf, Bytes}; use std::convert::TryInto; use std::io::{self, Read}; @@ -10,7 +11,7 @@ use std::sync::Mutex; use std::time::Duration; #[allow(unused_imports)] use tracing::{debug, error, info, warn}; -use wasmer::{Memory, MemorySize, WasmPtr, WasmSlice}; +use wasmer::{ContextMut, Memory, MemorySize, WasmPtr, WasmSlice}; use wasmer_vnet::{net_error_into_io_err, TimeType}; use wasmer_vnet::{ IpCidr, IpRoute, SocketHttpRequest, VirtualIcmpSocket, VirtualNetworking, VirtualRawSocket, @@ -768,6 +769,7 @@ impl InodeSocket { pub fn send( &mut self, + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, iov: WasmSlice<__wasi_ciovec_t>, ) -> Result { @@ -778,7 +780,7 @@ impl InodeSocket { .sum(); let buf_len: usize = buf_len.try_into().map_err(|_| __WASI_EINVAL)?; let mut buf = Vec::with_capacity(buf_len); - write_bytes(&mut buf, memory, iov)?; + write_bytes(ctx, &mut buf, memory, iov)?; match &mut self.kind { InodeSocketKind::HttpRequest(sock, ty) => { let sock = sock.get_mut().unwrap(); @@ -852,11 +854,12 @@ impl InodeSocket { pub fn send_to( &mut self, + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, iov: WasmSlice<__wasi_ciovec_t>, addr: WasmPtr<__wasi_addr_port_t, M>, ) -> Result { - let (addr_ip, addr_port) = read_ip_port(memory, addr)?; + let (addr_ip, addr_port) = read_ip_port(ctx, memory, addr)?; let addr = SocketAddr::new(addr_ip, addr_port); let buf_len: M::Offset = iov .iter() @@ -865,7 +868,7 @@ impl InodeSocket { .sum(); let buf_len: usize = buf_len.try_into().map_err(|_| __WASI_EINVAL)?; let mut buf = Vec::with_capacity(buf_len); - write_bytes(&mut buf, memory, iov)?; + write_bytes(ctx, &mut buf, memory, iov)?; match &mut self.kind { InodeSocketKind::Icmp(sock) => sock .send_to(Bytes::from(buf), addr) @@ -882,6 +885,7 @@ impl InodeSocket { pub fn recv( &mut self, + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, iov: WasmSlice<__wasi_iovec_t>, ) -> Result { @@ -890,7 +894,7 @@ impl InodeSocket { let buf_len = buf.len(); if buf_len > 0 { let reader = buf.as_ref(); - let read = read_bytes(reader, memory, iov).map(|_| buf_len)?; + let read = read_bytes(ctx, reader, memory, iov).map(|_| buf_len)?; if let InodeSocketKind::TcpStream(..) = &self.kind { buf.advance(read); } else { @@ -951,6 +955,7 @@ impl InodeSocket { pub fn recv_from( &mut self, + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, iov: WasmSlice<__wasi_iovec_t>, addr: WasmPtr<__wasi_addr_port_t, M>, @@ -959,11 +964,11 @@ impl InodeSocket { if let Some(buf) = self.read_buffer.as_mut() { if !buf.is_empty() { let reader = buf.as_ref(); - let ret = read_bytes(reader, memory, iov)?; + let ret = read_bytes(ctx, reader, memory, iov)?; let peer = self .read_addr .unwrap_or_else(|| SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0)); - write_ip_port(memory, addr, peer.ip(), peer.port())?; + write_ip_port(ctx, memory, addr, peer.ip(), peer.port())?; return Ok(ret); } } @@ -1130,10 +1135,11 @@ impl Drop for InodeSocket { #[allow(dead_code)] pub(crate) fn read_ip( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_addr_t, M>, ) -> Result { - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.u.octs; @@ -1148,10 +1154,11 @@ pub(crate) fn read_ip( } pub(crate) fn read_ip_v4( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_addr_ip4_t, M>, ) -> Result { - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.octs; @@ -1159,10 +1166,11 @@ pub(crate) fn read_ip_v4( } pub(crate) fn read_ip_v6( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_addr_ip6_t, M>, ) -> Result { - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(addr.segs) }; @@ -1170,6 +1178,7 @@ pub(crate) fn read_ip_v6( } pub(crate) fn write_ip( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_addr_t, M>, ip: IpAddr, @@ -1193,17 +1202,18 @@ pub(crate) fn write_ip( } }; - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); addr_ptr.write(ip).map_err(crate::mem_error_to_wasi)?; Ok(()) } #[allow(dead_code)] pub(crate) fn read_cidr( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_cidr_t, M>, ) -> Result { - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.u.octs; @@ -1231,6 +1241,7 @@ pub(crate) fn read_cidr( #[allow(dead_code)] pub(crate) fn write_cidr( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_cidr_t, M>, cidr: IpCidr, @@ -1262,16 +1273,17 @@ pub(crate) fn write_cidr( } }; - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); addr_ptr.write(cidr).map_err(crate::mem_error_to_wasi)?; Ok(()) } pub(crate) fn read_ip_port( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_addr_port_t, M>, ) -> Result<(IpAddr, u16), __wasi_errno_t> { - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; let o = addr.u.octs; @@ -1299,6 +1311,7 @@ pub(crate) fn read_ip_port( #[allow(dead_code)] pub(crate) fn write_ip_port( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_addr_port_t, M>, ip: IpAddr, @@ -1331,17 +1344,18 @@ pub(crate) fn write_ip_port( } }; - let addr_ptr = ptr.deref(memory); + let addr_ptr = ptr.deref(ctx, memory); addr_ptr.write(ipport).map_err(crate::mem_error_to_wasi)?; Ok(()) } #[allow(dead_code)] pub(crate) fn read_route( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_route_t, M>, ) -> Result { - let route_ptr = ptr.deref(memory); + let route_ptr = ptr.deref(ctx, memory); let route = route_ptr.read().map_err(crate::mem_error_to_wasi)?; Ok(IpRoute { @@ -1393,6 +1407,7 @@ pub(crate) fn read_route( } pub(crate) fn write_route( + ctx: &ContextMut<'_, WasiEnv>, memory: &Memory, ptr: WasmPtr<__wasi_route_t, M>, route: IpRoute, @@ -1471,7 +1486,7 @@ pub(crate) fn write_route( expires_at, }; - let route_ptr = ptr.deref(memory); + let route_ptr = ptr.deref(ctx, memory); route_ptr.write(route).map_err(crate::mem_error_to_wasi)?; Ok(()) } diff --git a/lib/wasi/src/syscalls/legacy/snapshot0.rs b/lib/wasi/src/syscalls/legacy/snapshot0.rs index e5d9c1ee0bb..96a1eed7090 100644 --- a/lib/wasi/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasi/src/syscalls/legacy/snapshot0.rs @@ -27,7 +27,7 @@ pub fn fd_filestat_get( // Set up complete, make the call with the pointer that will write to the // struct and some unrelated memory after the struct. - let result = syscalls::fd_filestat_get::(env, fd, new_buf); + let result = syscalls::fd_filestat_get::(ctx.as_context_mut(), fd, new_buf); // reborrow memory let env = ctx.data(); diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index e6d3abcae05..1c2e04f3b11 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -17,7 +17,7 @@ pub mod wasm32; pub mod windows; pub mod legacy; -pub mod wasi; +//pub mod wasi; pub mod wasix32; pub mod wasix64; @@ -141,7 +141,7 @@ fn has_rights(rights_set: __wasi_rights_t, rights_check_set: __wasi_rights_t) -> } fn __sock_actor( - ctx: ContextMut<'_, WasiEnv>, + ctx: &ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, rights: __wasi_rights_t, actor: F, @@ -149,6 +149,7 @@ fn __sock_actor( where F: FnOnce(&crate::state::InodeSocket) -> Result, { + let env = ctx.data(); let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(0); let fd_entry = state.fs.get_fd(sock)?; @@ -173,7 +174,7 @@ where } fn __sock_actor_mut( - ctx: ContextMut<'_, WasiEnv>, + ctx: &ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, rights: __wasi_rights_t, actor: F, @@ -181,6 +182,7 @@ fn __sock_actor_mut( where F: FnOnce(&mut crate::state::InodeSocket) -> Result, { + let env = ctx.data(); let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(0); let fd_entry = state.fs.get_fd(sock)?; @@ -205,7 +207,7 @@ where } fn __sock_upgrade( - ctx: ContextMut<'_, WasiEnv>, + ctx: &ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, rights: __wasi_rights_t, actor: F, @@ -215,6 +217,7 @@ where &mut crate::state::InodeSocket, ) -> Result, __wasi_errno_t>, { + let env = ctx.data(); let (_, state, inodes) = env.get_memory_and_wasi_state_and_inodes(0); let fd_entry = state.fs.get_fd(sock)?; @@ -252,7 +255,7 @@ fn write_buffer_array( ) -> __wasi_errno_t { let env = ctx.data(); let memory = env.memory(); - let ptrs = wasi_try_mem!(ptr_buffer.slice(&ctx, memory, wasi_try!(to_offset::(from.len())))); + let ptrs = wasi_try_mem!(ptr_buffer.slice(ctx, memory, wasi_try!(to_offset::(from.len())))); let mut current_buffer_offset = 0usize; for ((i, sub_buffer), ptr) in from.iter().enumerate().zip(ptrs.iter()) { @@ -263,12 +266,12 @@ fn write_buffer_array( wasi_try_mem!(ptr.write(new_ptr)); let data = - wasi_try_mem!(new_ptr.slice(&ctx, memory, wasi_try!(to_offset::(sub_buffer.len())))); - wasi_try_mem!(data.write_slice(&ctx, sub_buffer)); + wasi_try_mem!(new_ptr.slice(ctx, memory, wasi_try!(to_offset::(sub_buffer.len())))); + wasi_try_mem!(data.write_slice(sub_buffer)); wasi_try_mem!(wasi_try_mem!( new_ptr.add_offset(wasi_try!(to_offset::(sub_buffer.len()))) ) - .write(&ctx, memory, 0)); + .write(ctx, memory, 0)); current_buffer_offset += sub_buffer.len() + 1; } @@ -880,10 +883,10 @@ pub fn fd_pread( } } Kind::Socket { socket } => { - wasi_try_ok!(socket.recv(memory, iovs), env) + wasi_try_ok!(socket.recv(&ctx, memory, iovs), env) } Kind::Pipe { pipe } => { - wasi_try_ok!(pipe.recv(memory, iovs), env) + wasi_try_ok!(pipe.recv(&ctx, memory, iovs), env) } Kind::EventNotifications { .. } => return Ok(__WASI_EINVAL), Kind::Dir { .. } | Kind::Root { .. } => return Ok(__WASI_EISDIR), @@ -922,11 +925,7 @@ pub fn fd_prestat_get( let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(0); let prestat_ptr = buf.deref(&ctx, memory); - wasi_try_mem!(prestat_ptr.write( - &ctx, - memory, - wasi_try!(state.fs.prestat_fd(inodes.deref(), fd)) - )); + wasi_try_mem!(prestat_ptr.write(wasi_try!(state.fs.prestat_fd(inodes.deref(), fd)))); __WASI_ESUCCESS } @@ -1063,10 +1062,10 @@ pub fn fd_pwrite( } } Kind::Socket { socket } => { - wasi_try_ok!(socket.send(memory, iovs_arr), env) + wasi_try_ok!(socket.send(&ctx, memory, iovs_arr), env) } Kind::Pipe { pipe } => { - wasi_try_ok!(pipe.send(memory, iovs_arr), env) + wasi_try_ok!(pipe.send(&ctx, memory, iovs_arr), env) } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify @@ -1162,10 +1161,10 @@ pub fn fd_read( } } Kind::Socket { socket } => { - wasi_try_ok!(socket.recv(memory, iovs_arr), env) + wasi_try_ok!(socket.recv(&ctx, memory, iovs_arr), env) } Kind::Pipe { pipe } => { - wasi_try_ok!(pipe.recv(memory, iovs_arr), env) + wasi_try_ok!(pipe.recv(&ctx, memory, iovs_arr), env) } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify @@ -1430,10 +1429,11 @@ pub fn fd_dup( ) -> __wasi_errno_t { debug!("wasi::fd_dup"); + let env = ctx.data(); let (memory, state) = env.get_memory_and_wasi_state(0); let fd = wasi_try!(state.fs.clone_fd(fd)); - wasi_try_mem!(ret_fd.write(memory, fd)); + wasi_try_mem!(ret_fd.write(&ctx, memory, fd)); __WASI_ESUCCESS } @@ -1448,6 +1448,7 @@ pub fn fd_event( ) -> __wasi_errno_t { debug!("wasi::fd_event"); + let env = ctx.data(); let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(0); let kind = Kind::EventNotifications { @@ -1465,7 +1466,7 @@ pub fn fd_event( let rights = __WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_POLL_FD_READWRITE; let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); - wasi_try_mem!(ret_fd.write(memory, fd)); + wasi_try_mem!(ret_fd.write(&ctx, memory, fd)); __WASI_ESUCCESS } @@ -1711,10 +1712,10 @@ pub fn fd_write( } } Kind::Socket { socket } => { - wasi_try_ok!(socket.send(memory, iovs_arr), env) + wasi_try_ok!(socket.send(&ctx, memory, iovs_arr), env) } Kind::Pipe { pipe } => { - wasi_try_ok!(pipe.send(memory, iovs_arr), env) + wasi_try_ok!(pipe.send(&ctx, memory, iovs_arr), env) } Kind::Dir { .. } | Kind::Root { .. } => { // TODO: verify @@ -1786,6 +1787,7 @@ pub fn fd_pipe( ) -> __wasi_errno_t { trace!("wasi::fd_pipe"); + let env = ctx.data(); let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(0); let (pipe1, pipe2) = WasiPipe::new(); @@ -1807,8 +1809,8 @@ pub fn fd_pipe( let fd1 = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode1)); let fd2 = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode2)); - wasi_try_mem!(ro_fd1.write(memory, fd1)); - wasi_try_mem!(ro_fd2.write(memory, fd2)); + wasi_try_mem!(ro_fd1.write(&ctx, memory, fd1)); + wasi_try_mem!(ro_fd2.write(&ctx, memory, fd2)); __WASI_ESUCCESS } @@ -2495,7 +2497,7 @@ pub fn path_readlink( let out = wasi_try_mem!(buf.slice(&ctx, memory, wasi_try!(to_offset::(bytes.len())))); - wasi_try_mem!(out.write_slice(bytes)); + wasi_try_mem!(out.write_slice(&bytes)); // should we null terminate this? let bytes_len: M::Offset = @@ -3210,7 +3212,7 @@ pub fn poll_oneoff( } } let events_seen: M::Offset = wasi_try_ok!(events_seen.try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem_ok!(out_ptr.write(&ctx, events_seen)); + wasi_try_mem_ok!(out_ptr.write(events_seen)); Ok(__WASI_ESUCCESS) } @@ -3239,8 +3241,9 @@ pub fn proc_raise(ctx: ContextMut<'_, WasiEnv>, sig: __wasi_signal_t) -> __wasi_ /// ### `sched_yield()` /// Yields execution of the thread -pub fn sched_yield(env: &WasiEnv) -> Result<__wasi_errno_t, WasiError> { +pub fn sched_yield(ctx: ContextMut<'_, WasiEnv>) -> Result<__wasi_errno_t, WasiError> { trace!("wasi::sched_yield"); + let env = ctx.data(); env.yield_now()?; Ok(__WASI_ESUCCESS) } @@ -3403,7 +3406,7 @@ pub fn getcwd( u8_buffer }; - wasi_try_mem!(path_slice.write_slice(&ctx, &cur_dir[..])); + wasi_try_mem!(path_slice.write_slice(&cur_dir[..])); __WASI_ESUCCESS } @@ -3458,12 +3461,14 @@ pub fn thread_spawn( if method.as_str() != "_thread_start" { return __WASI_ENOTCAPABLE; }; + /* let funct = unsafe { if env.thread_start_ref().is_none() { return __WASI_EADDRNOTAVAIL; } env.thread_start_ref_unchecked() }; + */ let reactor = match reactor { __WASI_BOOL_FALSE => false, @@ -3481,6 +3486,7 @@ pub fn thread_spawn( wasi_try!(env .runtime .thread_spawn(Box::new(move || { + /* if let Some(funct) = sub_env.thread_start_ref() { if let Err(err) = funct.call(user_data) { warn!("thread failed: {}", err); @@ -3492,6 +3498,7 @@ pub fn thread_spawn( std::mem::forget(sub_thread); return; } + */ let thread = { let mut guard = sub_env.state.threading.lock().unwrap(); @@ -3514,7 +3521,7 @@ pub fn thread_spawn( }; let child: __wasi_tid_t = child.into(); - wasi_try_mem!(ret_tid.write(memory, child)); + wasi_try_mem!(ret_tid.write(&ctx, memory, child)); __WASI_ESUCCESS } @@ -3530,6 +3537,7 @@ pub fn thread_sleep( ) -> Result<__wasi_errno_t, WasiError> { debug!("wasi::thread_sleep"); + let env = ctx.data(); let duration = Duration::from_nanos(duration as u64); env.sleep(duration)?; Ok(__WASI_ESUCCESS) @@ -3546,7 +3554,7 @@ pub fn thread_id( let env = ctx.data(); let tid: __wasi_tid_t = env.id.into(); - wasi_try_mem!(ret_tid.write(env.memory(), tid)); + wasi_try_mem!(ret_tid.write(&ctx, env.memory(), tid)); __WASI_ESUCCESS } @@ -3563,6 +3571,7 @@ pub fn thread_join( ) -> Result<__wasi_errno_t, WasiError> { debug!("wasi::thread_join"); + let env = ctx.data(); let tid: WasiThreadId = tid.into(); let other_thread = { let guard = env.state.threading.lock().unwrap(); @@ -3596,7 +3605,7 @@ pub fn thread_parallelism( err })); let parallelism: M::Offset = wasi_try!(parallelism.try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem!(ret_parallelism.write(env.memory(), parallelism)); + wasi_try_mem!(ret_parallelism.write(&ctx, env.memory(), parallelism)); __WASI_ESUCCESS } @@ -3611,7 +3620,7 @@ pub fn getpid( let env = ctx.data(); let pid = env.runtime().getpid(); if let Some(pid) = pid { - wasi_try_mem!(ret_pid.write(env.memory(), pid as __wasi_pid_t)); + wasi_try_mem!(ret_pid.write(&ctx, env.memory(), pid as __wasi_pid_t)); __WASI_ESUCCESS } else { __WASI_ENOTSUP @@ -3673,10 +3682,10 @@ pub fn process_spawn( let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory(); - let name = unsafe { get_input_str_bus!(memory, name, name_len) }; - let args = unsafe { get_input_str_bus!(memory, args, args_len) }; - let preopen = unsafe { get_input_str_bus!(memory, preopen, preopen_len) }; - let working_dir = unsafe { get_input_str_bus!(memory, working_dir, working_dir_len) }; + let name = unsafe { get_input_str_bus!(&ctx, memory, name, name_len) }; + let args = unsafe { get_input_str_bus!(&ctx, memory, args, args_len) }; + let preopen = unsafe { get_input_str_bus!(&ctx, memory, preopen, preopen_len) }; + let working_dir = unsafe { get_input_str_bus!(&ctx, memory, working_dir, working_dir_len) }; let chroot = chroot == __WASI_BOOL_TRUE; debug!("wasi::process_spawn (name={})", name); @@ -3738,7 +3747,7 @@ pub fn process_spawn( stderr, }; - wasi_try_mem_bus!(ret_handles.write(memory, handles)); + wasi_try_mem_bus!(ret_handles.write(&ctx, memory, handles)); __BUS_ESUCCESS } @@ -3765,7 +3774,7 @@ pub fn bus_open_local( let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory(); - let name = unsafe { get_input_str_bus!(memory, name, name_len) }; + let name = unsafe { get_input_str_bus!(&ctx, memory, name, name_len) }; let reuse = reuse == __WASI_BOOL_TRUE; debug!("wasi::bus_open_local (name={}, reuse={})", name, reuse); @@ -3800,9 +3809,9 @@ pub fn bus_open_remote( let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory(); - let name = unsafe { get_input_str_bus!(memory, name, name_len) }; - let instance = unsafe { get_input_str_bus!(memory, instance, instance_len) }; - let token = unsafe { get_input_str_bus!(memory, token, token_len) }; + let name = unsafe { get_input_str_bus!(&ctx, memory, name, name_len) }; + let instance = unsafe { get_input_str_bus!(&ctx, memory, instance, instance_len) }; + let token = unsafe { get_input_str_bus!(&ctx, memory, token, token_len) }; let reuse = reuse == __WASI_BOOL_TRUE; debug!( "wasi::bus_open_remote (name={}, reuse={}, instance={})", @@ -3830,7 +3839,7 @@ fn bus_open_local_internal( let guard = env.state.threading.lock().unwrap(); if let Some(bid) = guard.process_reuse.get(&name) { if guard.processes.contains_key(bid) { - wasi_try_mem_bus!(ret_bid.write(memory, (*bid).into())); + wasi_try_mem_bus!(ret_bid.write(&ctx, memory, (*bid).into())); return __BUS_ESUCCESS; } } @@ -3865,7 +3874,7 @@ fn bus_open_local_internal( bid }; - wasi_try_mem_bus!(ret_bid.write(memory, bid.into())); + wasi_try_mem_bus!(ret_bid.write(&ctx, memory, bid.into())); __BUS_ESUCCESS } @@ -3879,6 +3888,7 @@ pub fn bus_close(ctx: ContextMut<'_, WasiEnv>, bid: __wasi_bid_t) -> __bus_errno trace!("wasi::bus_close (bid={})", bid); let bid: WasiBusProcessId = bid.into(); + let env = ctx.data(); let mut guard = env.state.threading.lock().unwrap(); guard.processes.remove(&bid); @@ -3910,7 +3920,7 @@ pub fn bus_call( let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory(); - let topic = unsafe { get_input_str_bus!(memory, topic, topic_len) }; + let topic = unsafe { get_input_str_bus!(&ctx, memory, topic, topic_len) }; let keep_alive = keep_alive == __WASI_BOOL_TRUE; trace!( "wasi::bus_call (bid={}, topic={}, buf_len={})", @@ -3947,7 +3957,7 @@ pub fn bus_subcall( let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory(); - let topic = unsafe { get_input_str_bus!(memory, topic, topic_len) }; + let topic = unsafe { get_input_str_bus!(&ctx, memory, topic, topic_len) }; let keep_alive = keep_alive == __WASI_BOOL_TRUE; trace!( "wasi::bus_subcall (parent={}, topic={}, buf_len={})", @@ -3985,7 +3995,7 @@ pub fn bus_poll( let env = ctx.data(); let bus = env.runtime.bus(); let memory = env.memory(); - let malloc = unsafe { get_input_str_bus!(memory, malloc, malloc_len) }; + let malloc = unsafe { get_input_str_bus!(&ctx, memory, malloc, malloc_len) }; trace!("wasi::bus_poll (timeout={}, malloc={})", timeout, malloc); __BUS_EUNSUPPORTED @@ -4008,6 +4018,7 @@ pub fn call_reply( buf: WasmPtr, buf_len: M::Offset, ) -> __bus_errno_t { + let env = ctx.data(); let bus = env.runtime.bus(); trace!( "wasi::call_reply (cid={}, format={}, data_len={})", @@ -4032,6 +4043,7 @@ pub fn call_fault( cid: __wasi_cid_t, fault: __bus_errno_t, ) -> __bus_errno_t { + let env = ctx.data(); let bus = env.runtime.bus(); debug!("wasi::call_fault (cid={}, fault={})", cid, fault); @@ -4044,6 +4056,7 @@ pub fn call_fault( /// /// * `cid` - Handle of the bus call handle to be dropped pub fn call_close(ctx: ContextMut<'_, WasiEnv>, cid: __wasi_cid_t) -> __bus_errno_t { + let env = ctx.data(); let bus = env.runtime.bus(); trace!("wasi::call_close (cid={})", cid); @@ -4091,7 +4104,7 @@ pub fn ws_connect( let rights = super::state::all_socket_rights(); let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); - wasi_try_mem!(ret_sock.write(memory, fd)); + wasi_try_mem!(ret_sock.write(&ctx, memory, fd)); __WASI_ESUCCESS } @@ -4206,7 +4219,7 @@ pub fn http_request( hdr: wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode_hdr)), }; - wasi_try_mem!(ret_handles.write(memory, handles)); + wasi_try_mem!(ret_handles.write(&ctx, memory, handles)); __WASI_ESUCCESS } @@ -4228,9 +4241,9 @@ pub fn http_status( let env = ctx.data(); let memory = env.memory(); - let ref_status = status.deref(memory); + let ref_status = status.deref(&ctx, memory); - let http_status = wasi_try!(__sock_actor(ctx, sock, 0, |socket| { + let http_status = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.http_status() })); @@ -4288,16 +4301,18 @@ pub fn port_bridge( /// ### `port_unbridge()` /// Disconnects from a remote network -pub fn port_unbridge(env: &WasiEnv) -> __wasi_errno_t { +pub fn port_unbridge(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { debug!("wasi::port_unbridge"); + let env = ctx.data(); wasi_try!(env.net().unbridge().map_err(net_error_into_wasi_err)); __WASI_ESUCCESS } /// ### `port_dhcp_acquire()` /// Acquires a set of IP addresses using DHCP -pub fn port_dhcp_acquire(env: &WasiEnv) -> __wasi_errno_t { +pub fn port_dhcp_acquire(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { debug!("wasi::port_dhcp_acquire"); + let env = ctx.data(); wasi_try!(env.net().dhcp_acquire().map_err(net_error_into_wasi_err)); __WASI_ESUCCESS } @@ -4315,7 +4330,7 @@ pub fn port_addr_add( debug!("wasi::port_addr_add"); let env = ctx.data(); let memory = env.memory(); - let cidr = wasi_try!(super::state::read_cidr(memory, ip)); + let cidr = wasi_try!(super::state::read_cidr(&ctx, memory, ip)); wasi_try!(env .net() .ip_add(cidr.ip, cidr.prefix) @@ -4336,15 +4351,16 @@ pub fn port_addr_remove( debug!("wasi::port_addr_remove"); let env = ctx.data(); let memory = env.memory(); - let ip = wasi_try!(super::state::read_ip(memory, ip)); + let ip = wasi_try!(super::state::read_ip(&ctx, memory, ip)); wasi_try!(env.net().ip_remove(ip).map_err(net_error_into_wasi_err)); __WASI_ESUCCESS } /// ### `port_addr_clear()` /// Clears all the addresses on the local port -pub fn port_addr_clear(env: &WasiEnv) -> __wasi_errno_t { +pub fn port_addr_clear(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { debug!("wasi::port_addr_clear"); + let env = ctx.data(); wasi_try!(env.net().ip_clear().map_err(net_error_into_wasi_err)); __WASI_ESUCCESS } @@ -4360,7 +4376,7 @@ pub fn port_mac( let memory = env.memory(); let mac = wasi_try!(env.net().mac().map_err(net_error_into_wasi_err)); let mac = __wasi_hardwareaddress_t { octs: mac }; - wasi_try_mem!(ret_mac.write(memory, mac)); + wasi_try_mem!(ret_mac.write(&ctx, memory, mac)); __WASI_ESUCCESS } @@ -4385,7 +4401,7 @@ pub fn port_addr_list( debug!("wasi::port_addr_list"); let env = ctx.data(); let memory = env.memory(); - let max_addrs = wasi_try_mem!(naddrs.read(memory)); + let max_addrs = wasi_try_mem!(naddrs.read(&ctx, memory)); let max_addrs: u64 = wasi_try!(max_addrs.try_into().map_err(|_| __WASI_EOVERFLOW)); let ref_addrs = wasi_try_mem!(addrs.slice(&ctx, memory, wasi_try!(to_offset::(max_addrs as usize)))); @@ -4393,14 +4409,14 @@ pub fn port_addr_list( let addrs = wasi_try!(env.net().ip_list().map_err(net_error_into_wasi_err)); let addrs_len: M::Offset = wasi_try!(addrs.len().try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem!(naddrs.write(memory, addrs_len)); + wasi_try_mem!(naddrs.write(&ctx, memory, addrs_len)); if addrs.len() as u64 > max_addrs { return __WASI_EOVERFLOW; } for n in 0..addrs.len() { let nip = ref_addrs.index(n as u64); - super::state::write_cidr(memory, nip.as_ptr::(), *addrs.get(n).unwrap()); + super::state::write_cidr(&ctx, memory, nip.as_ptr::(), *addrs.get(n).unwrap()); } __WASI_ESUCCESS @@ -4419,7 +4435,7 @@ pub fn port_gateway_set( debug!("wasi::port_gateway_set"); let env = ctx.data(); let memory = env.memory(); - let ip = wasi_try!(super::state::read_ip(memory, ip)); + let ip = wasi_try!(super::state::read_ip(&ctx, memory, ip)); wasi_try!(env.net().gateway_set(ip).map_err(net_error_into_wasi_err)); __WASI_ESUCCESS @@ -4437,15 +4453,15 @@ pub fn port_route_add( debug!("wasi::port_route_add"); let env = ctx.data(); let memory = env.memory(); - let cidr = wasi_try!(super::state::read_cidr(memory, cidr)); - let via_router = wasi_try!(super::state::read_ip(memory, via_router)); - let preferred_until = wasi_try_mem!(preferred_until.read(memory)); + let cidr = wasi_try!(super::state::read_cidr(&ctx, memory, cidr)); + let via_router = wasi_try!(super::state::read_ip(&ctx, memory, via_router)); + let preferred_until = wasi_try_mem!(preferred_until.read(&ctx, memory)); let preferred_until = match preferred_until.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(preferred_until.u)), _ => return __WASI_EINVAL, }; - let expires_at = wasi_try_mem!(expires_at.read(memory)); + let expires_at = wasi_try_mem!(expires_at.read(&ctx, memory)); let expires_at = match expires_at.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(expires_at.u)), @@ -4468,15 +4484,16 @@ pub fn port_route_remove( debug!("wasi::port_route_remove"); let env = ctx.data(); let memory = env.memory(); - let ip = wasi_try!(super::state::read_ip(memory, ip)); + let ip = wasi_try!(super::state::read_ip(&ctx, memory, ip)); wasi_try!(env.net().route_remove(ip).map_err(net_error_into_wasi_err)); __WASI_ESUCCESS } /// ### `port_route_clear()` /// Clears all the routes in the local port -pub fn port_route_clear(env: &WasiEnv) -> __wasi_errno_t { +pub fn port_route_clear(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { debug!("wasi::port_route_clear"); + let env = ctx.data(); wasi_try!(env.net().route_clear().map_err(net_error_into_wasi_err)); __WASI_ESUCCESS } @@ -4498,7 +4515,7 @@ pub fn port_route_list( debug!("wasi::port_route_list"); let env = ctx.data(); let memory = env.memory(); - let nroutes = nroutes.deref(memory); + let nroutes = nroutes.deref(&ctx, memory); let max_routes: usize = wasi_try!(wasi_try_mem!(nroutes.read()) .try_into() .map_err(|_| __WASI_EINVAL)); @@ -4515,7 +4532,12 @@ pub fn port_route_list( for n in 0..routes.len() { let nroute = ref_routes.index(n as u64); - super::state::write_route(memory, nroute.as_ptr::(), routes.get(n).unwrap().clone()); + super::state::write_route( + &ctx, + memory, + nroute.as_ptr::(), + routes.get(n).unwrap().clone(), + ); } __WASI_ESUCCESS @@ -4572,7 +4594,8 @@ pub fn sock_status( WasiSocketStatus::Failed => __WASI_SOCK_STATUS_FAILED, }; - wasi_try_mem!(ret_status.write(ctx.memory(), status)); + let env = ctx.data(); + wasi_try_mem!(ret_status.write(&ctx, env.memory(), status)); __WASI_ESUCCESS } @@ -4598,8 +4621,10 @@ pub fn sock_addr_local( let addr = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.addr_local() })); + let memory = ctx.data().memory(); wasi_try!(super::state::write_ip_port( - ctx.memory(), + &ctx, + memory, ret_addr, addr.ip(), addr.port() @@ -4626,8 +4651,9 @@ pub fn sock_addr_peer( debug!("wasi::sock_addr_peer"); let env = ctx.data(); - let addr = wasi_try!(__sock_actor(ctx, sock, 0, |socket| { socket.addr_peer() })); + let addr = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.addr_peer() })); wasi_try!(super::state::write_ip_port( + &ctx, env.memory(), ro_addr, addr.ip(), @@ -4664,7 +4690,8 @@ pub fn sock_open( ) -> __wasi_errno_t { debug!("wasi::sock_open"); - let (memory, state, mut inodes) = ctx.get_memory_and_wasi_state_and_inodes_mut(0); + let env = ctx.data(); + let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes_mut(0); let kind = match ty { __WASI_SOCK_TYPE_STREAM | __WASI_SOCK_TYPE_DGRAM => Kind::Socket { @@ -4696,7 +4723,7 @@ pub fn sock_open( let rights = super::state::all_socket_rights(); let fd = wasi_try!(state.fs.create_fd(rights, rights, 0, 0, inode)); - wasi_try_mem!(ro_sock.write(memory, fd)); + wasi_try_mem!(ro_sock.write(&ctx, memory, fd)); __WASI_ESUCCESS } @@ -4725,7 +4752,7 @@ pub fn sock_set_opt_flag( }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.set_opt_flag(option, flag) })); __WASI_ESUCCESS @@ -4746,10 +4773,11 @@ pub fn sock_get_opt_flag( ret_flag: WasmPtr<__wasi_bool_t, M>, ) -> __wasi_errno_t { debug!("wasi::sock_get_opt_flag(ty={})", opt); - let memory = ctx.memory(); + let env = ctx.data(); + let memory = env.memory(); let option: super::state::WasiSocketOption = opt.into(); - let flag = wasi_try!(__sock_actor(ctx, sock, 0, |socket| { + let flag = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { socket.get_opt_flag(option) })); let flag = match flag { @@ -4757,7 +4785,7 @@ pub fn sock_get_opt_flag( true => __WASI_BOOL_TRUE, }; - wasi_try_mem!(ret_flag.write(memory, flag)); + wasi_try_mem!(ret_flag.write(&ctx, memory, flag)); __WASI_ESUCCESS } @@ -4778,8 +4806,9 @@ pub fn sock_set_opt_time( ) -> __wasi_errno_t { debug!("wasi::sock_set_opt_time(ty={})", opt); - let memory = ctx.memory(); - let time = wasi_try_mem!(time.read(memory)); + let env = ctx.data(); + let memory = env.memory(); + let time = wasi_try_mem!(time.read(&ctx, memory)); let time = match time.tag { __WASI_OPTION_NONE => None, __WASI_OPTION_SOME => Some(Duration::from_nanos(time.u)), @@ -4796,7 +4825,7 @@ pub fn sock_set_opt_time( }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.set_opt_time(ty, time) })); __WASI_ESUCCESS @@ -4816,7 +4845,8 @@ pub fn sock_get_opt_time( ret_time: WasmPtr<__wasi_option_timestamp_t, M>, ) -> __wasi_errno_t { debug!("wasi::sock_get_opt_time(ty={})", opt); - let memory = ctx.memory(); + let env = ctx.data(); + let memory = env.memory(); let ty = match opt { __WASI_SOCK_OPTION_RECV_TIMEOUT => wasmer_vnet::TimeType::ReadTimeout, @@ -4827,7 +4857,9 @@ pub fn sock_get_opt_time( _ => return __WASI_EINVAL, }; - let time = wasi_try!(__sock_actor(ctx, sock, 0, |socket| { socket.opt_time(ty) })); + let time = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { + socket.opt_time(ty) + })); let time = match time { None => __wasi_option_timestamp_t { tag: __WASI_OPTION_NONE, @@ -4839,7 +4871,7 @@ pub fn sock_get_opt_time( }, }; - wasi_try_mem!(ret_time.write(memory, time)); + wasi_try_mem!(ret_time.write(&ctx, memory, time)); __WASI_ESUCCESS } @@ -4871,7 +4903,7 @@ pub fn sock_set_opt_size( }; let option: super::state::WasiSocketOption = opt.into(); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { match opt { __WASI_SOCK_OPTION_RECV_BUF_SIZE => socket.set_recv_buf_size(size as usize), __WASI_SOCK_OPTION_SEND_BUF_SIZE => socket.set_send_buf_size(size as usize), @@ -4901,7 +4933,7 @@ pub fn sock_get_opt_size( let env = ctx.data(); let memory = env.memory(); - let size = wasi_try!(__sock_actor(ctx, sock, 0, |socket| { + let size = wasi_try!(__sock_actor(&ctx, sock, 0, |socket| { match opt { __WASI_SOCK_OPTION_RECV_BUF_SIZE => { socket.recv_buf_size().map(|a| a as __wasi_filesize_t) @@ -4916,7 +4948,7 @@ pub fn sock_get_opt_size( _ => Err(__WASI_EINVAL), } })); - wasi_try_mem!(ret_size.write(memory, size)); + wasi_try_mem!(ret_size.write(&ctx, memory, size)); __WASI_ESUCCESS } @@ -4939,9 +4971,9 @@ pub fn sock_join_multicast_v4( let env = ctx.data(); let memory = env.memory(); - let multiaddr = wasi_try!(super::state::read_ip_v4(memory, multiaddr)); - let iface = wasi_try!(super::state::read_ip_v4(memory, iface)); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + let multiaddr = wasi_try!(super::state::read_ip_v4(&ctx, memory, multiaddr)); + let iface = wasi_try!(super::state::read_ip_v4(&ctx, memory, iface)); + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.join_multicast_v4(multiaddr, iface) })); __WASI_ESUCCESS @@ -4965,9 +4997,9 @@ pub fn sock_leave_multicast_v4( let env = ctx.data(); let memory = env.memory(); - let multiaddr = wasi_try!(super::state::read_ip_v4(memory, multiaddr)); - let iface = wasi_try!(super::state::read_ip_v4(memory, iface)); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + let multiaddr = wasi_try!(super::state::read_ip_v4(&ctx, memory, multiaddr)); + let iface = wasi_try!(super::state::read_ip_v4(&ctx, memory, iface)); + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.leave_multicast_v4(multiaddr, iface) })); __WASI_ESUCCESS @@ -4991,8 +5023,8 @@ pub fn sock_join_multicast_v6( let env = ctx.data(); let memory = env.memory(); - let multiaddr = wasi_try!(super::state::read_ip_v6(memory, multiaddr)); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + let multiaddr = wasi_try!(super::state::read_ip_v6(&ctx, memory, multiaddr)); + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.join_multicast_v6(multiaddr, iface) })); __WASI_ESUCCESS @@ -5016,8 +5048,8 @@ pub fn sock_leave_multicast_v6( let env = ctx.data(); let memory = env.memory(); - let multiaddr = wasi_try!(super::state::read_ip_v6(memory, multiaddr)); - wasi_try!(__sock_actor_mut(ctx, sock, 0, |socket| { + let multiaddr = wasi_try!(super::state::read_ip_v6(&ctx, memory, multiaddr)); + wasi_try!(__sock_actor_mut(&ctx, sock, 0, |socket| { socket.leave_multicast_v6(multiaddr, iface) })); __WASI_ESUCCESS @@ -5039,10 +5071,10 @@ pub fn sock_bind( debug!("wasi::sock_bind"); let env = ctx.data(); - let addr = wasi_try!(super::state::read_ip_port(env.memory(), addr)); + let addr = wasi_try!(super::state::read_ip_port(&ctx, env.memory(), addr)); let addr = SocketAddr::new(addr.0, addr.1); wasi_try!(__sock_upgrade( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_BIND, |socket| { socket.bind(env.net(), addr) } @@ -5069,9 +5101,10 @@ pub fn sock_listen( ) -> __wasi_errno_t { debug!("wasi::sock_listen"); + let env = ctx.data(); let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| __WASI_EINVAL)); wasi_try!(__sock_upgrade( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_BIND, |socket| { socket.listen(env.net(), backlog) } @@ -5100,12 +5133,13 @@ pub fn sock_accept( ) -> Result<__wasi_errno_t, WasiError> { debug!("wasi::sock_accept"); + let env = ctx.data(); let (child, addr) = { let mut ret; let (_, state) = env.get_memory_and_wasi_state(0); loop { wasi_try_ok!( - match __sock_actor(ctx, sock, __WASI_RIGHT_SOCK_ACCEPT, |socket| socket + match __sock_actor(&ctx, sock, __WASI_RIGHT_SOCK_ACCEPT, |socket| socket .accept_timeout(fd_flags, Duration::from_millis(5))) { Ok(a) => { @@ -5142,8 +5176,9 @@ pub fn sock_accept( let rights = super::state::all_socket_rights(); let fd = wasi_try_ok!(state.fs.create_fd(rights, rights, 0, 0, inode)); - wasi_try_mem_ok!(ro_fd.write(memory, fd)); + wasi_try_mem_ok!(ro_fd.write(&ctx, memory, fd)); wasi_try_ok!(super::state::write_ip_port( + &ctx, memory, ro_addr, addr.ip(), @@ -5173,10 +5208,10 @@ pub fn sock_connect( debug!("wasi::sock_connect"); let env = ctx.data(); - let addr = wasi_try!(super::state::read_ip_port(env.memory(), addr)); + let addr = wasi_try!(super::state::read_ip_port(&ctx, env.memory(), addr)); let addr = SocketAddr::new(addr.0, addr.1); wasi_try!(__sock_upgrade( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_CONNECT, |socket| { socket.connect(env.net(), addr) } @@ -5213,15 +5248,15 @@ pub fn sock_recv( let iovs_arr = wasi_try_mem_ok!(ri_data.slice(&ctx, memory, ri_data_len)); let bytes_read = wasi_try_ok!(__sock_actor_mut( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_RECV, - |socket| { socket.recv(memory, iovs_arr) } + |socket| { socket.recv(&ctx, memory, iovs_arr) } )); let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem_ok!(ro_flags.write(memory, 0)); - wasi_try_mem_ok!(ro_data_len.write(memory, bytes_read)); + wasi_try_mem_ok!(ro_flags.write(&ctx, memory, 0)); + wasi_try_mem_ok!(ro_data_len.write(&ctx, memory, bytes_read)); Ok(__WASI_ESUCCESS) } @@ -5256,15 +5291,15 @@ pub fn sock_recv_from( let iovs_arr = wasi_try_mem_ok!(ri_data.slice(&ctx, memory, ri_data_len)); let bytes_read = wasi_try_ok!(__sock_actor_mut( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_RECV_FROM, - |socket| { socket.recv_from(memory, iovs_arr, ro_addr) } + |socket| { socket.recv_from(&ctx, memory, iovs_arr, ro_addr) } )); let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem_ok!(ro_flags.write(memory, 0)); - wasi_try_mem_ok!(ro_data_len.write(memory, bytes_read)); + wasi_try_mem_ok!(ro_flags.write(&ctx, memory, 0)); + wasi_try_mem_ok!(ro_data_len.write(&ctx, memory, bytes_read)); Ok(__WASI_ESUCCESS) } @@ -5297,10 +5332,10 @@ pub fn sock_send( let iovs_arr = wasi_try_mem_ok!(si_data.slice(&ctx, memory, si_data_len)); let bytes_written = wasi_try_ok!(__sock_actor_mut( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_SEND, - |socket| { socket.send(memory, iovs_arr) } + |socket| { socket.send(&ctx, memory, iovs_arr) } )); let bytes_written: M::Offset = @@ -5340,15 +5375,15 @@ pub fn sock_send_to( let iovs_arr = wasi_try_mem_ok!(si_data.slice(&ctx, memory, si_data_len)); let bytes_written = wasi_try_ok!(__sock_actor_mut( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_SEND_TO, - |socket| { socket.send_to::(memory, iovs_arr, addr) } + |socket| { socket.send_to::(&ctx, memory, iovs_arr, addr) } )); let bytes_written: M::Offset = wasi_try_ok!(bytes_written.try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem_ok!(ret_data_len.write(memory, bytes_written as M::Offset)); + wasi_try_mem_ok!(ret_data_len.write(&ctx, memory, bytes_written as M::Offset)); Ok(__WASI_ESUCCESS) } @@ -5366,7 +5401,7 @@ pub fn sock_send_to( /// /// Number of bytes transmitted. pub unsafe fn sock_send_file( - ctx: ContextMut<'_, WasiEnv>, + mut ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, in_fd: __wasi_fd_t, offset: __wasi_filesize_t, @@ -5464,7 +5499,7 @@ pub unsafe fn sock_send_file( // Write it down to the socket let bytes_written = wasi_try_ok!(__sock_actor_mut( - ctx, + &ctx, sock, __WASI_RIGHT_SOCK_SEND, |socket| { @@ -5475,7 +5510,7 @@ pub unsafe fn sock_send_file( total_written += bytes_written as u64; } - wasi_try_mem_ok!(ret_sent.write(memory, total_written as __wasi_filesize_t)); + wasi_try_mem_ok!(ret_sent.write(&ctx, memory, total_written as __wasi_filesize_t)); Ok(__WASI_ESUCCESS) } @@ -5524,12 +5559,12 @@ pub fn resolve( let mut idx = 0; for found_ip in found_ips.iter().take(naddrs) { - super::state::write_ip(memory, addrs.index(idx).as_ptr::(), *found_ip); + super::state::write_ip(&ctx, memory, addrs.index(idx).as_ptr::(), *found_ip); idx += 1; } let idx: M::Offset = wasi_try!(idx.try_into().map_err(|_| __WASI_EOVERFLOW)); - wasi_try_mem!(ret_naddrs.write(memory, idx)); + wasi_try_mem!(ret_naddrs.write(&ctx, memory, idx)); __WASI_ESUCCESS } diff --git a/lib/wasi/src/syscalls/wasi.rs b/lib/wasi/src/syscalls/wasi.rs index b7d1c28edc4..14ab2200bbc 100644 --- a/lib/wasi/src/syscalls/wasi.rs +++ b/lib/wasi/src/syscalls/wasi.rs @@ -1,256 +1,260 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; -use wasmer::{Memory, Memory32, MemorySize, WasmPtr, WasmSlice}; +use wasmer::{ContextMut, Memory, Memory32, MemorySize, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; type MemoryType = Memory32; type MemoryOffset = u32; pub(crate) fn args_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, ) -> __wasi_errno_t { - super::args_get::(env, argv, argv_buf) + super::args_get::(ctx, argv, argv_buf) } pub(crate) fn args_sizes_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, argc: WasmPtr, argv_buf_size: WasmPtr, ) -> __wasi_errno_t { - super::args_sizes_get::(env, argc, argv_buf_size) + super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::clock_res_get::(env, clock_id, resolution) + super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::clock_time_get::(env, clock_id, precision, time) + super::clock_time_get::(ctx, clock_id, precision, time) } pub(crate) fn environ_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, ) -> __wasi_errno_t { - super::environ_get::(env, environ, environ_buf) + super::environ_get::(ctx, environ, environ_buf) } pub(crate) fn environ_sizes_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, environ_count: WasmPtr, environ_buf_size: WasmPtr, ) -> __wasi_errno_t { - super::environ_sizes_get::(env, environ_count, environ_buf_size) + super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, ) -> __wasi_errno_t { - super::fd_advise(env, fd, offset, len, advice) + super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> __wasi_errno_t { - super::fd_allocate(env, fd, offset, len) + super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_close(env, fd) +pub(crate) fn fd_close(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_datasync(env, fd) +pub(crate) fn fd_datasync(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_fdstat_get::(env, fd, buf_ptr) + super::fd_fdstat_get::(ctx, fd, buf_ptr) } pub(crate) fn fd_fdstat_set_flags( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_fdflags_t, ) -> __wasi_errno_t { - super::fd_fdstat_set_flags(env, fd, flags) + super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, ) -> __wasi_errno_t { - super::fd_fdstat_set_rights(env, fd, fs_rights_base, fs_rights_inheriting) + super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_filestat_get::(env, fd, buf) + super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, st_size: __wasi_filesize_t, ) -> __wasi_errno_t { - super::fd_filestat_set_size(env, fd, st_size) + super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { - super::fd_filestat_set_times(env, fd, st_atim, st_mtim, fst_flags) + super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_pread::(env, fd, iovs, iovs_len, offset, nread) + super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_prestat_get::(env, fd, buf) + super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::fd_prestat_dir_name::(env, fd, path, path_len) + super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_pwrite::(env, fd, iovs, iovs_len, offset, nwritten) + super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_read::(env, fd, iovs, iovs_len, nread) + super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr, buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, ) -> __wasi_errno_t { - super::fd_readdir::(env, fd, buf, buf_len, cookie, bufused) + super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber(env: &WasiEnv, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { - super::fd_renumber(env, from, to) +pub(crate) fn fd_renumber( + ctx: ContextMut<'_, WasiEnv>, + from: __wasi_fd_t, + to: __wasi_fd_t, +) -> __wasi_errno_t { + super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_seek::(env, fd, offset, whence, newoffset) + super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_sync(env, fd) +pub(crate) fn fd_sync(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_tell::(env, fd, offset) + super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_write::(env, fd, iovs, iovs_len, nwritten) + super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_create_directory::(env, fd, path, path_len) + super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> __wasi_errno_t { - super::path_filestat_get::(env, fd, flags, path, path_len, buf) + super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path: WasmPtr, @@ -260,12 +264,12 @@ pub(crate) fn path_filestat_set_times( fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { super::path_filestat_set_times::( - env, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, + ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) } pub(crate) fn path_link( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_fd: __wasi_fd_t, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, @@ -275,7 +279,7 @@ pub(crate) fn path_link( new_path_len: MemoryOffset, ) -> __wasi_errno_t { super::path_link::( - env, + ctx, old_fd, old_flags, old_path, @@ -287,7 +291,7 @@ pub(crate) fn path_link( } pub(crate) fn path_open( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, dirfd: __wasi_fd_t, dirflags: __wasi_lookupflags_t, path: WasmPtr, @@ -299,7 +303,7 @@ pub(crate) fn path_open( fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { super::path_open::( - env, + ctx, dirfd, dirflags, path, @@ -313,7 +317,7 @@ pub(crate) fn path_open( } pub(crate) fn path_readlink( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, dir_fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, @@ -321,20 +325,20 @@ pub(crate) fn path_readlink( buf_len: MemoryOffset, buf_used: WasmPtr, ) -> __wasi_errno_t { - super::path_readlink::(env, dir_fd, path, path_len, buf, buf_len, buf_used) + super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } pub(crate) fn path_remove_directory( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_remove_directory::(env, fd, path, path_len) + super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_fd: __wasi_fd_t, old_path: WasmPtr, old_path_len: MemoryOffset, @@ -343,7 +347,7 @@ pub(crate) fn path_rename( new_path_len: MemoryOffset, ) -> __wasi_errno_t { super::path_rename::( - env, + ctx, old_fd, old_path, old_path_len, @@ -354,57 +358,60 @@ pub(crate) fn path_rename( } pub(crate) fn path_symlink( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: MemoryOffset, fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_symlink::(env, old_path, old_path_len, fd, new_path, new_path_len) + super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } pub(crate) fn path_unlink_file( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_unlink_file::(env, fd, path, path_len) + super::path_unlink_file::(ctx, fd, path, path_len) } pub(crate) fn poll_oneoff( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, in_: WasmPtr<__wasi_subscription_t, MemoryType>, out_: WasmPtr<__wasi_event_t, MemoryType>, nsubscriptions: MemoryOffset, nevents: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::poll_oneoff::(env, in_, out_, nsubscriptions, nevents) + super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } -pub(crate) fn proc_exit(env: &WasiEnv, code: __wasi_exitcode_t) -> Result<(), WasiError> { - super::proc_exit(env, code) +pub(crate) fn proc_exit( + ctx: ContextMut<'_, WasiEnv>, + code: __wasi_exitcode_t, +) -> Result<(), WasiError> { + super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(env: &WasiEnv, sig: __wasi_signal_t) -> __wasi_errno_t { - super::proc_raise(env, sig) +pub(crate) fn proc_raise(ctx: ContextMut<'_, WasiEnv>, sig: __wasi_signal_t) -> __wasi_errno_t { + super::proc_raise(ctx, sig) } pub(crate) fn random_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, buf: WasmPtr, buf_len: MemoryOffset, ) -> __wasi_errno_t { - super::random_get::(env, buf, buf_len) + super::random_get::(ctx, buf, buf_len) } -pub(crate) fn sched_yield(env: &WasiEnv) -> Result<__wasi_errno_t, WasiError> { - super::sched_yield(env) +pub(crate) fn sched_yield(ctx: ContextMut<'_, WasiEnv>) -> Result<__wasi_errno_t, WasiError> { + super::sched_yield(ctx) } pub(crate) fn sock_recv( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, @@ -413,7 +420,7 @@ pub(crate) fn sock_recv( ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { super::sock_recv::( - env, + ctx, sock, ri_data, ri_data_len, @@ -424,20 +431,20 @@ pub(crate) fn sock_recv( } pub(crate) fn sock_send( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::sock_send::(env, sock, si_data, si_data_len, si_flags, ret_data_len) + super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) } pub(crate) fn sock_shutdown( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, how: __wasi_sdflags_t, ) -> __wasi_errno_t { - super::sock_shutdown(env, sock, how) + super::sock_shutdown(ctx, sock, how) } diff --git a/lib/wasi/src/syscalls/wasix32.rs b/lib/wasi/src/syscalls/wasix32.rs index 557e5c2089a..712c1a34eb9 100644 --- a/lib/wasi/src/syscalls/wasix32.rs +++ b/lib/wasi/src/syscalls/wasix32.rs @@ -1,256 +1,260 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; -use wasmer::{Memory, Memory32, MemorySize, WasmPtr, WasmSlice}; +use wasmer::{ContextMut, Memory, Memory32, MemorySize, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; type MemoryType = Memory32; type MemoryOffset = u32; pub(crate) fn args_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, ) -> __wasi_errno_t { - super::args_get::(env, argv, argv_buf) + super::args_get::(ctx, argv, argv_buf) } pub(crate) fn args_sizes_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, argc: WasmPtr, argv_buf_size: WasmPtr, ) -> __wasi_errno_t { - super::args_sizes_get::(env, argc, argv_buf_size) + super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::clock_res_get::(env, clock_id, resolution) + super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::clock_time_get::(env, clock_id, precision, time) + super::clock_time_get::(ctx, clock_id, precision, time) } pub(crate) fn environ_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, ) -> __wasi_errno_t { - super::environ_get::(env, environ, environ_buf) + super::environ_get::(ctx, environ, environ_buf) } pub(crate) fn environ_sizes_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, environ_count: WasmPtr, environ_buf_size: WasmPtr, ) -> __wasi_errno_t { - super::environ_sizes_get::(env, environ_count, environ_buf_size) + super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, ) -> __wasi_errno_t { - super::fd_advise(env, fd, offset, len, advice) + super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> __wasi_errno_t { - super::fd_allocate(env, fd, offset, len) + super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_close(env, fd) +pub(crate) fn fd_close(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_datasync(env, fd) +pub(crate) fn fd_datasync(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_fdstat_get::(env, fd, buf_ptr) + super::fd_fdstat_get::(ctx, fd, buf_ptr) } pub(crate) fn fd_fdstat_set_flags( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_fdflags_t, ) -> __wasi_errno_t { - super::fd_fdstat_set_flags(env, fd, flags) + super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, ) -> __wasi_errno_t { - super::fd_fdstat_set_rights(env, fd, fs_rights_base, fs_rights_inheriting) + super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_filestat_get::(env, fd, buf) + super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, st_size: __wasi_filesize_t, ) -> __wasi_errno_t { - super::fd_filestat_set_size(env, fd, st_size) + super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { - super::fd_filestat_set_times(env, fd, st_atim, st_mtim, fst_flags) + super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_pread::(env, fd, iovs, iovs_len, offset, nread) + super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_prestat_get::(env, fd, buf) + super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::fd_prestat_dir_name::(env, fd, path, path_len) + super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_pwrite::(env, fd, iovs, iovs_len, offset, nwritten) + super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_read::(env, fd, iovs, iovs_len, nread) + super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr, buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, ) -> __wasi_errno_t { - super::fd_readdir::(env, fd, buf, buf_len, cookie, bufused) + super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber(env: &WasiEnv, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { - super::fd_renumber(env, from, to) +pub(crate) fn fd_renumber( + ctx: ContextMut<'_, WasiEnv>, + from: __wasi_fd_t, + to: __wasi_fd_t, +) -> __wasi_errno_t { + super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_seek::(env, fd, offset, whence, newoffset) + super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_sync(env, fd) +pub(crate) fn fd_sync(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_tell::(env, fd, offset) + super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_write::(env, fd, iovs, iovs_len, nwritten) + super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_create_directory::(env, fd, path, path_len) + super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> __wasi_errno_t { - super::path_filestat_get::(env, fd, flags, path, path_len, buf) + super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path: WasmPtr, @@ -260,12 +264,12 @@ pub(crate) fn path_filestat_set_times( fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { super::path_filestat_set_times::( - env, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, + ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) } pub(crate) fn path_link( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_fd: __wasi_fd_t, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, @@ -275,7 +279,7 @@ pub(crate) fn path_link( new_path_len: MemoryOffset, ) -> __wasi_errno_t { super::path_link::( - env, + ctx, old_fd, old_flags, old_path, @@ -287,7 +291,7 @@ pub(crate) fn path_link( } pub(crate) fn path_open( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, dirfd: __wasi_fd_t, dirflags: __wasi_lookupflags_t, path: WasmPtr, @@ -299,7 +303,7 @@ pub(crate) fn path_open( fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { super::path_open::( - env, + ctx, dirfd, dirflags, path, @@ -313,7 +317,7 @@ pub(crate) fn path_open( } pub(crate) fn path_readlink( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, dir_fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, @@ -321,20 +325,20 @@ pub(crate) fn path_readlink( buf_len: MemoryOffset, buf_used: WasmPtr, ) -> __wasi_errno_t { - super::path_readlink::(env, dir_fd, path, path_len, buf, buf_len, buf_used) + super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } pub(crate) fn path_remove_directory( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_remove_directory::(env, fd, path, path_len) + super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_fd: __wasi_fd_t, old_path: WasmPtr, old_path_len: MemoryOffset, @@ -343,7 +347,7 @@ pub(crate) fn path_rename( new_path_len: MemoryOffset, ) -> __wasi_errno_t { super::path_rename::( - env, + ctx, old_fd, old_path, old_path_len, @@ -354,159 +358,168 @@ pub(crate) fn path_rename( } pub(crate) fn path_symlink( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: MemoryOffset, fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_symlink::(env, old_path, old_path_len, fd, new_path, new_path_len) + super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } pub(crate) fn path_unlink_file( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_unlink_file::(env, fd, path, path_len) + super::path_unlink_file::(ctx, fd, path, path_len) } pub(crate) fn poll_oneoff( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, in_: WasmPtr<__wasi_subscription_t, MemoryType>, out_: WasmPtr<__wasi_event_t, MemoryType>, nsubscriptions: MemoryOffset, nevents: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::poll_oneoff::(env, in_, out_, nsubscriptions, nevents) + super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } -pub(crate) fn proc_exit(env: &WasiEnv, code: __wasi_exitcode_t) -> Result<(), WasiError> { - super::proc_exit(env, code) +pub(crate) fn proc_exit( + ctx: ContextMut<'_, WasiEnv>, + code: __wasi_exitcode_t, +) -> Result<(), WasiError> { + super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(env: &WasiEnv, sig: __wasi_signal_t) -> __wasi_errno_t { - super::proc_raise(env, sig) +pub(crate) fn proc_raise(ctx: ContextMut<'_, WasiEnv>, sig: __wasi_signal_t) -> __wasi_errno_t { + super::proc_raise(ctx, sig) } pub(crate) fn random_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, buf: WasmPtr, buf_len: MemoryOffset, ) -> __wasi_errno_t { - super::random_get::(env, buf, buf_len) + super::random_get::(ctx, buf, buf_len) } pub(crate) fn fd_dup( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_dup::(env, fd, ret_fd) + super::fd_dup::(ctx, fd, ret_fd) } pub(crate) fn fd_event( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, initial_val: u64, flags: __wasi_eventfdflags, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_event(env, initial_val, flags, ret_fd) + super::fd_event(ctx, initial_val, flags, ret_fd) } pub(crate) fn fd_pipe( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ro_fd1: WasmPtr<__wasi_fd_t, MemoryType>, ro_fd2: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_pipe::(env, ro_fd1, ro_fd2) + super::fd_pipe::(ctx, ro_fd1, ro_fd2) } pub(crate) fn tty_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, ) -> __wasi_errno_t { - super::tty_get::(env, tty_state) + super::tty_get::(ctx, tty_state) } pub(crate) fn tty_set( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, ) -> __wasi_errno_t { - super::tty_set::(env, tty_state) + super::tty_set::(ctx, tty_state) } pub(crate) fn getcwd( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, path: WasmPtr, path_len: WasmPtr, ) -> __wasi_errno_t { - super::getcwd::(env, path, path_len) + super::getcwd::(ctx, path, path_len) } pub(crate) fn chdir( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::chdir::(env, path, path_len) + super::chdir::(ctx, path, path_len) } pub(crate) fn thread_spawn( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, method: WasmPtr, method_len: MemoryOffset, user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, ) -> __wasi_errno_t { - super::thread_spawn::(env, method, method_len, user_data, reactor, ret_tid) + super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) } pub(crate) fn thread_sleep( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, duration: __wasi_timestamp_t, ) -> Result<__wasi_errno_t, WasiError> { - super::thread_sleep(env, duration) + super::thread_sleep(ctx, duration) } pub(crate) fn thread_id( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, ) -> __wasi_errno_t { - super::thread_id::(env, ret_tid) + super::thread_id::(ctx, ret_tid) } -pub(crate) fn thread_join(env: &WasiEnv, tid: __wasi_tid_t) -> Result<__wasi_errno_t, WasiError> { - super::thread_join(env, tid) +pub(crate) fn thread_join( + ctx: ContextMut<'_, WasiEnv>, + tid: __wasi_tid_t, +) -> Result<__wasi_errno_t, WasiError> { + super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ret_parallelism: WasmPtr, ) -> __wasi_errno_t { - super::thread_parallelism::(env, ret_parallelism) + super::thread_parallelism::(ctx, ret_parallelism) } pub(crate) fn thread_exit( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, exitcode: __wasi_exitcode_t, ) -> Result<__wasi_errno_t, WasiError> { - super::thread_exit(env, exitcode) + super::thread_exit(ctx, exitcode) } -pub(crate) fn sched_yield(env: &WasiEnv) -> Result<__wasi_errno_t, WasiError> { - super::sched_yield(env) +pub(crate) fn sched_yield(ctx: ContextMut<'_, WasiEnv>) -> Result<__wasi_errno_t, WasiError> { + super::sched_yield(ctx) } -pub(crate) fn getpid(env: &WasiEnv, ret_pid: WasmPtr<__wasi_pid_t, MemoryType>) -> __wasi_errno_t { - super::getpid::(env, ret_pid) +pub(crate) fn getpid( + ctx: ContextMut<'_, WasiEnv>, + ret_pid: WasmPtr<__wasi_pid_t, MemoryType>, +) -> __wasi_errno_t { + super::getpid::(ctx, ret_pid) } pub(crate) fn process_spawn( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, name: WasmPtr, name_len: MemoryOffset, chroot: __wasi_bool_t, @@ -522,7 +535,7 @@ pub(crate) fn process_spawn( ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, ) -> __bus_errno_t { super::process_spawn::( - env, + ctx, name, name_len, chroot, @@ -540,17 +553,17 @@ pub(crate) fn process_spawn( } pub(crate) fn bus_open_local( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, name: WasmPtr, name_len: MemoryOffset, reuse: __wasi_bool_t, ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, ) -> __bus_errno_t { - super::bus_open_local::(env, name, name_len, reuse, ret_bid) + super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } pub(crate) fn bus_open_remote( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, name: WasmPtr, name_len: MemoryOffset, reuse: __wasi_bool_t, @@ -561,7 +574,7 @@ pub(crate) fn bus_open_remote( ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, ) -> __bus_errno_t { super::bus_open_remote::( - env, + ctx, name, name_len, reuse, @@ -573,12 +586,12 @@ pub(crate) fn bus_open_remote( ) } -pub(crate) fn bus_close(env: &WasiEnv, bid: __wasi_bid_t) -> __bus_errno_t { - super::bus_close(env, bid) +pub(crate) fn bus_close(ctx: ContextMut<'_, WasiEnv>, bid: __wasi_bid_t) -> __bus_errno_t { + super::bus_close(ctx, bid) } pub(crate) fn bus_call( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, bid: __wasi_bid_t, keep_alive: __wasi_bool_t, topic: WasmPtr, @@ -589,12 +602,12 @@ pub(crate) fn bus_call( ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, ) -> __bus_errno_t { super::bus_call::( - env, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, + ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) } pub(crate) fn bus_subcall( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, parent: __wasi_cid_t, keep_alive: __wasi_bool_t, topic: WasmPtr, @@ -605,12 +618,12 @@ pub(crate) fn bus_subcall( ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, ) -> __bus_errno_t { super::bus_subcall::( - env, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, + ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) } pub(crate) fn bus_poll( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, timeout: __wasi_timestamp_t, events: WasmPtr, nevents: MemoryOffset, @@ -619,7 +632,7 @@ pub(crate) fn bus_poll( ret_nevents: WasmPtr, ) -> __bus_errno_t { super::bus_poll::( - env, + ctx, timeout, events, nevents, @@ -630,122 +643,126 @@ pub(crate) fn bus_poll( } pub(crate) fn call_reply( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, cid: __wasi_cid_t, format: __wasi_busdataformat_t, buf: WasmPtr, buf_len: MemoryOffset, ) -> __bus_errno_t { - super::call_reply::(env, cid, format, buf, buf_len) + super::call_reply::(ctx, cid, format, buf, buf_len) } -pub(crate) fn call_fault(env: &WasiEnv, cid: __wasi_cid_t, fault: __bus_errno_t) -> __bus_errno_t { - super::call_fault(env, cid, fault) +pub(crate) fn call_fault( + ctx: ContextMut<'_, WasiEnv>, + cid: __wasi_cid_t, + fault: __bus_errno_t, +) -> __bus_errno_t { + super::call_fault(ctx, cid, fault) } -pub(crate) fn call_close(env: &WasiEnv, cid: __wasi_cid_t) -> __bus_errno_t { - super::call_close(env, cid) +pub(crate) fn call_close(ctx: ContextMut<'_, WasiEnv>, cid: __wasi_cid_t) -> __bus_errno_t { + super::call_close(ctx, cid) } pub(crate) fn port_bridge( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, network: WasmPtr, network_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, security: __wasi_streamsecurity_t, ) -> __wasi_errno_t { - super::port_bridge::(env, network, network_len, token, token_len, security) + super::port_bridge::(ctx, network, network_len, token, token_len, security) } -pub(crate) fn port_unbridge(env: &WasiEnv) -> __wasi_errno_t { - super::port_unbridge(env) +pub(crate) fn port_unbridge(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(env: &WasiEnv) -> __wasi_errno_t { - super::port_dhcp_acquire(env) +pub(crate) fn port_dhcp_acquire(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_dhcp_acquire(ctx) } pub(crate) fn port_addr_add( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, addr: WasmPtr<__wasi_cidr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_addr_add::(env, addr) + super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, addr: WasmPtr<__wasi_addr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_addr_remove::(env, addr) + super::port_addr_remove::(ctx, addr) } -pub(crate) fn port_addr_clear(env: &WasiEnv) -> __wasi_errno_t { - super::port_addr_clear(env) +pub(crate) fn port_addr_clear(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_addr_clear(ctx) } pub(crate) fn port_addr_list( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, ) -> __wasi_errno_t { - super::port_addr_list::(env, addrs, naddrs) + super::port_addr_list::(ctx, addrs, naddrs) } pub(crate) fn port_mac( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ret_mac: WasmPtr<__wasi_hardwareaddress_t, MemoryType>, ) -> __wasi_errno_t { - super::port_mac::(env, ret_mac) + super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_gateway_set::(env, ip) + super::port_gateway_set::(ctx, ip) } pub(crate) fn port_route_add( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, cidr: WasmPtr<__wasi_cidr_t, MemoryType>, via_router: WasmPtr<__wasi_addr_t, MemoryType>, preferred_until: WasmPtr<__wasi_option_timestamp_t, MemoryType>, expires_at: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::port_route_add::(env, cidr, via_router, preferred_until, expires_at) + super::port_route_add::(ctx, cidr, via_router, preferred_until, expires_at) } pub(crate) fn port_route_remove( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_route_remove::(env, ip) + super::port_route_remove::(ctx, ip) } -pub(crate) fn port_route_clear(env: &WasiEnv) -> __wasi_errno_t { - super::port_route_clear(env) +pub(crate) fn port_route_clear(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_route_clear(ctx) } pub(crate) fn port_route_list( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, routes: WasmPtr<__wasi_route_t, MemoryType>, nroutes: WasmPtr, ) -> __wasi_errno_t { - super::port_route_list::(env, routes, nroutes) + super::port_route_list::(ctx, routes, nroutes) } pub(crate) fn ws_connect( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, url: WasmPtr, url_len: MemoryOffset, ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::ws_connect::(env, url, url_len, ret_sock) + super::ws_connect::(ctx, url, url_len, ret_sock) } pub(crate) fn http_request( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, url: WasmPtr, url_len: MemoryOffset, method: WasmPtr, @@ -756,7 +773,7 @@ pub(crate) fn http_request( ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, ) -> __wasi_errno_t { super::http_request::( - env, + ctx, url, url_len, method, @@ -769,7 +786,7 @@ pub(crate) fn http_request( } pub(crate) fn http_status( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, status: WasmPtr<__wasi_http_status_t, MemoryType>, status_text: WasmPtr, @@ -777,169 +794,169 @@ pub(crate) fn http_status( headers: WasmPtr, headers_len: WasmPtr, ) -> __wasi_errno_t { - super::http_status::(env, sock, status) + super::http_status::(ctx, sock, status) } pub(crate) fn sock_status( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_status::(env, sock, ret_status) + super::sock_status::(ctx, sock, ret_status) } pub(crate) fn sock_addr_local( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_addr_local::(env, sock, ret_addr) + super::sock_addr_local::(ctx, sock, ret_addr) } pub(crate) fn sock_addr_peer( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_addr_peer::(env, sock, ro_addr) + super::sock_addr_peer::(ctx, sock, ro_addr) } pub(crate) fn sock_open( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_open::(env, af, ty, pt, ro_sock) + super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, flag: __wasi_bool_t, ) -> __wasi_errno_t { - super::sock_set_opt_flag(env, sock, opt, flag) + super::sock_set_opt_flag(ctx, sock, opt, flag) } pub(crate) fn sock_get_opt_flag( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_get_opt_flag::(env, sock, opt, ret_flag) + super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } pub fn sock_set_opt_time( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_set_opt_time(env, sock, opt, time) + super::sock_set_opt_time(ctx, sock, opt, time) } pub fn sock_get_opt_time( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_get_opt_time(env, sock, opt, ret_time) + super::sock_get_opt_time(ctx, sock, opt, ret_time) } pub fn sock_set_opt_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, size: __wasi_filesize_t, ) -> __wasi_errno_t { - super::sock_set_opt_size(env, sock, opt, size) + super::sock_set_opt_size(ctx, sock, opt, size) } pub fn sock_get_opt_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_get_opt_size(env, sock, opt, ret_size) + super::sock_get_opt_size(ctx, sock, opt, ret_size) } pub(crate) fn sock_join_multicast_v4( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_join_multicast_v4::(env, sock, multiaddr, iface) + super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v4( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_leave_multicast_v4::(env, sock, multiaddr, iface) + super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_join_multicast_v6( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> __wasi_errno_t { - super::sock_join_multicast_v6::(env, sock, multiaddr, iface) + super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v6( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> __wasi_errno_t { - super::sock_leave_multicast_v6::(env, sock, multiaddr, iface) + super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_bind( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_bind::(env, sock, addr) + super::sock_bind::(ctx, sock, addr) } pub(crate) fn sock_listen( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, backlog: MemoryOffset, ) -> __wasi_errno_t { - super::sock_listen::(env, sock, backlog) + super::sock_listen::(ctx, sock, backlog) } pub(crate) fn sock_accept( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, fd_flags: __wasi_fdflags_t, ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - super::sock_accept::(env, sock, fd_flags, ro_fd, ro_addr) + super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) } pub(crate) fn sock_connect( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_connect::(env, sock, addr) + super::sock_connect::(ctx, sock, addr) } pub(crate) fn sock_recv( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, @@ -948,7 +965,7 @@ pub(crate) fn sock_recv( ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { super::sock_recv::( - env, + ctx, sock, ri_data, ri_data_len, @@ -959,7 +976,7 @@ pub(crate) fn sock_recv( } pub(crate) fn sock_recv_from( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, @@ -969,7 +986,7 @@ pub(crate) fn sock_recv_from( ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { super::sock_recv_from::( - env, + ctx, sock, ri_data, ri_data_len, @@ -981,18 +998,18 @@ pub(crate) fn sock_recv_from( } pub(crate) fn sock_send( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::sock_send::(env, sock, si_data, si_data_len, si_flags, ret_data_len) + super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) } pub(crate) fn sock_send_to( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, @@ -1001,7 +1018,7 @@ pub(crate) fn sock_send_to( ret_data_len: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { super::sock_send_to::( - env, + ctx, sock, si_data, si_data_len, @@ -1012,26 +1029,26 @@ pub(crate) fn sock_send_to( } pub(crate) fn sock_send_file( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, out_fd: __wasi_fd_t, in_fd: __wasi_fd_t, offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - unsafe { super::sock_send_file::(env, out_fd, in_fd, offset, count, ret_sent) } + unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } pub(crate) fn sock_shutdown( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, how: __wasi_sdflags_t, ) -> __wasi_errno_t { - super::sock_shutdown(env, sock, how) + super::sock_shutdown(ctx, sock, how) } pub(crate) fn resolve( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, host: WasmPtr, host_len: MemoryOffset, port: u16, @@ -1039,5 +1056,5 @@ pub(crate) fn resolve( nips: MemoryOffset, ret_nips: WasmPtr, ) -> __wasi_errno_t { - super::resolve::(env, host, host_len, port, ips, nips, ret_nips) + super::resolve::(ctx, host, host_len, port, ips, nips, ret_nips) } diff --git a/lib/wasi/src/syscalls/wasix64.rs b/lib/wasi/src/syscalls/wasix64.rs index e3ece1fb80d..4064232ae6f 100644 --- a/lib/wasi/src/syscalls/wasix64.rs +++ b/lib/wasi/src/syscalls/wasix64.rs @@ -1,256 +1,260 @@ #![deny(dead_code)] use crate::{WasiEnv, WasiError, WasiState, WasiThread}; -use wasmer::{Memory, Memory64, MemorySize, WasmPtr, WasmSlice}; +use wasmer::{ContextMut, Memory, Memory64, MemorySize, WasmPtr, WasmSlice}; use wasmer_wasi_types::*; type MemoryType = Memory64; type MemoryOffset = u64; pub(crate) fn args_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, argv: WasmPtr, MemoryType>, argv_buf: WasmPtr, ) -> __wasi_errno_t { - super::args_get::(env, argv, argv_buf) + super::args_get::(ctx, argv, argv_buf) } pub(crate) fn args_sizes_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, argc: WasmPtr, argv_buf_size: WasmPtr, ) -> __wasi_errno_t { - super::args_sizes_get::(env, argc, argv_buf_size) + super::args_sizes_get::(ctx, argc, argv_buf_size) } pub(crate) fn clock_res_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, resolution: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::clock_res_get::(env, clock_id, resolution) + super::clock_res_get::(ctx, clock_id, resolution) } pub(crate) fn clock_time_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, clock_id: __wasi_clockid_t, precision: __wasi_timestamp_t, time: WasmPtr<__wasi_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::clock_time_get::(env, clock_id, precision, time) + super::clock_time_get::(ctx, clock_id, precision, time) } pub(crate) fn environ_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, environ: WasmPtr, MemoryType>, environ_buf: WasmPtr, ) -> __wasi_errno_t { - super::environ_get::(env, environ, environ_buf) + super::environ_get::(ctx, environ, environ_buf) } pub(crate) fn environ_sizes_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, environ_count: WasmPtr, environ_buf_size: WasmPtr, ) -> __wasi_errno_t { - super::environ_sizes_get::(env, environ_count, environ_buf_size) + super::environ_sizes_get::(ctx, environ_count, environ_buf_size) } pub(crate) fn fd_advise( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, advice: __wasi_advice_t, ) -> __wasi_errno_t { - super::fd_advise(env, fd, offset, len, advice) + super::fd_advise(ctx, fd, offset, len, advice) } pub(crate) fn fd_allocate( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filesize_t, len: __wasi_filesize_t, ) -> __wasi_errno_t { - super::fd_allocate(env, fd, offset, len) + super::fd_allocate(ctx, fd, offset, len) } -pub(crate) fn fd_close(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_close(env, fd) +pub(crate) fn fd_close(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_close(ctx, fd) } -pub(crate) fn fd_datasync(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_datasync(env, fd) +pub(crate) fn fd_datasync(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_datasync(ctx, fd) } pub(crate) fn fd_fdstat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf_ptr: WasmPtr<__wasi_fdstat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_fdstat_get::(env, fd, buf_ptr) + super::fd_fdstat_get::(ctx, fd, buf_ptr) } pub(crate) fn fd_fdstat_set_flags( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_fdflags_t, ) -> __wasi_errno_t { - super::fd_fdstat_set_flags(env, fd, flags) + super::fd_fdstat_set_flags(ctx, fd, flags) } pub(crate) fn fd_fdstat_set_rights( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, fs_rights_base: __wasi_rights_t, fs_rights_inheriting: __wasi_rights_t, ) -> __wasi_errno_t { - super::fd_fdstat_set_rights(env, fd, fs_rights_base, fs_rights_inheriting) + super::fd_fdstat_set_rights(ctx, fd, fs_rights_base, fs_rights_inheriting) } pub(crate) fn fd_filestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_filestat_get::(env, fd, buf) + super::fd_filestat_get::(ctx, fd, buf) } pub(crate) fn fd_filestat_set_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, st_size: __wasi_filesize_t, ) -> __wasi_errno_t { - super::fd_filestat_set_size(env, fd, st_size) + super::fd_filestat_set_size(ctx, fd, st_size) } pub(crate) fn fd_filestat_set_times( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, st_atim: __wasi_timestamp_t, st_mtim: __wasi_timestamp_t, fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { - super::fd_filestat_set_times(env, fd, st_atim, st_mtim, fst_flags) + super::fd_filestat_set_times(ctx, fd, st_atim, st_mtim, fst_flags) } pub(crate) fn fd_pread( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nread: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_pread::(env, fd, iovs, iovs_len, offset, nread) + super::fd_pread::(ctx, fd, iovs, iovs_len, offset, nread) } pub(crate) fn fd_prestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr<__wasi_prestat_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_prestat_get::(env, fd, buf) + super::fd_prestat_get::(ctx, fd, buf) } pub(crate) fn fd_prestat_dir_name( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::fd_prestat_dir_name::(env, fd, path, path_len) + super::fd_prestat_dir_name::(ctx, fd, path, path_len) } pub(crate) fn fd_pwrite( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, offset: __wasi_filesize_t, nwritten: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_pwrite::(env, fd, iovs, iovs_len, offset, nwritten) + super::fd_pwrite::(ctx, fd, iovs, iovs_len, offset, nwritten) } pub(crate) fn fd_read( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_iovec_t, MemoryType>, iovs_len: MemoryOffset, nread: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_read::(env, fd, iovs, iovs_len, nread) + super::fd_read::(ctx, fd, iovs, iovs_len, nread) } pub(crate) fn fd_readdir( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, buf: WasmPtr, buf_len: MemoryOffset, cookie: __wasi_dircookie_t, bufused: WasmPtr, ) -> __wasi_errno_t { - super::fd_readdir::(env, fd, buf, buf_len, cookie, bufused) + super::fd_readdir::(ctx, fd, buf, buf_len, cookie, bufused) } -pub(crate) fn fd_renumber(env: &WasiEnv, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_errno_t { - super::fd_renumber(env, from, to) +pub(crate) fn fd_renumber( + ctx: ContextMut<'_, WasiEnv>, + from: __wasi_fd_t, + to: __wasi_fd_t, +) -> __wasi_errno_t { + super::fd_renumber(ctx, from, to) } pub(crate) fn fd_seek( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: __wasi_filedelta_t, whence: __wasi_whence_t, newoffset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_seek::(env, fd, offset, whence, newoffset) + super::fd_seek::(ctx, fd, offset, whence, newoffset) } -pub(crate) fn fd_sync(env: &WasiEnv, fd: __wasi_fd_t) -> __wasi_errno_t { - super::fd_sync(env, fd) +pub(crate) fn fd_sync(ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t) -> __wasi_errno_t { + super::fd_sync(ctx, fd) } pub(crate) fn fd_tell( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, offset: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_tell::(env, fd, offset) + super::fd_tell::(ctx, fd, offset) } pub(crate) fn fd_write( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, iovs: WasmPtr<__wasi_ciovec_t, MemoryType>, iovs_len: MemoryOffset, nwritten: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::fd_write::(env, fd, iovs, iovs_len, nwritten) + super::fd_write::(ctx, fd, iovs, iovs_len, nwritten) } pub(crate) fn path_create_directory( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_create_directory::(env, fd, path, path_len) + super::path_create_directory::(ctx, fd, path, path_len) } pub(crate) fn path_filestat_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path: WasmPtr, path_len: MemoryOffset, buf: WasmPtr<__wasi_filestat_t, MemoryType>, ) -> __wasi_errno_t { - super::path_filestat_get::(env, fd, flags, path, path_len, buf) + super::path_filestat_get::(ctx, fd, flags, path, path_len, buf) } pub(crate) fn path_filestat_set_times( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, flags: __wasi_lookupflags_t, path: WasmPtr, @@ -260,12 +264,12 @@ pub(crate) fn path_filestat_set_times( fst_flags: __wasi_fstflags_t, ) -> __wasi_errno_t { super::path_filestat_set_times::( - env, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, + ctx, fd, flags, path, path_len, st_atim, st_mtim, fst_flags, ) } pub(crate) fn path_link( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_fd: __wasi_fd_t, old_flags: __wasi_lookupflags_t, old_path: WasmPtr, @@ -275,7 +279,7 @@ pub(crate) fn path_link( new_path_len: MemoryOffset, ) -> __wasi_errno_t { super::path_link::( - env, + ctx, old_fd, old_flags, old_path, @@ -287,7 +291,7 @@ pub(crate) fn path_link( } pub(crate) fn path_open( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, dirfd: __wasi_fd_t, dirflags: __wasi_lookupflags_t, path: WasmPtr, @@ -299,7 +303,7 @@ pub(crate) fn path_open( fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { super::path_open::( - env, + ctx, dirfd, dirflags, path, @@ -313,7 +317,7 @@ pub(crate) fn path_open( } pub(crate) fn path_readlink( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, dir_fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, @@ -321,20 +325,20 @@ pub(crate) fn path_readlink( buf_len: MemoryOffset, buf_used: WasmPtr, ) -> __wasi_errno_t { - super::path_readlink::(env, dir_fd, path, path_len, buf, buf_len, buf_used) + super::path_readlink::(ctx, dir_fd, path, path_len, buf, buf_len, buf_used) } pub(crate) fn path_remove_directory( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_remove_directory::(env, fd, path, path_len) + super::path_remove_directory::(ctx, fd, path, path_len) } pub(crate) fn path_rename( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_fd: __wasi_fd_t, old_path: WasmPtr, old_path_len: MemoryOffset, @@ -343,7 +347,7 @@ pub(crate) fn path_rename( new_path_len: MemoryOffset, ) -> __wasi_errno_t { super::path_rename::( - env, + ctx, old_fd, old_path, old_path_len, @@ -354,159 +358,168 @@ pub(crate) fn path_rename( } pub(crate) fn path_symlink( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, old_path: WasmPtr, old_path_len: MemoryOffset, fd: __wasi_fd_t, new_path: WasmPtr, new_path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_symlink::(env, old_path, old_path_len, fd, new_path, new_path_len) + super::path_symlink::(ctx, old_path, old_path_len, fd, new_path, new_path_len) } pub(crate) fn path_unlink_file( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::path_unlink_file::(env, fd, path, path_len) + super::path_unlink_file::(ctx, fd, path, path_len) } pub(crate) fn poll_oneoff( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, in_: WasmPtr<__wasi_subscription_t, MemoryType>, out_: WasmPtr<__wasi_event_t, MemoryType>, nsubscriptions: MemoryOffset, nevents: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::poll_oneoff::(env, in_, out_, nsubscriptions, nevents) + super::poll_oneoff::(ctx, in_, out_, nsubscriptions, nevents) } -pub(crate) fn proc_exit(env: &WasiEnv, code: __wasi_exitcode_t) -> Result<(), WasiError> { - super::proc_exit(env, code) +pub(crate) fn proc_exit( + ctx: ContextMut<'_, WasiEnv>, + code: __wasi_exitcode_t, +) -> Result<(), WasiError> { + super::proc_exit(ctx, code) } -pub(crate) fn proc_raise(env: &WasiEnv, sig: __wasi_signal_t) -> __wasi_errno_t { - super::proc_raise(env, sig) +pub(crate) fn proc_raise(ctx: ContextMut<'_, WasiEnv>, sig: __wasi_signal_t) -> __wasi_errno_t { + super::proc_raise(ctx, sig) } pub(crate) fn random_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, buf: WasmPtr, buf_len: MemoryOffset, ) -> __wasi_errno_t { - super::random_get::(env, buf, buf_len) + super::random_get::(ctx, buf, buf_len) } pub(crate) fn fd_dup( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, fd: __wasi_fd_t, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_dup::(env, fd, ret_fd) + super::fd_dup::(ctx, fd, ret_fd) } pub(crate) fn fd_event( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, initial_val: u64, flags: __wasi_eventfdflags, ret_fd: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_event(env, initial_val, flags, ret_fd) + super::fd_event(ctx, initial_val, flags, ret_fd) } pub(crate) fn fd_pipe( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ro_fd1: WasmPtr<__wasi_fd_t, MemoryType>, ro_fd2: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::fd_pipe::(env, ro_fd1, ro_fd2) + super::fd_pipe::(ctx, ro_fd1, ro_fd2) } pub(crate) fn tty_get( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, ) -> __wasi_errno_t { - super::tty_get::(env, tty_state) + super::tty_get::(ctx, tty_state) } pub(crate) fn tty_set( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, tty_state: WasmPtr<__wasi_tty_t, MemoryType>, ) -> __wasi_errno_t { - super::tty_set::(env, tty_state) + super::tty_set::(ctx, tty_state) } pub(crate) fn getcwd( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, path: WasmPtr, path_len: WasmPtr, ) -> __wasi_errno_t { - super::getcwd::(env, path, path_len) + super::getcwd::(ctx, path, path_len) } pub(crate) fn chdir( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, path: WasmPtr, path_len: MemoryOffset, ) -> __wasi_errno_t { - super::chdir::(env, path, path_len) + super::chdir::(ctx, path, path_len) } pub(crate) fn thread_spawn( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, method: WasmPtr, method_len: MemoryOffset, user_data: u64, reactor: __wasi_bool_t, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, ) -> __wasi_errno_t { - super::thread_spawn::(env, method, method_len, user_data, reactor, ret_tid) + super::thread_spawn::(ctx, method, method_len, user_data, reactor, ret_tid) } pub(crate) fn thread_sleep( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, duration: __wasi_timestamp_t, ) -> Result<__wasi_errno_t, WasiError> { - super::thread_sleep(env, duration) + super::thread_sleep(ctx, duration) } pub(crate) fn thread_id( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ret_tid: WasmPtr<__wasi_tid_t, MemoryType>, ) -> __wasi_errno_t { - super::thread_id::(env, ret_tid) + super::thread_id::(ctx, ret_tid) } -pub(crate) fn thread_join(env: &WasiEnv, tid: __wasi_tid_t) -> Result<__wasi_errno_t, WasiError> { - super::thread_join(env, tid) +pub(crate) fn thread_join( + ctx: ContextMut<'_, WasiEnv>, + tid: __wasi_tid_t, +) -> Result<__wasi_errno_t, WasiError> { + super::thread_join(ctx, tid) } pub(crate) fn thread_parallelism( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ret_parallelism: WasmPtr, ) -> __wasi_errno_t { - super::thread_parallelism::(env, ret_parallelism) + super::thread_parallelism::(ctx, ret_parallelism) } pub(crate) fn thread_exit( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, exitcode: __wasi_exitcode_t, ) -> Result<__wasi_errno_t, WasiError> { - super::thread_exit(env, exitcode) + super::thread_exit(ctx, exitcode) } -pub(crate) fn sched_yield(env: &WasiEnv) -> Result<__wasi_errno_t, WasiError> { - super::sched_yield(env) +pub(crate) fn sched_yield(ctx: ContextMut<'_, WasiEnv>) -> Result<__wasi_errno_t, WasiError> { + super::sched_yield(ctx) } -pub(crate) fn getpid(env: &WasiEnv, ret_pid: WasmPtr<__wasi_pid_t, MemoryType>) -> __wasi_errno_t { - super::getpid::(env, ret_pid) +pub(crate) fn getpid( + ctx: ContextMut<'_, WasiEnv>, + ret_pid: WasmPtr<__wasi_pid_t, MemoryType>, +) -> __wasi_errno_t { + super::getpid::(ctx, ret_pid) } pub(crate) fn process_spawn( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, name: WasmPtr, name_len: MemoryOffset, chroot: __wasi_bool_t, @@ -522,7 +535,7 @@ pub(crate) fn process_spawn( ret_handles: WasmPtr<__wasi_bus_handles_t, MemoryType>, ) -> __bus_errno_t { super::process_spawn::( - env, + ctx, name, name_len, chroot, @@ -540,17 +553,17 @@ pub(crate) fn process_spawn( } pub(crate) fn bus_open_local( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, name: WasmPtr, name_len: MemoryOffset, reuse: __wasi_bool_t, ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, ) -> __bus_errno_t { - super::bus_open_local::(env, name, name_len, reuse, ret_bid) + super::bus_open_local::(ctx, name, name_len, reuse, ret_bid) } pub(crate) fn bus_open_remote( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, name: WasmPtr, name_len: MemoryOffset, reuse: __wasi_bool_t, @@ -561,7 +574,7 @@ pub(crate) fn bus_open_remote( ret_bid: WasmPtr<__wasi_bid_t, MemoryType>, ) -> __bus_errno_t { super::bus_open_remote::( - env, + ctx, name, name_len, reuse, @@ -573,12 +586,12 @@ pub(crate) fn bus_open_remote( ) } -pub(crate) fn bus_close(env: &WasiEnv, bid: __wasi_bid_t) -> __bus_errno_t { - super::bus_close(env, bid) +pub(crate) fn bus_close(ctx: ContextMut<'_, WasiEnv>, bid: __wasi_bid_t) -> __bus_errno_t { + super::bus_close(ctx, bid) } pub(crate) fn bus_call( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, bid: __wasi_bid_t, keep_alive: __wasi_bool_t, topic: WasmPtr, @@ -589,12 +602,12 @@ pub(crate) fn bus_call( ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, ) -> __bus_errno_t { super::bus_call::( - env, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, + ctx, bid, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) } pub(crate) fn bus_subcall( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, parent: __wasi_cid_t, keep_alive: __wasi_bool_t, topic: WasmPtr, @@ -605,12 +618,12 @@ pub(crate) fn bus_subcall( ret_cid: WasmPtr<__wasi_cid_t, MemoryType>, ) -> __bus_errno_t { super::bus_subcall::( - env, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, + ctx, parent, keep_alive, topic, topic_len, format, buf, buf_len, ret_cid, ) } pub(crate) fn bus_poll( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, timeout: __wasi_timestamp_t, events: WasmPtr, nevents: MemoryOffset, @@ -619,7 +632,7 @@ pub(crate) fn bus_poll( ret_nevents: WasmPtr, ) -> __bus_errno_t { super::bus_poll::( - env, + ctx, timeout, events, nevents, @@ -630,122 +643,126 @@ pub(crate) fn bus_poll( } pub(crate) fn call_reply( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, cid: __wasi_cid_t, format: __wasi_busdataformat_t, buf: WasmPtr, buf_len: MemoryOffset, ) -> __bus_errno_t { - super::call_reply::(env, cid, format, buf, buf_len) + super::call_reply::(ctx, cid, format, buf, buf_len) } -pub(crate) fn call_fault(env: &WasiEnv, cid: __wasi_cid_t, fault: __bus_errno_t) -> __bus_errno_t { - super::call_fault(env, cid, fault) +pub(crate) fn call_fault( + ctx: ContextMut<'_, WasiEnv>, + cid: __wasi_cid_t, + fault: __bus_errno_t, +) -> __bus_errno_t { + super::call_fault(ctx, cid, fault) } -pub(crate) fn call_close(env: &WasiEnv, cid: __wasi_cid_t) -> __bus_errno_t { - super::call_close(env, cid) +pub(crate) fn call_close(ctx: ContextMut<'_, WasiEnv>, cid: __wasi_cid_t) -> __bus_errno_t { + super::call_close(ctx, cid) } pub(crate) fn port_bridge( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, network: WasmPtr, network_len: MemoryOffset, token: WasmPtr, token_len: MemoryOffset, security: __wasi_streamsecurity_t, ) -> __wasi_errno_t { - super::port_bridge::(env, network, network_len, token, token_len, security) + super::port_bridge::(ctx, network, network_len, token, token_len, security) } -pub(crate) fn port_unbridge(env: &WasiEnv) -> __wasi_errno_t { - super::port_unbridge(env) +pub(crate) fn port_unbridge(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_unbridge(ctx) } -pub(crate) fn port_dhcp_acquire(env: &WasiEnv) -> __wasi_errno_t { - super::port_dhcp_acquire(env) +pub(crate) fn port_dhcp_acquire(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_dhcp_acquire(ctx) } pub(crate) fn port_addr_add( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, addr: WasmPtr<__wasi_cidr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_addr_add::(env, addr) + super::port_addr_add::(ctx, addr) } pub(crate) fn port_addr_remove( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, addr: WasmPtr<__wasi_addr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_addr_remove::(env, addr) + super::port_addr_remove::(ctx, addr) } -pub(crate) fn port_addr_clear(env: &WasiEnv) -> __wasi_errno_t { - super::port_addr_clear(env) +pub(crate) fn port_addr_clear(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_addr_clear(ctx) } pub(crate) fn port_addr_list( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, addrs: WasmPtr<__wasi_cidr_t, MemoryType>, naddrs: WasmPtr, ) -> __wasi_errno_t { - super::port_addr_list::(env, addrs, naddrs) + super::port_addr_list::(ctx, addrs, naddrs) } pub(crate) fn port_mac( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ret_mac: WasmPtr<__wasi_hardwareaddress_t, MemoryType>, ) -> __wasi_errno_t { - super::port_mac::(env, ret_mac) + super::port_mac::(ctx, ret_mac) } pub(crate) fn port_gateway_set( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_gateway_set::(env, ip) + super::port_gateway_set::(ctx, ip) } pub(crate) fn port_route_add( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, cidr: WasmPtr<__wasi_cidr_t, MemoryType>, via_router: WasmPtr<__wasi_addr_t, MemoryType>, preferred_until: WasmPtr<__wasi_option_timestamp_t, MemoryType>, expires_at: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::port_route_add::(env, cidr, via_router, preferred_until, expires_at) + super::port_route_add::(ctx, cidr, via_router, preferred_until, expires_at) } pub(crate) fn port_route_remove( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, MemoryType>, ) -> __wasi_errno_t { - super::port_route_remove::(env, ip) + super::port_route_remove::(ctx, ip) } -pub(crate) fn port_route_clear(env: &WasiEnv) -> __wasi_errno_t { - super::port_route_clear(env) +pub(crate) fn port_route_clear(ctx: ContextMut<'_, WasiEnv>) -> __wasi_errno_t { + super::port_route_clear(ctx) } pub(crate) fn port_route_list( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, routes: WasmPtr<__wasi_route_t, MemoryType>, nroutes: WasmPtr, ) -> __wasi_errno_t { - super::port_route_list::(env, routes, nroutes) + super::port_route_list::(ctx, routes, nroutes) } pub(crate) fn ws_connect( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, url: WasmPtr, url_len: MemoryOffset, ret_sock: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::ws_connect::(env, url, url_len, ret_sock) + super::ws_connect::(ctx, url, url_len, ret_sock) } pub(crate) fn http_request( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, url: WasmPtr, url_len: MemoryOffset, method: WasmPtr, @@ -756,7 +773,7 @@ pub(crate) fn http_request( ret_handles: WasmPtr<__wasi_http_handles_t, MemoryType>, ) -> __wasi_errno_t { super::http_request::( - env, + ctx, url, url_len, method, @@ -769,7 +786,7 @@ pub(crate) fn http_request( } pub(crate) fn http_status( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, status: WasmPtr<__wasi_http_status_t, MemoryType>, status_text: WasmPtr, @@ -777,169 +794,169 @@ pub(crate) fn http_status( headers: WasmPtr, headers_len: WasmPtr, ) -> __wasi_errno_t { - super::http_status::(env, sock, status) + super::http_status::(ctx, sock, status) } pub(crate) fn sock_status( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ret_status: WasmPtr<__wasi_sockstatus_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_status::(env, sock, ret_status) + super::sock_status::(ctx, sock, ret_status) } pub(crate) fn sock_addr_local( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ret_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_addr_local::(env, sock, ret_addr) + super::sock_addr_local::(ctx, sock, ret_addr) } pub(crate) fn sock_addr_peer( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_addr_peer::(env, sock, ro_addr) + super::sock_addr_peer::(ctx, sock, ro_addr) } pub(crate) fn sock_open( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, af: __wasi_addressfamily_t, ty: __wasi_socktype_t, pt: __wasi_sockproto_t, ro_sock: WasmPtr<__wasi_fd_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_open::(env, af, ty, pt, ro_sock) + super::sock_open::(ctx, af, ty, pt, ro_sock) } pub(crate) fn sock_set_opt_flag( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, flag: __wasi_bool_t, ) -> __wasi_errno_t { - super::sock_set_opt_flag(env, sock, opt, flag) + super::sock_set_opt_flag(ctx, sock, opt, flag) } pub(crate) fn sock_get_opt_flag( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_flag: WasmPtr<__wasi_bool_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_get_opt_flag::(env, sock, opt, ret_flag) + super::sock_get_opt_flag::(ctx, sock, opt, ret_flag) } pub fn sock_set_opt_time( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_set_opt_time(env, sock, opt, time) + super::sock_set_opt_time(ctx, sock, opt, time) } pub fn sock_get_opt_time( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_time: WasmPtr<__wasi_option_timestamp_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_get_opt_time(env, sock, opt, ret_time) + super::sock_get_opt_time(ctx, sock, opt, ret_time) } pub fn sock_set_opt_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, size: __wasi_filesize_t, ) -> __wasi_errno_t { - super::sock_set_opt_size(env, sock, opt, size) + super::sock_set_opt_size(ctx, sock, opt, size) } pub fn sock_get_opt_size( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, opt: __wasi_sockoption_t, ret_size: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_get_opt_size(env, sock, opt, ret_size) + super::sock_get_opt_size(ctx, sock, opt, ret_size) } pub(crate) fn sock_join_multicast_v4( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_join_multicast_v4::(env, sock, multiaddr, iface) + super::sock_join_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v4( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip4_t, MemoryType>, iface: WasmPtr<__wasi_addr_ip4_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_leave_multicast_v4::(env, sock, multiaddr, iface) + super::sock_leave_multicast_v4::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_join_multicast_v6( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> __wasi_errno_t { - super::sock_join_multicast_v6::(env, sock, multiaddr, iface) + super::sock_join_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_leave_multicast_v6( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, multiaddr: WasmPtr<__wasi_addr_ip6_t, MemoryType>, iface: u32, ) -> __wasi_errno_t { - super::sock_leave_multicast_v6::(env, sock, multiaddr, iface) + super::sock_leave_multicast_v6::(ctx, sock, multiaddr, iface) } pub(crate) fn sock_bind( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_bind::(env, sock, addr) + super::sock_bind::(ctx, sock, addr) } pub(crate) fn sock_listen( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, backlog: MemoryOffset, ) -> __wasi_errno_t { - super::sock_listen::(env, sock, backlog) + super::sock_listen::(ctx, sock, backlog) } pub(crate) fn sock_accept( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, fd_flags: __wasi_fdflags_t, ro_fd: WasmPtr<__wasi_fd_t, MemoryType>, ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - super::sock_accept::(env, sock, fd_flags, ro_fd, ro_addr) + super::sock_accept::(ctx, sock, fd_flags, ro_fd, ro_addr) } pub(crate) fn sock_connect( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> __wasi_errno_t { - super::sock_connect::(env, sock, addr) + super::sock_connect::(ctx, sock, addr) } pub(crate) fn sock_recv( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, @@ -948,7 +965,7 @@ pub(crate) fn sock_recv( ro_flags: WasmPtr<__wasi_roflags_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { super::sock_recv::( - env, + ctx, sock, ri_data, ri_data_len, @@ -959,7 +976,7 @@ pub(crate) fn sock_recv( } pub(crate) fn sock_recv_from( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, ri_data: WasmPtr<__wasi_iovec_t, MemoryType>, ri_data_len: MemoryOffset, @@ -969,7 +986,7 @@ pub(crate) fn sock_recv_from( ro_addr: WasmPtr<__wasi_addr_port_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { super::sock_recv_from::( - env, + ctx, sock, ri_data, ri_data_len, @@ -981,18 +998,18 @@ pub(crate) fn sock_recv_from( } pub(crate) fn sock_send( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, si_flags: __wasi_siflags_t, ret_data_len: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { - super::sock_send::(env, sock, si_data, si_data_len, si_flags, ret_data_len) + super::sock_send::(ctx, sock, si_data, si_data_len, si_flags, ret_data_len) } pub(crate) fn sock_send_to( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, si_data: WasmPtr<__wasi_ciovec_t, MemoryType>, si_data_len: MemoryOffset, @@ -1001,7 +1018,7 @@ pub(crate) fn sock_send_to( ret_data_len: WasmPtr, ) -> Result<__wasi_errno_t, WasiError> { super::sock_send_to::( - env, + ctx, sock, si_data, si_data_len, @@ -1012,26 +1029,26 @@ pub(crate) fn sock_send_to( } pub(crate) fn sock_send_file( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, out_fd: __wasi_fd_t, in_fd: __wasi_fd_t, offset: __wasi_filesize_t, count: __wasi_filesize_t, ret_sent: WasmPtr<__wasi_filesize_t, MemoryType>, ) -> Result<__wasi_errno_t, WasiError> { - unsafe { super::sock_send_file::(env, out_fd, in_fd, offset, count, ret_sent) } + unsafe { super::sock_send_file::(ctx, out_fd, in_fd, offset, count, ret_sent) } } pub(crate) fn sock_shutdown( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, sock: __wasi_fd_t, how: __wasi_sdflags_t, ) -> __wasi_errno_t { - super::sock_shutdown(env, sock, how) + super::sock_shutdown(ctx, sock, how) } pub(crate) fn resolve( - env: &WasiEnv, + ctx: ContextMut<'_, WasiEnv>, host: WasmPtr, host_len: MemoryOffset, port: u16, @@ -1039,5 +1056,5 @@ pub(crate) fn resolve( nips: MemoryOffset, ret_nips: WasmPtr, ) -> __wasi_errno_t { - super::resolve::(env, host, host_len, port, ips, nips, ret_nips) + super::resolve::(ctx, host, host_len, port, ips, nips, ret_nips) }