Skip to content

Commit f49761b

Browse files
authored
Merge pull request #426 from grant0417/master
Bump bitflags to 2.3.2
2 parents 486c2a4 + e2ab0c6 commit f49761b

File tree

10 files changed

+113
-2
lines changed

10 files changed

+113
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rust-version = "1.57" # Needed to support panic! in const fns
2121

2222
[dependencies]
2323
bit_field = "0.10.1"
24-
bitflags = "1.3.2"
24+
bitflags = "2.3.2"
2525
volatile = "0.4.4"
2626
rustversion = "1.0.5"
2727

src/registers/control.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Cr0;
1010
bitflags! {
1111
/// Configuration flags of the [`Cr0`] register.
1212
#[repr(transparent)]
13+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
1314
pub struct Cr0Flags: u64 {
1415
/// Enables protected mode.
1516
const PROTECTED_MODE_ENABLE = 1;
@@ -50,6 +51,14 @@ bitflags! {
5051
}
5152
}
5253

54+
impl Cr0Flags {
55+
#[deprecated = "use the safe `from_bits_retain` method instead"]
56+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
57+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
58+
Self::from_bits_retain(bits)
59+
}
60+
}
61+
5362
/// Contains the Page Fault Linear Address (PFLA).
5463
///
5564
/// When a page fault occurs, the CPU sets this register to the faulting virtual address.
@@ -64,6 +73,7 @@ bitflags! {
6473
/// Controls cache settings for the highest-level page table.
6574
///
6675
/// Unused if paging is disabled or if [`PCID`](Cr4Flags::PCID) is enabled.
76+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
6777
pub struct Cr3Flags: u64 {
6878
/// Use a writethrough cache policy for the table (otherwise a writeback policy is used).
6979
const PAGE_LEVEL_WRITETHROUGH = 1 << 3;
@@ -72,6 +82,14 @@ bitflags! {
7282
}
7383
}
7484

85+
impl Cr3Flags {
86+
#[deprecated = "use the safe `from_bits_retain` method instead"]
87+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
88+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
89+
Self::from_bits_retain(bits)
90+
}
91+
}
92+
7593
/// Contains various control flags that enable architectural extensions, and
7694
/// indicate support for specific processor capabilities.
7795
#[derive(Debug)]
@@ -80,6 +98,7 @@ pub struct Cr4;
8098
bitflags! {
8199
/// Configuration flags of the [`Cr4`] register.
82100
#[repr(transparent)]
101+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
83102
pub struct Cr4Flags: u64 {
84103
/// Enables hardware-supported performance enhancements for software running in
85104
/// virtual-8086 mode.
@@ -159,6 +178,14 @@ bitflags! {
159178
}
160179
}
161180

181+
impl Cr4Flags {
182+
#[deprecated = "use the safe `from_bits_retain` method instead"]
183+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
184+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
185+
Self::from_bits_retain(bits)
186+
}
187+
}
188+
162189
#[cfg(feature = "instructions")]
163190
mod x86_64 {
164191
use super::*;

src/registers/debug.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct Dr6;
110110
bitflags! {
111111
/// Debug condition flags of the [`Dr6`] register.
112112
#[repr(transparent)]
113+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
113114
pub struct Dr6Flags: u64 {
114115
/// Breakpoint condition 0 was detected.
115116
const TRAP0 = 1;
@@ -124,7 +125,7 @@ bitflags! {
124125
const TRAP3 = 1 << 3;
125126

126127
/// Breakpoint condition was detected.
127-
const TRAP = Self::TRAP0.bits | Self::TRAP1.bits | Self::TRAP2.bits | Self::TRAP3.bits;
128+
const TRAP = Self::TRAP0.bits() | Self::TRAP1.bits() | Self::TRAP2.bits() | Self::TRAP3.bits();
128129

129130
/// Next instruction accesses one of the debug registers.
130131
///
@@ -159,11 +160,18 @@ impl Dr6Flags {
159160
DebugAddressRegisterNumber::Dr3 => Self::TRAP3,
160161
}
161162
}
163+
164+
#[deprecated = "use the safe `from_bits_retain` method instead"]
165+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
166+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
167+
Self::from_bits_retain(bits)
168+
}
162169
}
163170

164171
bitflags! {
165172
/// Debug control flags of the [`Dr7`] register.
166173
#[repr(transparent)]
174+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
167175
pub struct Dr7Flags: u64 {
168176
/// Breakpoint 0 is enabled for the current task.
169177
const LOCAL_BREAKPOINT_0_ENABLE = 1;
@@ -231,6 +239,12 @@ impl Dr7Flags {
231239
DebugAddressRegisterNumber::Dr3 => Self::GLOBAL_BREAKPOINT_3_ENABLE,
232240
}
233241
}
242+
243+
#[deprecated = "use the safe `from_bits_retain` method instead"]
244+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
245+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
246+
Self::from_bits_retain(bits)
247+
}
234248
}
235249

236250
/// The condition for a hardware breakpoint.

src/registers/model_specific.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl SCet {
111111
bitflags! {
112112
/// Flags of the Extended Feature Enable Register.
113113
#[repr(transparent)]
114+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
114115
pub struct EferFlags: u64 {
115116
/// Enables the `syscall` and `sysret` instructions.
116117
const SYSTEM_CALL_EXTENSIONS = 1;
@@ -131,10 +132,19 @@ bitflags! {
131132
}
132133
}
133134

135+
impl EferFlags {
136+
#[deprecated = "use the safe `from_bits_retain` method instead"]
137+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
138+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
139+
Self::from_bits_retain(bits)
140+
}
141+
}
142+
134143
bitflags! {
135144
/// Flags stored in IA32_U_CET and IA32_S_CET (Table-2-2 in Intel SDM Volume
136145
/// 4). The Intel SDM-equivalent names are described in parentheses.
137146
#[repr(transparent)]
147+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
138148
pub struct CetFlags: u64 {
139149
/// Enable shadow stack (SH_STK_EN)
140150
const SS_ENABLE = 1 << 0;
@@ -155,6 +165,14 @@ bitflags! {
155165
}
156166
}
157167

168+
impl CetFlags {
169+
#[deprecated = "use the safe `from_bits_retain` method instead"]
170+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
171+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
172+
Self::from_bits_retain(bits)
173+
}
174+
}
175+
158176
#[cfg(feature = "instructions")]
159177
mod x86_64 {
160178
use super::*;

src/registers/mxcsr.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use bitflags::bitflags;
88
bitflags! {
99
/// MXCSR register.
1010
#[repr(transparent)]
11+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
1112
pub struct MxCsr: u32 {
1213
/// Invalid operation
1314
const INVALID_OPERATION = 1 << 0;
@@ -59,6 +60,14 @@ impl Default for MxCsr {
5960
}
6061
}
6162

63+
impl MxCsr {
64+
#[deprecated = "use the safe `from_bits_retain` method instead"]
65+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
66+
pub const unsafe fn from_bits_unchecked(bits: u32) -> Self {
67+
Self::from_bits_retain(bits)
68+
}
69+
}
70+
6271
#[cfg(feature = "instructions")]
6372
mod x86_64 {
6473
use super::*;

src/registers/rflags.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use bitflags::bitflags;
88
bitflags! {
99
/// The RFLAGS register.
1010
#[repr(transparent)]
11+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
1112
pub struct RFlags: u64 {
1213
/// Processor feature identification flag.
1314
///
@@ -63,6 +64,14 @@ bitflags! {
6364
}
6465
}
6566

67+
impl RFlags {
68+
#[deprecated = "use the safe `from_bits_retain` method instead"]
69+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
70+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
71+
Self::from_bits_retain(bits)
72+
}
73+
}
74+
6675
#[cfg(feature = "instructions")]
6776
mod x86_64 {
6877
use super::*;

src/registers/xcontrol.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bitflags! {
1111
/// For MPX, [`BNDREG`](XCr0Flags::BNDREG) and [`BNDCSR`](XCr0Flags::BNDCSR) must be set/unset simultaneously.
1212
/// For AVX-512, [`OPMASK`](XCr0Flags::OPMASK), [`ZMM_HI256`](XCr0Flags::ZMM_HI256), and [`HI16_ZMM`](XCr0Flags::HI16_ZMM) must be set/unset simultaneously.
1313
#[repr(transparent)]
14+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
1415
pub struct XCr0Flags: u64 {
1516
/// Enables using the x87 FPU state
1617
/// with `XSAVE`/`XRSTOR`.
@@ -52,6 +53,14 @@ bitflags! {
5253
}
5354
}
5455

56+
impl XCr0Flags {
57+
#[deprecated = "use the safe `from_bits_retain` method instead"]
58+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
59+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
60+
Self::from_bits_retain(bits)
61+
}
62+
}
63+
5564
#[cfg(feature = "instructions")]
5665
mod x86_64 {
5766
use super::*;

src/structures/gdt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub enum Descriptor {
187187

188188
bitflags! {
189189
/// Flags for a GDT descriptor. Not all flags are valid for all descriptor types.
190+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
190191
pub struct DescriptorFlags: u64 {
191192
/// Set by the processor if this segment has been accessed. Only cleared by software.
192193
/// _Setting_ this bit in software prevents GDT writes on first use.
@@ -268,6 +269,12 @@ impl DescriptorFlags {
268269
/// A 64-bit user code segment
269270
pub const USER_CODE64: Self =
270271
Self::from_bits_truncate(Self::KERNEL_CODE64.bits() | Self::DPL_RING_3.bits());
272+
273+
#[deprecated = "use the safe `from_bits_retain` method instead"]
274+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
275+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
276+
Self::from_bits_retain(bits)
277+
}
271278
}
272279

273280
impl Descriptor {

src/structures/idt.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ bitflags! {
968968
/// * AMD Volume 2: 8.4.2
969969
/// * Intel Volume 3A: 4.7
970970
#[repr(transparent)]
971+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
971972
pub struct PageFaultErrorCode: u64 {
972973
/// If this flag is set, the page fault was caused by a page-protection violation,
973974
/// else the page fault was caused by a not-present page.
@@ -1008,6 +1009,14 @@ bitflags! {
10081009
}
10091010
}
10101011

1012+
impl PageFaultErrorCode {
1013+
#[deprecated = "use the safe `from_bits_retain` method instead"]
1014+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
1015+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
1016+
Self::from_bits_retain(bits)
1017+
}
1018+
}
1019+
10111020
/// Describes an error code referencing a segment selector.
10121021
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
10131022
#[repr(transparent)]

src/structures/paging/page_table.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl fmt::Debug for PageTableEntry {
106106

107107
bitflags! {
108108
/// Possible flags for a page table entry.
109+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
109110
pub struct PageTableFlags: u64 {
110111
/// Specifies whether the mapped frame or page table is loaded in memory.
111112
const PRESENT = 1;
@@ -168,6 +169,14 @@ bitflags! {
168169
}
169170
}
170171

172+
impl PageTableFlags {
173+
#[deprecated = "use the safe `from_bits_retain` method instead"]
174+
/// Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
175+
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self {
176+
Self::from_bits_retain(bits)
177+
}
178+
}
179+
171180
/// The number of entries in a page table.
172181
const ENTRY_COUNT: usize = 512;
173182

0 commit comments

Comments
 (0)