Skip to content

Commit

Permalink
Review: write_raw() must be unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
sw committed Jan 23, 2025
1 parent 78f7968 commit 8279b63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cortex-m/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ where

let r = f();

crate::register::primask::write_raw(primask);
unsafe {
crate::register::primask::write_raw(primask);
}

r
}
Expand Down
2 changes: 1 addition & 1 deletion cortex-m/src/register/primask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn read_raw() -> u32 {
/// Note that bits [31:1] are reserved and SBZP (Should-Be-Zero-or-Preserved)
#[cfg(cortex_m)]
#[inline]
pub fn write_raw(r: u32) {
pub unsafe fn write_raw(r: u32) {
// Ensure no preceeding memory accesses are reordered to after interrupts are possibly enabled.
compiler_fence(Ordering::SeqCst);
unsafe { asm!("msr PRIMASK, {}", in(reg) r, options(nomem, nostack, preserves_flags)) };
Expand Down

0 comments on commit 8279b63

Please sign in to comment.