From 759ac160db3a02d23b1126c6875143b67f5c2e20 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 7 Apr 2017 16:38:39 -0500 Subject: [PATCH] remove the borrow_mut method from resources it can be used to break references rules within nested locks ``` rust static R1: Resource = unsafe { Resource::new(false) }; static R2: Resource = unsafe { Resource::new(false) }; static R3: Resource = unsafe { Resource::new(false) }; // Priority = 1 extern "C" fn j1(task: interrupt::Exti0Irq) { R1.lock(&task, |r1, c1| { R2.lock(&task, |r2, c2| { R3.lock(&task, |r3, mut c3| { // BAD &- and &mut - that point to the same data let r1_ref: &bool = R1.borrow(&c2); let r1_ref_mut: &mut bool = R1.borrow_mut(&mut c3); }); }); }); } ``` --- src/lib.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a1976db419..bf0b7bd542 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -180,19 +180,6 @@ where unsafe { &*self.peripheral.get() } } - /// Mutably borrows the resource without locking - /// - /// NOTE The system ceiling must be higher than this resource ceiling - pub fn borrow_mut<'l, SC>( - &'static self, - _system_ceiling: &'l mut SC, - ) -> &'l mut P - where - SC: HigherThan, - { - unsafe { &mut *self.peripheral.get() } - } - /// Returns an immutable reference to the inner data without locking /// /// # Safety @@ -327,16 +314,6 @@ where unsafe { &*self.data.get() } } - /// Mutably borrows the resource without locking - /// - /// NOTE The system ceiling must be higher than this resource ceiling - pub fn borrow_mut<'l, SC>(&'static self, _ctxt: &'l mut SC) -> &'l mut T - where - SC: HigherThan, - { - unsafe { &mut *self.data.get() } - } - /// Returns an immutable reference to the inner data without locking /// /// # Safety