|
4 | 4 |
|
5 | 5 | use core::arch::asm;
|
6 | 6 | use core::convert::TryFrom;
|
7 |
| -use core::mem; |
8 | 7 | use core::ops::Range;
|
9 | 8 |
|
10 | 9 | use crate::VirtAddr;
|
@@ -149,7 +148,6 @@ impl Dr6Flags {
|
149 | 148 |
|
150 | 149 | bitflags! {
|
151 | 150 | /// Debug control flags of the [`Dr7`] register.
|
152 |
| - // SAFETY: We choose to allow extra bits in `Dr7Flags` to be used for fields in `Dr7Value`. |
153 | 151 | #[repr(transparent)]
|
154 | 152 | pub struct Dr7Flags: u64 {
|
155 | 153 | /// Breakpoint 0 is enabled for the current task.
|
@@ -370,18 +368,35 @@ impl Dr7Value {
|
370 | 368 | /// Returns the [`Dr7Flags`] in this value.
|
371 | 369 | #[inline]
|
372 | 370 | pub const fn flags(self) -> Dr7Flags {
|
373 |
| - // SAFETY: The extra bits used in fields are valid in our representation of `Dr7Flags`. |
374 |
| - unsafe { Dr7Flags::from_bits_unchecked(self.bits) } |
| 371 | + Dr7Flags::from_bits_truncate(self.bits) |
375 | 372 | }
|
376 | 373 |
|
377 |
| - /// Returns a mutable reference to the [`Dr7Flags`] in this value. |
378 |
| - /// |
379 |
| - /// This can be used to modify the flags of this value in-place. |
| 374 | + /// Inserts the specified [`Dr7Flags`] in-place. |
| 375 | + #[inline] |
| 376 | + pub fn insert_flags(&mut self, flags: Dr7Flags) { |
| 377 | + self.bits |= flags.bits(); |
| 378 | + } |
| 379 | + |
| 380 | + /// Removes the specified [`Dr7Flags`] in-place. |
| 381 | + #[inline] |
| 382 | + pub fn remove_flags(&mut self, flags: Dr7Flags) { |
| 383 | + self.bits &= !flags.bits(); |
| 384 | + } |
| 385 | + |
| 386 | + /// Toggles the specified [`Dr7Flags`] in-place. |
| 387 | + #[inline] |
| 388 | + pub fn toggle_flags(&mut self, flags: Dr7Flags) { |
| 389 | + self.bits ^= flags.bits(); |
| 390 | + } |
| 391 | + |
| 392 | + /// Inserts or removes the specified [`Dr7Flags`] depending on the passed value. |
380 | 393 | #[inline]
|
381 |
| - pub fn flags_mut(&mut self) -> &mut Dr7Flags { |
382 |
| - // SAFETY: The extra bits used in fields are valid in our representation of `Dr7Flags`. |
383 |
| - // SAFETY: `Dr7Flags` has the same representation as `Dr7Value`. |
384 |
| - unsafe { mem::transmute(self) } |
| 394 | + pub fn set_flags(&mut self, flags: Dr7Flags, value: bool) { |
| 395 | + if value { |
| 396 | + self.insert_flags(flags); |
| 397 | + } else { |
| 398 | + self.remove_flags(flags); |
| 399 | + } |
385 | 400 | }
|
386 | 401 |
|
387 | 402 | /// Returns the condition field of a debug address register.
|
|
0 commit comments