mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 14:25:32 +00:00
Added _clock_gettime emscripten implementation
This commit is contained in:
parent
cb7c7fd475
commit
5911ac58c0
@ -290,6 +290,11 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||
"_gettimeofday",
|
||||
ImportValue::Func(time::_gettimeofday as _),
|
||||
);
|
||||
import_object.set(
|
||||
"env",
|
||||
"_clock_gettime",
|
||||
ImportValue::Func(time::_clock_gettime as _),
|
||||
);
|
||||
mock_external!(import_object, _waitpid);
|
||||
mock_external!(import_object, _utimes);
|
||||
mock_external!(import_object, _usleep);
|
||||
@ -324,7 +329,7 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||
mock_external!(import_object, _exit);
|
||||
mock_external!(import_object, _execve);
|
||||
mock_external!(import_object, _endgrent);
|
||||
mock_external!(import_object, _clock_gettime);
|
||||
// mock_external!(import_object, _clock_gettime);
|
||||
mock_external!(import_object, ___syscall97);
|
||||
mock_external!(import_object, ___syscall91);
|
||||
mock_external!(import_object, ___syscall85);
|
||||
|
32
src/apis/emscripten/time.rs
Normal file
32
src/apis/emscripten/time.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use libc::{gettimeofday, timeval, c_int, clock_gettime, clockid_t, timespec};
|
||||
use std::ptr;
|
||||
|
||||
use crate::webassembly::Instance;
|
||||
|
||||
/// emscripten: _gettimeofday
|
||||
pub extern "C" fn _gettimeofday(timeval_ptr_offset: c_int, tz_offset: c_int, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::_gettimeofday {}", timeval_ptr_offset);
|
||||
|
||||
unsafe {
|
||||
let mut timeval_value = *(instance.memory_offset_addr(0, timeval_ptr_offset as _) as *mut timeval);
|
||||
// We skip the timezone for now
|
||||
let mut tz = ptr::null_mut();
|
||||
debug!("emscripten::_gettimeofday(initial) {} {}", (timeval_value).tv_sec, (timeval_value).tv_usec);
|
||||
|
||||
let returned = gettimeofday(&mut timeval_value, tz);
|
||||
debug!("emscripten::_gettimeofday(filled) {} {}", (timeval_value).tv_sec, (timeval_value).tv_usec);
|
||||
returned
|
||||
}
|
||||
}
|
||||
|
||||
/// emscripten: _clock_gettime
|
||||
pub extern "C" fn _clock_gettime(clk_id: clockid_t, tp_offset: c_int, instance: &mut Instance) -> c_int {
|
||||
debug!("emscripten::_clock_gettime {} {}", clk_id, tp_offset);
|
||||
|
||||
unsafe {
|
||||
let mut tp = instance.memory_offset_addr(0, tp_offset as _) as *mut timespec;
|
||||
let returned = clock_gettime(clk_id, tp);
|
||||
debug!("emscripten::clock_gettime(filled) {} {}", (*tp).tv_sec, (*tp).tv_nsec);
|
||||
returned
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user