pipette/
crash.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Handler for kernel crash requests.
5
6#[cfg(target_os = "linux")]
7pub fn trigger_kernel_crash() -> anyhow::Result<()> {
8    use anyhow::Context;
9
10    std::fs::write("/proc/sysrq-trigger", "c").context("failed to write to /proc/sysrq-trigger")?;
11    Ok(())
12}
13
14#[cfg(windows)]
15pub fn trigger_kernel_crash() -> anyhow::Result<()> {
16    use anyhow::Context;
17
18    let output = std::process::Command::new("taskkill")
19        .args(["/IM", "wininit.exe", "/F", "/T"])
20        .output()
21        .context("failed to execute taskkill")?;
22
23    if !output.status.success() {
24        anyhow::bail!(
25            "taskkill exited with status {}:\n{}\n{}",
26            output.status,
27            String::from_utf8_lossy(&output.stdout),
28            String::from_utf8_lossy(&output.stderr)
29        );
30    }
31
32    Ok(())
33}