Skip to content

Commit 659c871

Browse files
committed
fix(interrupts): add compiler fences to enable and disable
Without this, the compiler may reorder memory accesses over the sti and cli calls. Signed-off-by: Martin Kröning <[email protected]>
1 parent 950a941 commit 659c871

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/instructions/interrupts.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Enabling and disabling interrupts
22
33
use core::arch::asm;
4+
use core::sync::atomic::{compiler_fence, Ordering};
45

56
/// Returns whether interrupts are enabled.
67
#[inline]
@@ -15,6 +16,8 @@ pub fn are_enabled() -> bool {
1516
/// This is a wrapper around the `sti` instruction.
1617
#[inline]
1718
pub fn enable() {
19+
// Prevent earlier writes to be moved beyond this point
20+
compiler_fence(Ordering::Release);
1821
unsafe {
1922
asm!("sti", options(nomem, nostack));
2023
}
@@ -25,6 +28,8 @@ pub fn enable() {
2528
/// This is a wrapper around the `cli` instruction.
2629
#[inline]
2730
pub fn disable() {
31+
// Prevent future writes to be moved before this point.
32+
compiler_fence(Ordering::Acquire);
2833
unsafe {
2934
asm!("cli", options(nomem, nostack));
3035
}

0 commit comments

Comments
 (0)