From 8065d741aceb96ea06e70afce05408e334a977b5 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 2 Nov 2021 13:41:12 +0100 Subject: Fixed aliasing issue due to RacyCell implementation --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index ca52ec1..d5505b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,16 +69,16 @@ impl RacyCell { RacyCell(UnsafeCell::new(value)) } - /// Get `&mut T` + /// Get `*mut T` #[inline(always)] - pub unsafe fn get_mut_unchecked(&self) -> &mut T { - &mut *self.0.get() + pub unsafe fn get_mut(&self) -> *mut T { + self.0.get() } - /// Get `&T` + /// Get `*const T` #[inline(always)] - pub unsafe fn get_unchecked(&self) -> &T { - &*self.0.get() + pub unsafe fn get(&self) -> *const T { + self.0.get() } } -- cgit v1.2.3 From 1e2ab78a3fad8f383e5949dd0a11aaaaf03467f1 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Tue, 2 Nov 2021 19:47:14 +0100 Subject: added doc for RacyCell --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index d5505b0..8463442 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,6 +59,27 @@ where use core::cell::UnsafeCell; /// Internal replacement for `static mut T` +/// +/// Used to represent RTIC Resources +/// +/// Soundness: +/// 1) Unsafe API for internal use only +/// 2) get_mut(&self) -> *mut T +/// returns a raw mutable pointer to the inner T +/// casting to &mut T is under control of RTIC +/// RTIC ensures &mut T to be unique under Rust aliasing rules. +/// +/// Implementation uses the underlying UnsafeCell +/// self.0.get() -> *mut T +/// +/// 3) get(&self) -> *const T +/// returns a raw immutable (const) pointer to the inner T +/// casting to &T is under control of RTIC +/// RTIC ensures &T to be shared under Rust aliasing rules. +/// +/// Implementation uses the underlying UnsafeCell +/// self.0.get() -> *mut T, demoted to *const T +/// #[repr(transparent)] pub struct RacyCell(UnsafeCell); -- cgit v1.2.3