-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve calling of platform-specific code and impl linux clock calls
- Loading branch information
Mark McCaskey
committed
Mar 29, 2019
1 parent
23c09ac
commit 48d34d9
Showing
6 changed files
with
65 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,54 @@ | ||
use crate::syscalls::types::*; | ||
use crate::ptr::{Array, WasmPtr}, | ||
use wasmer_runtime_core::{memory::Memory, vm::Ctx}; | ||
use libc::{ | ||
clock_getres, clock_gettime, timespec, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, | ||
CLOCK_REALTIME, CLOCK_THREAD_CPUTIME_ID, | ||
}; | ||
use std::cell::Cell; | ||
use std::mem; | ||
|
||
pub fn platform_clock_res_get( | ||
ctx: &mut Ctx, | ||
clock_id: __wasi_clockid_t, | ||
resolution: WasmPtr<__wasi_timestamp_t>, | ||
resolution: &Cell<__wasi_timestamp_t>, | ||
) -> __wasi_errno_t { | ||
__WASI_EINVAL | ||
let linux_clock_id = match clock_id { | ||
__WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, | ||
__WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, | ||
__WASI_CLOCK_REALTIME => CLOCK_REALTIME, | ||
__WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, | ||
_ => return __WASI_EINVAL, | ||
}; | ||
|
||
let output = unsafe { | ||
let mut timespec_out: timespec = mem::uninitialized(); | ||
clock_getres(linux_clock_id, &mut timespec_out); | ||
}; | ||
|
||
resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); | ||
|
||
// TODO: map output of clock_getres to __wasi_errno_t | ||
__WASI_ESUCCESS | ||
} | ||
|
||
pub fn platform_clock_time_get( | ||
ctx: &mut Ctx, | ||
clock_id: __wasi_clockid_t, | ||
precision: __wasi_timestamp_t, | ||
time: WasmPtr<__wasi_timestamp_t>, | ||
time: &Cell<__wasi_timestamp_t>, | ||
) -> __wasi_errno_t { | ||
unimplemented!() | ||
let linux_clock_id = match clock_id { | ||
__WASI_CLOCK_MONOTONIC => CLOCK_MONOTONIC, | ||
__WASI_CLOCK_PROCESS_CPUTIME_ID => CLOCK_PROCESS_CPUTIME_ID, | ||
__WASI_CLOCK_REALTIME => CLOCK_REALTIME, | ||
__WASI_CLOCK_THREAD_CPUTIME_ID => CLOCK_THREAD_CPUTIME_ID, | ||
_ => return __WASI_EINVAL, | ||
}; | ||
|
||
let output = unsafe { | ||
let mut timespec_out: timespec = mem::uninitialized(); | ||
clock_gettime(linux_clock_id, precision, &mut timespec_out); | ||
}; | ||
|
||
resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); | ||
|
||
// TODO: map output of clock_gettime to __wasi_errno_t | ||
__WASI_ESUCCESS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
use crate::syscalls::types::*; | ||
use crate::ptr::{Array, WasmPtr}, | ||
use wasmer_runtime_core::{memory::Memory, vm::Ctx}; | ||
use std::cell::Cell; | ||
|
||
pub fn platform_clock_res_get( | ||
ctx: &mut Ctx, | ||
clock_id: __wasi_clockid_t, | ||
resolution: WasmPtr<__wasi_timestamp_t>, | ||
resolution: &Cell<__wasi_timestamp_t>, | ||
) -> __wasi_errno_t { | ||
__WASI_EINVAL | ||
} | ||
|
||
pub fn platform_clock_time_get( | ||
ctx: &mut Ctx, | ||
clock_id: __wasi_clockid_t, | ||
precision: __wasi_timestamp_t, | ||
time: WasmPtr<__wasi_timestamp_t>, | ||
time: &Cell<__wasi_timestamp_t>, | ||
) -> __wasi_errno_t { | ||
unimplemented!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
use crate::syscalls::types::*; | ||
use crate::ptr::{Array, WasmPtr}, | ||
use wasmer_runtime_core::{memory::Memory, vm::Ctx}; | ||
use std::cell::Cell; | ||
|
||
pub fn platform_clock_res_get( | ||
ctx: &mut Ctx, | ||
clock_id: __wasi_clockid_t, | ||
resolution: WasmPtr<__wasi_timestamp_t>, | ||
resolution: &Cell<__wasi_timestamp_t>, | ||
) -> __wasi_errno_t { | ||
__WASI_EINVAL | ||
} | ||
|
||
pub fn platform_clock_time_get( | ||
ctx: &mut Ctx, | ||
clock_id: __wasi_clockid_t, | ||
precision: __wasi_timestamp_t, | ||
time: WasmPtr<__wasi_timestamp_t>, | ||
time: &Cell<__wasi_timestamp_t>, | ||
) -> __wasi_errno_t { | ||
unimplemented!() | ||
} |