#![cfg_attr(not(windows), allow(dead_code, unused_imports))]
#[cfg(not(windows))]
compile_error!("msr-driver-rs supports Windows only");
#[cfg(all(feature = "scaphandre", feature = "winring0"))]
compile_error!("Cannot enable both 'scaphandre' and 'winring0' features at the same time");
#[cfg(not(any(feature = "scaphandre", feature = "winring0")))]
compile_error!("At least one of 'scaphandre' or 'winring0' features must be enabled");
mod device;
mod error;
mod service;
mod util;
pub use crate::error::{Error, Result};
pub struct MsrDriver {
device: device::DeviceHandle,
}
impl MsrDriver {
pub fn new() -> Result<Self> {
match device::DeviceHandle::open() {
Ok(device) => Ok(Self { device }),
Err(Error::NotInstalled) => {
if service::is_installed()? {
return Err(Error::NotRunning);
}
Err(Error::NotInstalled)
}
Err(err) => Err(err),
}
}
pub fn install() -> Result<()> {
service::install()
}
pub fn is_installed() -> Result<bool> {
service::is_installed()
}
pub fn needs_update() -> Result<bool> {
service::needs_update()
}
pub fn start() -> Result<()> {
service::start()
}
pub fn close(&mut self) -> Result<()> {
self.device.close()
}
pub fn uninstall_service() -> Result<()> {
service::uninstall()
}
pub fn uninstall(&mut self) -> Result<()> {
let _ = self.close();
service::uninstall()
}
pub fn read_msr(&self, msr_register: u32, cpu_index: u32) -> Result<u64> {
self.device.read_msr(msr_register, cpu_index)
}
}