MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / proc_clock_gettime

Function proc_clock_gettime

host/sysenv/sys_proc.cpp:90–113  ·  view source on GitHub ↗

clock_gettime(clk_id:i32, ts_ptr) -> i32

Source from the content-addressed store, hash-verified

88
89// clock_gettime(clk_id:i32, ts_ptr) -> i32
90static 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

Callers

nothing calls this directly

Calls 4

get_ptrFunction · 0.85
ValueClass · 0.85
clock_now_nsFunction · 0.85
mem_writeFunction · 0.85

Tested by

no test coverage detected