{"record":{"id":"7922027d9ee0cc0b","repo":"wasmerio/wasmer","slug":"wasi-platform-clock-time-get-wasi-clockid-threa","errorCode":null,"errorMessage":"wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)","messagePattern":"wasi::platform_clock_time_get\\(wasi::Clockid::ThreadCputimeId, \\.\\.\\)","errorType":"panic","errorClass":"panic","httpStatus":null,"severity":"error","filePath":"lib/wasix/src/syscalls/windows.rs","lineNumber":50,"sourceCode":"        wasi::Snapshot0Clockid::Monotonic => {\n            let tick_ms =\n                unsafe { windows_sys::Win32::System::SystemInformation::GetTickCount64() };\n            tick_ms * 1_000_000\n        }\n        wasi::Snapshot0Clockid::Realtime => {\n            let duration = std::time::SystemTime::now()\n                .duration_since(std::time::UNIX_EPOCH)\n                .map_err(|e| {\n                    debug!(\"Error in wasi::platform_clock_time_get: {:?}\", e);\n                    wasi::Errno::Io\n                })?;\n            duration.as_nanos() as u64\n        }\n        wasi::Snapshot0Clockid::ProcessCputimeId => {\n            unimplemented!(\"wasi::platform_clock_time_get(wasi::Clockid::ProcessCputimeId, ..)\")\n        }\n        wasi::Snapshot0Clockid::ThreadCputimeId => {\n            unimplemented!(\"wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)\")\n        }\n        _ => return Err(wasi::Errno::Inval),\n    };\n    Ok(nanos as i64)\n}\n","sourceCodeStart":32,"sourceCodeEnd":56,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/wasix/src/syscalls/windows.rs#L32-L56","documentation":"Same family as [211]: on Windows, wasix's platform_clock_time_get panics with unimplemented! when asked for ThreadCputimeId, because per-thread CPU time was never implemented in the Windows syscall shim. Only the panic message differs (thread vs process clock).","triggerScenarios":"A WASI guest calling clock_time_get with clock id ThreadCputimeId under Wasmer on Windows (windows.rs code path).","commonSituations":"Guest code measuring per-thread CPU usage (thread profilers, schedulers, instrumentation libraries) run on Windows via Wasmer.","solutions":["Avoid ThreadCputimeId on Windows; use monotonic/realtime clocks and measure wall time per thread.","Guard guest code by platform and degrade gracefully when the CPU-time clock is unavailable.","Implement the Windows variant using GetThreadTimes() for the guest thread handle, returning nanoseconds instead of panicking."],"exampleFix":"// before\nwasi::Snapshot0Clockid::ThreadCputimeId => {\n    unimplemented!(\"wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)\")\n}\n// after (Windows implementation idea)\nwasi::Snapshot0Clockid::ThreadCputimeId => {\n    let mut creation = 0; let mut exit = 0; let mut kernel = 0; let mut user = 0;\n    unsafe { GetThreadTimes(GetCurrentThread(), &mut creation, &mut exit, &mut kernel, &mut user) };\n    (user.saturating_add(kernel)) * 100\n}","handlingStrategy":"fallback","validationCode":"// avoid ThreadCputimeId on Windows\n#[cfg(windows)]\nlet clock = wasi::Snapshot0Clockid::Monotonic;\n#[cfg(not(windows))]\nlet clock = wasi::Snapshot0Clockid::ThreadCputime;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use wall-clock or monotonic measurements per thread on Windows","Guard thread-profiling code with platform checks","Add Windows CI coverage for any guest code using CPU-time clocks"],"tags":["wasix","wasi","windows","clock","unimplemented","panic"],"backgroundTag":"unimplemented-platform-clock","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}