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

Commit 9f41e6e

Browse files
Remove unsafe from barrier instructions (#48)
Usage of barriers does not compromise memory safety. They shouldn't have been unsafe to begin with.
1 parent 2a5ca5a commit 9f41e6e

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

src/asm/barrier.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
1010
mod sealed {
1111
pub trait Dmb {
12-
unsafe fn __dmb(&self);
12+
fn __dmb(&self);
1313
}
1414

1515
pub trait Dsb {
16-
unsafe fn __dsb(&self);
16+
fn __dsb(&self);
1717
}
1818

1919
pub trait Isb {
20-
unsafe fn __isb(&self);
20+
fn __isb(&self);
2121
}
2222
}
2323

2424
macro_rules! dmb_dsb {
2525
($A:ident) => {
2626
impl sealed::Dmb for $A {
2727
#[inline(always)]
28-
unsafe fn __dmb(&self) {
28+
fn __dmb(&self) {
2929
match () {
3030
#[cfg(target_arch = "aarch64")]
31-
() => {
31+
() => unsafe {
3232
core::arch::asm!(concat!("DMB ", stringify!($A)), options(nostack))
33-
}
33+
},
3434

3535
#[cfg(not(target_arch = "aarch64"))]
3636
() => unimplemented!(),
@@ -39,12 +39,12 @@ macro_rules! dmb_dsb {
3939
}
4040
impl sealed::Dsb for $A {
4141
#[inline(always)]
42-
unsafe fn __dsb(&self) {
42+
fn __dsb(&self) {
4343
match () {
4444
#[cfg(target_arch = "aarch64")]
45-
() => {
45+
() => unsafe {
4646
core::arch::asm!(concat!("DSB ", stringify!($A)), options(nostack))
47-
}
47+
},
4848

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

6565
impl sealed::Isb for SY {
6666
#[inline(always)]
67-
unsafe fn __isb(&self) {
67+
fn __isb(&self) {
6868
match () {
6969
#[cfg(target_arch = "aarch64")]
70-
() => {
71-
core::arch::asm!("ISB SY", options(nostack))
72-
}
70+
() => unsafe { core::arch::asm!("ISB SY", options(nostack)) },
7371

7472
#[cfg(not(target_arch = "aarch64"))]
7573
() => unimplemented!(),
7674
}
7775
}
7876
}
7977

80-
/// # Safety
81-
///
82-
/// In your own hands, this is hardware land!
78+
/// Data Memory Barrier.
8379
#[inline(always)]
84-
pub unsafe fn dmb<A>(arg: A)
80+
pub fn dmb<A>(arg: A)
8581
where
8682
A: sealed::Dmb,
8783
{
8884
arg.__dmb()
8985
}
9086

91-
/// # Safety
92-
///
93-
/// In your own hands, this is hardware land!
87+
/// Data Synchronization Barrier.
9488
#[inline(always)]
95-
pub unsafe fn dsb<A>(arg: A)
89+
pub fn dsb<A>(arg: A)
9690
where
9791
A: sealed::Dsb,
9892
{
9993
arg.__dsb()
10094
}
10195

102-
/// # Safety
103-
///
104-
/// In your own hands, this is hardware land!
96+
/// Instruction Synchronization Barrier.
10597
#[inline(always)]
106-
pub unsafe fn isb<A>(arg: A)
98+
pub fn isb<A>(arg: A)
10799
where
108100
A: sealed::Isb,
109101
{

0 commit comments

Comments
 (0)