Skip to content

Commit f00dc02

Browse files
committed
Add deprecated from_bits_unchecked
1 parent add9e20 commit f00dc02

File tree

9 files changed

+98
-0
lines changed

9 files changed

+98
-0
lines changed

src/registers/control.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ bitflags! {
5151
}
5252
}
5353

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
58+
Self::from_bits_retain(bits)
59+
}
60+
}
61+
5462
/// Contains the Page Fault Linear Address (PFLA).
5563
///
5664
/// When a page fault occurs, the CPU sets this register to the faulting virtual address.
@@ -74,6 +82,14 @@ bitflags! {
7482
}
7583
}
7684

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
89+
Self::from_bits_retain(bits)
90+
}
91+
}
92+
7793
/// Contains various control flags that enable architectural extensions, and
7894
/// indicate support for specific processor capabilities.
7995
#[derive(Debug)]
@@ -162,6 +178,14 @@ bitflags! {
162178
}
163179
}
164180

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
185+
Self::from_bits_retain(bits)
186+
}
187+
}
188+
165189
#[cfg(feature = "instructions")]
166190
mod x86_64 {
167191
use super::*;

src/registers/debug.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ impl Dr6Flags {
160160
DebugAddressRegisterNumber::Dr3 => Self::TRAP3,
161161
}
162162
}
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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
167+
Self::from_bits_retain(bits)
168+
}
163169
}
164170

165171
bitflags! {
@@ -233,6 +239,12 @@ impl Dr7Flags {
233239
DebugAddressRegisterNumber::Dr3 => Self::GLOBAL_BREAKPOINT_3_ENABLE,
234240
}
235241
}
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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
246+
Self::from_bits_retain(bits)
247+
}
236248
}
237249

238250
/// The condition for a hardware breakpoint.

src/registers/model_specific.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ bitflags! {
132132
}
133133
}
134134

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
139+
Self::from_bits_retain(bits)
140+
}
141+
}
142+
135143
bitflags! {
136144
/// Flags stored in IA32_U_CET and IA32_S_CET (Table-2-2 in Intel SDM Volume
137145
/// 4). The Intel SDM-equivalent names are described in parentheses.
@@ -157,6 +165,14 @@ bitflags! {
157165
}
158166
}
159167

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
172+
Self::from_bits_retain(bits)
173+
}
174+
}
175+
160176
#[cfg(feature = "instructions")]
161177
mod x86_64 {
162178
use super::*;

src/registers/mxcsr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ impl Default for MxCsr {
6060
}
6161
}
6262

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 unsafe fn from_bits_unchecked(bits: u32) -> Self {
67+
Self::from_bits_retain(bits)
68+
}
69+
}
70+
6371
#[cfg(feature = "instructions")]
6472
mod x86_64 {
6573
use super::*;

src/registers/rflags.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ bitflags! {
6464
}
6565
}
6666

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
71+
Self::from_bits_retain(bits)
72+
}
73+
}
74+
6775
#[cfg(feature = "instructions")]
6876
mod x86_64 {
6977
use super::*;

src/registers/xcontrol.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ bitflags! {
5353
}
5454
}
5555

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
60+
Self::from_bits_retain(bits)
61+
}
62+
}
63+
5664
#[cfg(feature = "instructions")]
5765
mod x86_64 {
5866
use super::*;

src/structures/gdt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ impl DescriptorFlags {
269269
/// A 64-bit user code segment
270270
pub const USER_CODE64: Self =
271271
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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
276+
Self::from_bits_retain(bits)
277+
}
272278
}
273279

274280
impl Descriptor {

src/structures/idt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,14 @@ bitflags! {
10091009
}
10101010
}
10111011

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
1016+
Self::from_bits_retain(bits)
1017+
}
1018+
}
1019+
10121020
/// Describes an error code referencing a segment selector.
10131021
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
10141022
#[repr(transparent)]

src/structures/paging/page_table.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ bitflags! {
169169
}
170170
}
171171

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 unsafe fn from_bits_unchecked(bits: u64) -> Self {
176+
Self::from_bits_retain(bits)
177+
}
178+
}
179+
172180
/// The number of entries in a page table.
173181
const ENTRY_COUNT: usize = 512;
174182

0 commit comments

Comments
 (0)