Refactor clock functions to use WASI types (#2666)
Refactoring the clock functions to use WASI types so we can simplify the code and remove some unnecessary boilerplate. See https://github.com/bytecodealliance/wasm-micro-runtime/pull/2637#discussion_r1362202879 for details.
This commit is contained in:
@ -193,7 +193,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_clock_res_get(clock_id, resolution);
|
||||
return os_clock_res_get(clock_id, resolution);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
@ -207,7 +207,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(time, sizeof(wasi_timestamp_t)))
|
||||
return (wasi_errno_t)-1;
|
||||
|
||||
return wasmtime_ssp_clock_time_get(clock_id, precision, time);
|
||||
return os_clock_time_get(clock_id, precision, time);
|
||||
}
|
||||
|
||||
static wasi_errno_t
|
||||
|
||||
@ -41,17 +41,6 @@ wasmtime_ssp_args_sizes_get(struct argv_environ_values *arg_environ,
|
||||
size_t *argc, size_t *argv_buf_size)
|
||||
WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) WARN_UNUSED;
|
||||
|
||||
__wasi_errno_t
|
||||
wasmtime_ssp_clock_res_get(__wasi_clockid_t clock_id,
|
||||
__wasi_timestamp_t *resolution)
|
||||
WASMTIME_SSP_SYSCALL_NAME(clock_res_get) WARN_UNUSED;
|
||||
|
||||
__wasi_errno_t
|
||||
wasmtime_ssp_clock_time_get(__wasi_clockid_t clock_id,
|
||||
__wasi_timestamp_t precision,
|
||||
__wasi_timestamp_t *time)
|
||||
WASMTIME_SSP_SYSCALL_NAME(clock_time_get) WARN_UNUSED;
|
||||
|
||||
__wasi_errno_t
|
||||
wasmtime_ssp_environ_get(struct argv_environ_values *arg_environ,
|
||||
char **environs, char *environ_buf)
|
||||
|
||||
@ -94,7 +94,7 @@ ns_lookup_list_search(char **list, const char *host)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef BH_PLATFORM_WINDOWS
|
||||
#if !defined(BH_PLATFORM_WINDOWS) && CONFIG_HAS_CLOCK_NANOSLEEP
|
||||
static bool
|
||||
wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out)
|
||||
{
|
||||
@ -197,52 +197,6 @@ wasi_addr_ip_to_bh_ip_addr_buffer(__wasi_addr_ip_t *addr,
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
wasi_clockid_to_bh_clockid(__wasi_clockid_t in, bh_clock_id_t *out)
|
||||
{
|
||||
switch (in) {
|
||||
case __WASI_CLOCK_MONOTONIC:
|
||||
*out = BH_CLOCK_ID_MONOTONIC;
|
||||
return true;
|
||||
case __WASI_CLOCK_PROCESS_CPUTIME_ID:
|
||||
*out = BH_CLOCK_ID_PROCESS_CPUTIME_ID;
|
||||
return true;
|
||||
case __WASI_CLOCK_REALTIME:
|
||||
*out = BH_CLOCK_ID_REALTIME;
|
||||
return true;
|
||||
case __WASI_CLOCK_THREAD_CPUTIME_ID:
|
||||
*out = BH_CLOCK_ID_THREAD_CPUTIME_ID;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__wasi_errno_t
|
||||
wasmtime_ssp_clock_res_get(__wasi_clockid_t clock_id,
|
||||
__wasi_timestamp_t *resolution)
|
||||
{
|
||||
bh_clock_id_t bh_clockid;
|
||||
if (!wasi_clockid_to_bh_clockid(clock_id, &bh_clockid))
|
||||
return __WASI_EINVAL;
|
||||
if (os_clock_res_get(clock_id, resolution) != BHT_OK)
|
||||
return convert_errno(errno);
|
||||
return __WASI_ESUCCESS;
|
||||
}
|
||||
|
||||
__wasi_errno_t
|
||||
wasmtime_ssp_clock_time_get(__wasi_clockid_t clock_id,
|
||||
__wasi_timestamp_t precision,
|
||||
__wasi_timestamp_t *time)
|
||||
{
|
||||
bh_clock_id_t bh_clockid;
|
||||
if (!wasi_clockid_to_bh_clockid(clock_id, &bh_clockid))
|
||||
return __WASI_EINVAL;
|
||||
if (os_clock_time_get(clock_id, precision, time) != BHT_OK)
|
||||
return convert_errno(errno);
|
||||
return __WASI_ESUCCESS;
|
||||
}
|
||||
|
||||
struct fd_prestat {
|
||||
const char *dir;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user