clock_gettime(clk_id:i32, ts_ptr) -> i32
| 88 | |
| 89 | // clock_gettime(clk_id:i32, ts_ptr) -> i32 |
| 90 | static std::vector<Value> proc_clock_gettime(Stack& stack) { |
| 91 | Frame& frame = stack.frames.top(); |
| 92 | i32_t clk_id = std::get<i32_t>(frame.locals[0]); |
| 93 | i64_t ts_ptr = get_ptr(frame.locals[1]); |
| 94 | |
| 95 | bool monotonic; |
| 96 | switch(clk_id) { |
| 97 | case WASM_CLOCK_REALTIME: monotonic = false; break; |
| 98 | case WASM_CLOCK_MONOTONIC: monotonic = true; break; |
| 99 | default: return {Value(i32_t(-EINVAL))}; |
| 100 | } |
| 101 | |
| 102 | auto [sec, nsec] = WasmVM::sysenv_compat::clock_now_ns(monotonic); |
| 103 | |
| 104 | try { |
| 105 | uint8_t buf[WASM_TIMESPEC_SIZE]; |
| 106 | std::memcpy(buf + 0, &sec, 8); |
| 107 | std::memcpy(buf + 8, &nsec, 4); |
| 108 | mem_write(stack, ts_ptr, buf, WASM_TIMESPEC_SIZE); |
| 109 | return {Value(i32_t(0))}; |
| 110 | } catch(...) { |
| 111 | return {Value(i32_t(-EFAULT))}; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // ---- Registration ----------------------------------------------------------- |
| 116 |
nothing calls this directly
no test coverage detected