~ruther/avr-device

c0edb56c6f841fad307e66926b93c213623f8348 — Rahix 4 years ago 0e43361
interrupt: Make interrupt::enable() unsafe

To bring this crate more in line with cortex-m, mark interrupt::enable()
as unsafe.  This also fixes a soundness issue: When the function is
safe, one could call it inside a critical section in entirely safe rust.
This is problematic because lot's of code in critical sections relies on
the fact that interrupts are disabled and it thus can safely perform
non-atomic operations without anything interrupting it.

Signed-off-by: Rahix <rahix@rahix.de>
1 files changed, 5 insertions(+), 7 deletions(-)

M src/interrupt.rs
M src/interrupt.rs => src/interrupt.rs +5 -7
@@ 26,12 26,10 @@ pub fn disable() {
/// # Safety
///
/// - Do not call this function inside an [crate::interrupt::free] critical section
pub fn enable() {
    unsafe {
        llvm_asm!(
            "sei" :::: "volatile"
        );
    }
pub unsafe fn enable() {
    llvm_asm!(
        "sei" :::: "volatile"
    );
}

/// Execute closure `f` in an interrupt-free context.


@@ 61,7 59,7 @@ where

    // Restore interrupt state
    if sreg & 0x80 != 0x00 {
        enable();
        unsafe { enable(); }
    }

    r

Do not follow this link