Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add realtime and monotonic clock support for wasi on windows #459

Merged
merged 6 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

- run:
name: Release Build
command: |
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ log = "0.4.6"
byteorder = "1.3.1"
# hack to get tests to work
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
winapi = "0.3"
MarkMcCaskey marked this conversation as resolved.
Show resolved Hide resolved

[build-dependencies]
glob = "0.2.11"
Expand Down
2 changes: 2 additions & 0 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#[macro_use]
extern crate log;
#[cfg(target = "windows")]
extern crate winapi;

#[macro_use]
mod macros;
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 40 additions & 2 deletions lib/wasi/src/syscalls/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,51 @@ 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(
clock_id: __wasi_clockid_t,
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
}