From 741095dff0ce66981e1a4dfa64426fb507869ece Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Wed, 5 Nov 2025 21:59:10 +0300 Subject: **RAW**: Added two more functions in `non_critical`: Kernel Panic: Sys-RQ kern panic & Broken kmod panic. Updated `build.rs`, and more files --- src/non_critical/kern_panic/mod.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/non_critical/kern_panic/mod.rs (limited to 'src/non_critical/kern_panic') diff --git a/src/non_critical/kern_panic/mod.rs b/src/non_critical/kern_panic/mod.rs new file mode 100644 index 0000000..4dccc34 --- /dev/null +++ b/src/non_critical/kern_panic/mod.rs @@ -0,0 +1,34 @@ +use std::process::Command; +use std::path::PathBuf; +use std::env; + +extern "C" { + pub fn linux_sysrq_start(); + pub fn linux_sysrq_panic(); +} + +pub unsafe fn sysrq_panic() { + linux_sysrq_start(); + linux_sysrq_panic(); +} + +pub fn kmod_panic() -> Result<(), String> { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap_or_else(|_| "target/debug".into())); + let ko_file = out_dir.join("linux_kmod.ko"); + + if !ko_file.exists() { + return Err(format!("Kernel module not found at: {}", ko_file.display())); + } + + let status = Command::new("insmod") + .arg(&ko_file) + .status() + .map_err(|e| format!("Failed to execute insmod: {}", e))?; + + if !status.success() { + return Err(format!("Failed to load kernel module: exit code {:?}", status.code())); + } + + Ok(()) +} + -- cgit v1.2.3