/rust/registry/src/index.crates.io-6f17d22bba15001f/x86_64-0.14.13/src/lib.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! This crate provides x86_64 specific functions and data structures, |
2 | | //! and access to various system registers. |
3 | | |
4 | | #![cfg_attr(not(test), no_std)] |
5 | | #![cfg_attr(feature = "const_fn", feature(const_mut_refs))] // GDT add_entry() |
6 | | #![cfg_attr(feature = "abi_x86_interrupt", feature(abi_x86_interrupt))] |
7 | | #![cfg_attr(feature = "step_trait", feature(step_trait))] |
8 | | #![cfg_attr(feature = "doc_auto_cfg", feature(doc_auto_cfg))] |
9 | | #![warn(missing_docs)] |
10 | | #![deny(missing_debug_implementations)] |
11 | | #![deny(unsafe_op_in_unsafe_fn)] |
12 | | |
13 | | pub use crate::addr::{align_down, align_up, PhysAddr, VirtAddr}; |
14 | | |
15 | | pub mod addr; |
16 | | pub mod instructions; |
17 | | pub mod registers; |
18 | | pub mod structures; |
19 | | |
20 | | /// Represents a protection ring level. |
21 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
22 | | #[repr(u8)] |
23 | | pub enum PrivilegeLevel { |
24 | | /// Privilege-level 0 (most privilege): This level is used by critical system-software |
25 | | /// components that require direct access to, and control over, all processor and system |
26 | | /// resources. This can include BIOS, memory-management functions, and interrupt handlers. |
27 | | Ring0 = 0, |
28 | | |
29 | | /// Privilege-level 1 (moderate privilege): This level is used by less-critical system- |
30 | | /// software services that can access and control a limited scope of processor and system |
31 | | /// resources. Software running at these privilege levels might include some device drivers |
32 | | /// and library routines. The actual privileges of this level are defined by the |
33 | | /// operating system. |
34 | | Ring1 = 1, |
35 | | |
36 | | /// Privilege-level 2 (moderate privilege): Like level 1, this level is used by |
37 | | /// less-critical system-software services that can access and control a limited scope of |
38 | | /// processor and system resources. The actual privileges of this level are defined by the |
39 | | /// operating system. |
40 | | Ring2 = 2, |
41 | | |
42 | | /// Privilege-level 3 (least privilege): This level is used by application software. |
43 | | /// Software running at privilege-level 3 is normally prevented from directly accessing |
44 | | /// most processor and system resources. Instead, applications request access to the |
45 | | /// protected processor and system resources by calling more-privileged service routines |
46 | | /// to perform the accesses. |
47 | | Ring3 = 3, |
48 | | } |
49 | | |
50 | | impl PrivilegeLevel { |
51 | | /// Creates a `PrivilegeLevel` from a numeric value. The value must be in the range 0..4. |
52 | | /// |
53 | | /// This function panics if the passed value is >3. |
54 | | #[inline] |
55 | 0 | pub const fn from_u16(value: u16) -> PrivilegeLevel { |
56 | 0 | match value { |
57 | 0 | 0 => PrivilegeLevel::Ring0, |
58 | 0 | 1 => PrivilegeLevel::Ring1, |
59 | 0 | 2 => PrivilegeLevel::Ring2, |
60 | 0 | 3 => PrivilegeLevel::Ring3, |
61 | 0 | _ => panic!("invalid privilege level"), |
62 | | } |
63 | 0 | } Unexecuted instantiation: <x86_64::PrivilegeLevel>::from_u16 Unexecuted instantiation: <x86_64::PrivilegeLevel>::from_u16 |
64 | | } |