mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
improve calling of platform-specific code and impl linux clock calls
This commit is contained in:
parent
23c09ac042
commit
48d34d9522
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1482,6 +1482,7 @@ dependencies = [
|
||||
name = "wasmer-wasi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmer-runtime-core 0.2.1",
|
||||
]
|
||||
|
||||
|
@ -6,3 +6,4 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" }
|
||||
libc = "0.2.50"
|
@ -108,7 +108,13 @@ pub fn clock_res_get(
|
||||
clock_id: __wasi_clockid_t,
|
||||
resolution: WasmPtr<__wasi_timestamp_t>,
|
||||
) -> __wasi_errno_t {
|
||||
platform_clock_res_get(ctx, clock_id, resolution)
|
||||
let memory = ctx.memory(0);
|
||||
|
||||
if let Some(out_addr) = resolution.deref(memory) {
|
||||
platform_clock_res_get(clock_id, out_addr)
|
||||
} else {
|
||||
__WASI_EFAULT
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clock_time_get(
|
||||
@ -117,7 +123,13 @@ pub fn clock_time_get(
|
||||
precision: __wasi_timestamp_t,
|
||||
time: WasmPtr<__wasi_timestamp_t>,
|
||||
) -> __wasi_errno_t {
|
||||
platform_clock_time_get(ctx, clock_id, precision, time)
|
||||
let memory = ctx.memory(0);
|
||||
|
||||
if let Some(out_addr) = time.deref(memory) {
|
||||
platform_clock_time_get(clock_id, precision, out_addr)
|
||||
} else {
|
||||
__WASI_EFAULT
|
||||
}
|
||||
}
|
||||
|
||||
/// ### `environ_get()`
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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!()
|
||||
}
|
||||
|
@ -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!()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user