Skip to content

Commit

Permalink
export wasi_clock_time_get
Browse files Browse the repository at this point in the history
Signed-off-by: mathetake <takeshi@tetrate.io>
  • Loading branch information
mathetake committed Oct 12, 2020
1 parent 49ed20e commit 7e8f9dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/proxy-wasm/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Word wasi_unstable_environ_sizes_get(void *raw_context, Word count_ptr, Word buf
Word wasi_unstable_args_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
void wasi_unstable_proc_exit(void *, Word);
void wasi_unstable_proc_exit(void *, Word);
Word wasi_unstable_clock_time_get(void *, Word, int64_t, Word);
Word pthread_equal(void *, Word left, Word right);

// Support for embedders, not exported to Wasm.
Expand Down
8 changes: 5 additions & 3 deletions include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ template <size_t N> using WasmCallbackWord = WasmFuncType<N, Word, void *, Word>
// Extended with W = Word
// Z = void, j = uint32_t, l = int64_t, m = uint64_t
using WasmCallback_WWl = Word (*)(void *, Word, int64_t);
using WasmCallback_WWlW = Word (*)(void *, Word, int64_t, Word);
using WasmCallback_WWlWW = Word (*)(void *, Word, int64_t, Word, Word);
using WasmCallback_WWm = Word (*)(void *, Word, uint64_t);
using WasmCallback_dd = double (*)(void *, double);
Expand All @@ -92,9 +93,10 @@ using WasmCallback_dd = double (*)(void *, double);
_f(proxy_wasm::WasmCallbackWord<10>) \
_f(proxy_wasm::WasmCallbackWord<12>) \
_f(proxy_wasm::WasmCallback_WWl) \
_f(proxy_wasm::WasmCallback_WWlWW) \
_f(proxy_wasm::WasmCallback_WWm) \
_f(proxy_wasm::WasmCallback_dd)
_f(proxy_wasm::WasmCallback_WWlW) \
_f(proxy_wasm::WasmCallback_WWlWW) \
_f(proxy_wasm::WasmCallback_WWm) \
_f(proxy_wasm::WasmCallback_dd)

enum class Cloneable {
NotCloneable, // VMs can not be cloned and should be created from scratch.
Expand Down
16 changes: 16 additions & 0 deletions src/exports.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,22 @@ Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_bu
return 0; // __WASI_ESUCCESS
}

// __wasi_errno_t __wasi_args_sizes_get(uint32_t *id, uint64_t precision, uint64_t* time);
Word wasi_unstable_clock_time_get(void *raw_context, Word clock_id, int64_t precision,
Word result_time_uint64_ptr) {

if (clock_id != 0 /* realtime */) {
return 58; // __WASI_ENOTSUP
}

auto context = WASM_CONTEXT(raw_context);
uint64_t result = context->getCurrentTimeNanoseconds();
if (!context->wasm()->setDatatype(result_time_uint64_ptr, result)) {
return 21; // __WASI_EFAULT
}
return 0; // __WASI_ESUCCESS
}

// void __wasi_proc_exit(__wasi_exitcode_t rval);
void wasi_unstable_proc_exit(void *raw_context, Word) {
auto context = WASM_CONTEXT(raw_context);
Expand Down
1 change: 1 addition & 0 deletions src/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void WasmBase::registerCallbacks() {
_REGISTER_WASI(environ_sizes_get);
_REGISTER_WASI(args_get);
_REGISTER_WASI(args_sizes_get);
_REGISTER_WASI(clock_time_get);
_REGISTER_WASI(proc_exit);
#undef _REGISTER_WASI

Expand Down

0 comments on commit 7e8f9dc

Please sign in to comment.