privilege_level 0.1.0

Quick and simple access to the current privilege level of the CPU
Documentation

This library provides a simple, architecture independent way to detect the current privilege level (CPL).

Example

use privilege_level::{privilege_level, PrivilegeLevel};

# fn main() {
match privilege_level() {
PrivilegeLevel::Hypervisor => println!("Currently a hypervisor"),
PrivilegeLevel::Kernel => println!("Currently in kernel space"),
PrivilegeLevel::Driver => println!("Currently in a driver"),
PrivilegeLevel::User => println!("Currently in user space"),
}
# }

Details

The main entrypoint into this crate is through the [privilege_level] function. That will use the architecture dependent code necessary to determine the current privilege level then converts it into the common API.

The common API ([PrivilegeLevel]) is meant to be usable on any platform. It contains generic privilege levels that are common on most architectures. However, it's not always possible to include support for every architecture. As a compromise, depending on the target architecture, certain functions will be made available that return architecture-specific structures.

If you only want the raw privilege level number rather than a symbolic structure, you can also use the [raw_privilege_level] function. It uses architecture specific code to read the privilege level, converts it into a u16, then returns it. It's important to note that it doesn't do anything to make the output common in any way!