From 5da57f65cd07f84f49c30d777d5bc12191b0f530 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 1 Oct 2019 14:45:17 +0200 Subject: [PATCH 1/2] Add an unsafe fn `SCB::steal` --- src/peripheral/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index 7019224f..9a30869c 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -429,6 +429,18 @@ pub struct SCB { unsafe impl Send for SCB {} impl SCB { + /// Unsafely obtains an `SCB` instance from nothing. + /// + /// # Safety + /// + /// This is only safe to use when the returned `SCB` instance is used + /// correctly without conflicting with any other existing `SCB` instances. + pub unsafe fn steal() -> Self { + Self { + _marker: PhantomData, + } + } + /// Returns a pointer to the register block pub fn ptr() -> *const scb::RegisterBlock { 0xE000_ED04 as *const _ From d2962c83809f2613a117e8d9a234dd1afd036761 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 4 Oct 2019 11:49:36 +0200 Subject: [PATCH 2/2] Clarify safety constraints --- src/peripheral/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index 9a30869c..c7fcd79b 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -433,8 +433,8 @@ impl SCB { /// /// # Safety /// - /// This is only safe to use when the returned `SCB` instance is used - /// correctly without conflicting with any other existing `SCB` instances. + /// The caller has to ensure that all SCB access is synchronized across all + /// `SCB` instances to avoid race conditions. pub unsafe fn steal() -> Self { Self { _marker: PhantomData,