Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Remove unsafe from barrier instructions
Browse files Browse the repository at this point in the history
Usage of barriers does not compromise memory safety. They shouldn't have been
unsafe to begin with.
  • Loading branch information
andre-richter committed Sep 19, 2022
1 parent 2a5ca5a commit 9421f40
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions src/asm/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
mod sealed {
pub trait Dmb {
unsafe fn __dmb(&self);
fn __dmb(&self);
}

pub trait Dsb {
unsafe fn __dsb(&self);
fn __dsb(&self);
}

pub trait Isb {
unsafe fn __isb(&self);
fn __isb(&self);
}
}

macro_rules! dmb_dsb {
($A:ident) => {
impl sealed::Dmb for $A {
#[inline(always)]
unsafe fn __dmb(&self) {
fn __dmb(&self) {
match () {
#[cfg(target_arch = "aarch64")]
() => {
() => unsafe {
core::arch::asm!(concat!("DMB ", stringify!($A)), options(nostack))
}
},

#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
Expand All @@ -39,12 +39,12 @@ macro_rules! dmb_dsb {
}
impl sealed::Dsb for $A {
#[inline(always)]
unsafe fn __dsb(&self) {
fn __dsb(&self) {
match () {
#[cfg(target_arch = "aarch64")]
() => {
() => unsafe {
core::arch::asm!(concat!("DSB ", stringify!($A)), options(nostack))
}
},

#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
Expand All @@ -64,46 +64,38 @@ dmb_dsb!(SY);

impl sealed::Isb for SY {
#[inline(always)]
unsafe fn __isb(&self) {
fn __isb(&self) {
match () {
#[cfg(target_arch = "aarch64")]
() => {
core::arch::asm!("ISB SY", options(nostack))
}
() => unsafe { core::arch::asm!("ISB SY", options(nostack)) },

#[cfg(not(target_arch = "aarch64"))]
() => unimplemented!(),
}
}
}

/// # Safety
///
/// In your own hands, this is hardware land!
/// Data Memory Barrier.
#[inline(always)]
pub unsafe fn dmb<A>(arg: A)
pub fn dmb<A>(arg: A)
where
A: sealed::Dmb,
{
arg.__dmb()
}

/// # Safety
///
/// In your own hands, this is hardware land!
/// Data Synchronization Barrier.
#[inline(always)]
pub unsafe fn dsb<A>(arg: A)
pub fn dsb<A>(arg: A)
where
A: sealed::Dsb,
{
arg.__dsb()
}

/// # Safety
///
/// In your own hands, this is hardware land!
/// Instruction Synchronization Barrier.
#[inline(always)]
pub unsafe fn isb<A>(arg: A)
pub fn isb<A>(arg: A)
where
A: sealed::Isb,
{
Expand Down

0 comments on commit 9421f40

Please sign in to comment.