wasmerio/wasmer · error · panic

wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId

Error message

wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)

What it means

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).

Source

Thrown at lib/wasix/src/syscalls/windows.rs:50

        wasi::Snapshot0Clockid::Monotonic => {
            let tick_ms =
                unsafe { windows_sys::Win32::System::SystemInformation::GetTickCount64() };
            tick_ms * 1_000_000
        }
        wasi::Snapshot0Clockid::Realtime => {
            let duration = std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .map_err(|e| {
                    debug!("Error in wasi::platform_clock_time_get: {:?}", e);
                    wasi::Errno::Io
                })?;
            duration.as_nanos() as u64
        }
        wasi::Snapshot0Clockid::ProcessCputimeId => {
            unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ProcessCputimeId, ..)")
        }
        wasi::Snapshot0Clockid::ThreadCputimeId => {
            unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)")
        }
        _ => return Err(wasi::Errno::Inval),
    };
    Ok(nanos as i64)
}

View on GitHub (pinned to 8c4b9ee9d3)

Solutions

  1. Avoid ThreadCputimeId on Windows; use monotonic/realtime clocks and measure wall time per thread.
  2. Guard guest code by platform and degrade gracefully when the CPU-time clock is unavailable.
  3. Implement the Windows variant using GetThreadTimes() for the guest thread handle, returning nanoseconds instead of panicking.

Example fix

// before
wasi::Snapshot0Clockid::ThreadCputimeId => {
    unimplemented!("wasi::platform_clock_time_get(wasi::Clockid::ThreadCputimeId, ..)")
}
// after (Windows implementation idea)
wasi::Snapshot0Clockid::ThreadCputimeId => {
    let mut creation = 0; let mut exit = 0; let mut kernel = 0; let mut user = 0;
    unsafe { GetThreadTimes(GetCurrentThread(), &mut creation, &mut exit, &mut kernel, &mut user) };
    (user.saturating_add(kernel)) * 100
}
Defensive patterns

Strategy: fallback

Validate before calling

// avoid ThreadCputimeId on Windows
#[cfg(windows)]
let clock = wasi::Snapshot0Clockid::Monotonic;
#[cfg(not(windows))]
let clock = wasi::Snapshot0Clockid::ThreadCputime;

Prevention

When it happens

Trigger: A WASI guest calling clock_time_get with clock id ThreadCputimeId under Wasmer on Windows (windows.rs code path).

Common situations: Guest code measuring per-thread CPU usage (thread profilers, schedulers, instrumentation libraries) run on Windows via Wasmer.

Related errors


AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01). Data as JSON: /api/errors/7922027d9ee0cc0b. Report an issue: GitHub.