Skip to content

Commit

Permalink
Merge pull request #436 from mkroening/interrupt-fence
Browse files Browse the repository at this point in the history
fix(interrupts): add compiler fences to enable and disable
  • Loading branch information
Freax13 authored Sep 15, 2023
2 parents 950a941 + 659c871 commit a8165d4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/instructions/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Enabling and disabling interrupts
use core::arch::asm;
use core::sync::atomic::{compiler_fence, Ordering};

/// Returns whether interrupts are enabled.
#[inline]
Expand All @@ -15,6 +16,8 @@ pub fn are_enabled() -> bool {
/// This is a wrapper around the `sti` instruction.
#[inline]
pub fn enable() {
// Prevent earlier writes to be moved beyond this point
compiler_fence(Ordering::Release);
unsafe {
asm!("sti", options(nomem, nostack));
}
Expand All @@ -25,6 +28,8 @@ pub fn enable() {
/// This is a wrapper around the `cli` instruction.
#[inline]
pub fn disable() {
// Prevent future writes to be moved before this point.
compiler_fence(Ordering::Acquire);
unsafe {
asm!("cli", options(nomem, nostack));
}
Expand Down

0 comments on commit a8165d4

Please sign in to comment.