Skip to content

Commit f77c2c6

Browse files
committed
export wasi_clock_time_get
Signed-off-by: mathetake <takeshi@tetrate.io>
1 parent 49ed20e commit f77c2c6

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

include/proxy-wasm/exports.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Word wasi_unstable_environ_sizes_get(void *raw_context, Word count_ptr, Word buf
144144
Word wasi_unstable_args_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
145145
Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_buf_size_ptr);
146146
void wasi_unstable_proc_exit(void *, Word);
147-
void wasi_unstable_proc_exit(void *, Word);
147+
Word wasi_unstable_clock_time_get(void *, Word, int64_t, Word);
148148
Word pthread_equal(void *, Word left, Word right);
149149

150150
// Support for embedders, not exported to Wasm.

include/proxy-wasm/wasm_vm.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ template <size_t N> using WasmCallbackWord = WasmFuncType<N, Word, void *, Word>
7676
// Extended with W = Word
7777
// Z = void, j = uint32_t, l = int64_t, m = uint64_t
7878
using WasmCallback_WWl = Word (*)(void *, Word, int64_t);
79+
using WasmCallback_WWlW = Word (*)(void *, Word, int64_t, Word);
7980
using WasmCallback_WWlWW = Word (*)(void *, Word, int64_t, Word, Word);
8081
using WasmCallback_WWm = Word (*)(void *, Word, uint64_t);
8182
using WasmCallback_dd = double (*)(void *, double);
@@ -92,9 +93,10 @@ using WasmCallback_dd = double (*)(void *, double);
9293
_f(proxy_wasm::WasmCallbackWord<10>) \
9394
_f(proxy_wasm::WasmCallbackWord<12>) \
9495
_f(proxy_wasm::WasmCallback_WWl) \
95-
_f(proxy_wasm::WasmCallback_WWlWW) \
96-
_f(proxy_wasm::WasmCallback_WWm) \
97-
_f(proxy_wasm::WasmCallback_dd)
96+
_f(proxy_wasm::WasmCallback_WWlW) \
97+
_f(proxy_wasm::WasmCallback_WWlWW) \
98+
_f(proxy_wasm::WasmCallback_WWm) \
99+
_f(proxy_wasm::WasmCallback_dd)
98100

99101
enum class Cloneable {
100102
NotCloneable, // VMs can not be cloned and should be created from scratch.

src/exports.cc

+16
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,22 @@ Word wasi_unstable_args_sizes_get(void *raw_context, Word argc_ptr, Word argv_bu
798798
return 0; // __WASI_ESUCCESS
799799
}
800800

801+
// __wasi_errno_t __wasi_clock_time_get(uint32_t *id, uint64_t precision, uint64_t* time);
802+
Word wasi_unstable_clock_time_get(void *raw_context, Word clock_id, int64_t precision,
803+
Word result_time_uint64_ptr) {
804+
805+
if (clock_id != 0 /* realtime */) {
806+
return 58; // __WASI_ENOTSUP
807+
}
808+
809+
auto context = WASM_CONTEXT(raw_context);
810+
uint64_t result = context->getCurrentTimeNanoseconds();
811+
if (!context->wasm()->setDatatype(result_time_uint64_ptr, result)) {
812+
return 21; // __WASI_EFAULT
813+
}
814+
return 0; // __WASI_ESUCCESS
815+
}
816+
801817
// void __wasi_proc_exit(__wasi_exitcode_t rval);
802818
void wasi_unstable_proc_exit(void *raw_context, Word) {
803819
auto context = WASM_CONTEXT(raw_context);

src/wasm.cc

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void WasmBase::registerCallbacks() {
131131
_REGISTER_WASI(environ_sizes_get);
132132
_REGISTER_WASI(args_get);
133133
_REGISTER_WASI(args_sizes_get);
134+
_REGISTER_WASI(clock_time_get);
134135
_REGISTER_WASI(proc_exit);
135136
#undef _REGISTER_WASI
136137

0 commit comments

Comments
 (0)