Skip to content

Commit 204edcc

Browse files
committed
Make InterruptStackFrame::as_mut return a volatile reference
1 parent f5cd3d6 commit 204edcc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ edition = "2018"
2828
[dependencies]
2929
bit_field = "0.9.0"
3030
bitflags = "1.0.4"
31+
volatile = "0.4.4"
3132

3233
[build-dependencies]
3334
cc = { version = "1.0.37", optional = true }

src/structures/idt.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use core::fmt;
1616
use core::marker::PhantomData;
1717
use core::ops::Bound::{Excluded, Included, Unbounded};
1818
use core::ops::{Deref, Index, IndexMut, RangeBounds};
19+
use volatile::Volatile;
1920

2021
/// An Interrupt Descriptor Table with 256 entries.
2122
///
@@ -720,16 +721,22 @@ pub struct InterruptStackFrame {
720721
impl InterruptStackFrame {
721722
/// Gives mutable access to the contents of the interrupt stack frame.
722723
///
724+
/// The `Volatile` wrapper is used because LLVM optimizations remove non-volatile
725+
/// modifications of the interrupt stack frame.
726+
///
723727
/// ## Safety
724728
///
725729
/// This function is unsafe since modifying the content of the interrupt stack frame
726730
/// can easily lead to undefined behavior. For example, by writing an invalid value to
727731
/// the instruction pointer field, the CPU can jump to arbitrary code at the end of the
728732
/// interrupt.
733+
///
734+
/// Also, it is not fully clear yet whether modifications of the interrupt stack frame are
735+
/// officially supported by LLVM's x86 interrupt calling convention.
729736
#[allow(clippy::should_implement_trait)]
730737
#[inline]
731-
pub unsafe fn as_mut(&mut self) -> &mut InterruptStackFrameValue {
732-
&mut self.value
738+
pub unsafe fn as_mut(&mut self) -> Volatile<&mut InterruptStackFrameValue> {
739+
Volatile::new(&mut self.value)
733740
}
734741
}
735742

0 commit comments

Comments
 (0)