459: add realtime and monotonic clock support for wasi on windows r=MarkMcCaskey a=MarkMcCaskey

resolves #455 

Co-authored-by: Mark McCaskey <mark@wasmer.io>
This commit is contained in:
bors[bot] 2019-05-21 18:36:08 +00:00
commit 699d65bddb
6 changed files with 51 additions and 7 deletions

View File

@ -176,6 +176,10 @@ jobs:
export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/"
make test-emscripten-clif
make test-emscripten-llvm
- run:
name: Debug flag checked
command: |
cargo check --features "debug"
- run:
name: Release Build
command: |
@ -189,10 +193,6 @@ jobs:
echo "${CIRCLE_TAG}" >> artifacts/git_version
make build-install
cp ./wasmer.tar.gz ./artifacts/$(./binary-name.sh)
- run:
name: Debug flag checked
command: |
cargo check --features "debug"
- persist_to_workspace:
root: .
paths:

1
Cargo.lock generated
View File

@ -2492,6 +2492,7 @@ dependencies = [
"wasmer-dev-utils 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View File

@ -20,6 +20,9 @@ byteorder = "1.3.1"
# hack to get tests to work
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
[target.'cfg(windows)'.dependencies]
winapi = "0.3"
[build-dependencies]
glob = "0.2.11"

View File

@ -2,6 +2,8 @@
#[macro_use]
extern crate log;
#[cfg(target = "windows")]
extern crate winapi;
#[macro_use]
mod macros;

View File

@ -219,7 +219,7 @@ impl WasiFs {
}
debug!("wasi::fs::mapped_dirs");
for (alias, real_dir) in mapped_dirs {
debug!("Attempting to open {:?} at {}", dest_dir, alias);
debug!("Attempting to open {:?} at {}", real_dir, alias);
// TODO: think about this
let default_rights = 0x1FFFFFFF; // all rights
let cur_dir_metadata = real_dir

View File

@ -5,7 +5,22 @@ pub fn platform_clock_res_get(
clock_id: __wasi_clockid_t,
resolution: &Cell<__wasi_timestamp_t>,
) -> __wasi_errno_t {
__WASI_EINVAL
let resolution_val = match clock_id {
// resolution of monotonic clock at 10ms, from:
// https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-gettickcount64
__WASI_CLOCK_MONOTONIC => 10_000_000,
// TODO: verify or compute this
__WASI_CLOCK_REALTIME => 1,
__WASI_CLOCK_PROCESS_CPUTIME_ID => {
return __WASI_EINVAL;
}
__WASI_CLOCK_THREAD_CPUTIME_ID => {
return __WASI_EINVAL;
}
_ => return __WASI_EINVAL,
};
resolution.set(resolution_val);
__WASI_ESUCCESS
}
pub fn platform_clock_time_get(
@ -13,5 +28,28 @@ pub fn platform_clock_time_get(
precision: __wasi_timestamp_t,
time: &Cell<__wasi_timestamp_t>,
) -> __wasi_errno_t {
unimplemented!()
let nanos = match clock_id {
__WASI_CLOCK_MONOTONIC => {
let tick_ms = unsafe { winapi::um::sysinfoapi::GetTickCount64() };
tick_ms * 1_000_000
}
__WASI_CLOCK_REALTIME => {
let duration = wasi_try!(std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_err(|e| {
debug!("Error in wasi::platform_clock_time_get: {:?}", e);
__WASI_EIO
}));
duration.as_nanos() as u64
}
__WASI_CLOCK_PROCESS_CPUTIME_ID => {
unimplemented!("wasi::platform_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, ..)")
}
__WASI_CLOCK_THREAD_CPUTIME_ID => {
unimplemented!("wasi::platform_clock_time_get(__WASI_CLOCK_THREAD_CPUTIME_ID, ..)")
}
_ => return __WASI_EINVAL,
};
time.set(nanos);
__WASI_ESUCCESS
}