Expand description
This library provides a simple, architecture independent way to detect the current privilege level (CPL).
§Example
use privilege_level::{privilege_level, PrivilegeLevel};
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!
Enums§
- Privilege
Level - Represents a generic CPU privilege level.
- x86_
64Privilege Level x86-64 - Represents a protection ring level.
Functions§
- privilege_
level - Gets the current privilege level.
- raw_
privilege_ level - Gets the current privilege level as a raw number.
- x86_
64_ privilege_ level x86-64 - Gets the current privilege level for
x86_64systems.