From bd09343fcad694128b559da0ce4c6e383eb29d93 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 28 Mar 2019 17:09:39 -0700 Subject: [PATCH] add structure for cross-platform wasi syscall implementations --- lib/wasi/src/syscalls/mod.rs | 20 +++++++++++++------- lib/wasi/src/syscalls/unix/linux.rs | 19 +++++++++++++++++++ lib/wasi/src/syscalls/unix/macos.rs | 19 +++++++++++++++++++ lib/wasi/src/syscalls/unix/mod.rs | 11 +++++++++++ lib/wasi/src/syscalls/windows.rs | 19 +++++++++++++++++++ 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 lib/wasi/src/syscalls/unix/linux.rs create mode 100644 lib/wasi/src/syscalls/unix/macos.rs create mode 100644 lib/wasi/src/syscalls/unix/mod.rs create mode 100644 lib/wasi/src/syscalls/windows.rs diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0c5f2f9b0..077a61155 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,6 +1,19 @@ +pub mod types; +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub mod unix; +#[cfg(any(target_os = "windows"))] +pub mod windows; + use crate::state::WasiState; +use types::*; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub use unix::*; + +#[cfg(any(target_os = "windows"))] +pub use windows::*; + #[allow(clippy::mut_from_ref)] fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { unsafe { &mut *(ctx.data as *mut WasiState) } @@ -59,13 +72,6 @@ pub fn args_sizes_get(ctx: &mut Ctx, argc_out: u32, argv_buf_size_out: u32) { memory.view::()[(argv_buf_size_out / 4) as usize].set(total_arg_size as u32); } -pub fn clock_res_get(ctx: &mut Ctx) { - unimplemented!() -} -pub fn clock_time_get(ctx: &mut Ctx) { - unimplemented!() -} - /// ### `environ_get()` /// Read environment variable data. /// The sizes of the buffers should match that returned by [`environ_sizes_get()`](#environ_sizes_get). diff --git a/lib/wasi/src/syscalls/unix/linux.rs b/lib/wasi/src/syscalls/unix/linux.rs new file mode 100644 index 000000000..c3556faba --- /dev/null +++ b/lib/wasi/src/syscalls/unix/linux.rs @@ -0,0 +1,19 @@ +use crate::syscalls::types::*; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; + +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + __WASI_EINVAL +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + unimplemented!() +} diff --git a/lib/wasi/src/syscalls/unix/macos.rs b/lib/wasi/src/syscalls/unix/macos.rs new file mode 100644 index 000000000..c3556faba --- /dev/null +++ b/lib/wasi/src/syscalls/unix/macos.rs @@ -0,0 +1,19 @@ +use crate::syscalls::types::*; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; + +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + __WASI_EINVAL +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + unimplemented!() +} diff --git a/lib/wasi/src/syscalls/unix/mod.rs b/lib/wasi/src/syscalls/unix/mod.rs new file mode 100644 index 000000000..8fab04668 --- /dev/null +++ b/lib/wasi/src/syscalls/unix/mod.rs @@ -0,0 +1,11 @@ +#[cfg(target_os = "linux")] +pub mod linux; + +#[cfg(target_os = "macos")] +pub mod macos; + +#[cfg(target_os = "linux")] +pub use linux::*; + +#[cfg(target_os = "macos")] +pub use macos::*; diff --git a/lib/wasi/src/syscalls/windows.rs b/lib/wasi/src/syscalls/windows.rs new file mode 100644 index 000000000..c3556faba --- /dev/null +++ b/lib/wasi/src/syscalls/windows.rs @@ -0,0 +1,19 @@ +use crate::syscalls::types::*; +use wasmer_runtime_core::{memory::Memory, vm::Ctx}; + +pub fn clock_res_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + resolution: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + __WASI_EINVAL +} + +pub fn clock_time_get( + ctx: &mut Ctx, + clock_id: __wasi_clockid_t, + precision: __wasi_timestamp_t, + time: WasmPtr<__wasi_timestamp_t>, +) -> __wasi_errno_t { + unimplemented!() +}