Skip to content

Commit 8fd89bd

Browse files
authored
Implement clock() wrapper for built-in libc (#691)
1 parent 0db04e0 commit 8fd89bd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,14 @@ clock_gettime_wrapper(wasm_exec_env_t exec_env,
10901090
return (uint32)0;
10911091
}
10921092

1093+
static uint64
1094+
clock_wrapper(wasm_exec_env_t exec_env)
1095+
{
1096+
/* Convert to nano seconds as CLOCKS_PER_SEC in wasi-sdk */
1097+
1098+
return os_time_get_boot_microsecond() * 1000;
1099+
}
1100+
10931101
#if WASM_ENABLE_SPEC_TEST != 0
10941102
static void
10951103
print_wrapper(wasm_exec_env_t exec_env)
@@ -1190,6 +1198,7 @@ static NativeSymbol native_symbols_libc_builtin[] = {
11901198
REG_NATIVE_FUNC(__cxa_begin_catch, "(*)"),
11911199
REG_NATIVE_FUNC(__cxa_throw, "(**i)"),
11921200
REG_NATIVE_FUNC(clock_gettime, "(i*)i"),
1201+
REG_NATIVE_FUNC(clock, "()I"),
11931202
};
11941203

11951204
#if WASM_ENABLE_SPEC_TEST != 0

0 commit comments

Comments
 (0)