@@ -99,18 +99,11 @@ pub struct Item {
99
99
perm : Permission ,
100
100
/// The pointers the permission is granted to.
101
101
tag : SbTag ,
102
- /// An optional protector, ensuring the item cannot get popped until `CallId` is over.
103
- protector : Option < CallId > ,
104
102
}
105
103
106
104
impl fmt:: Debug for Item {
107
105
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
108
- write ! ( f, "[{:?} for {:?}" , self . perm, self . tag) ?;
109
- if let Some ( call) = self . protector {
110
- write ! ( f, " (call {})" , call) ?;
111
- }
112
- write ! ( f, "]" ) ?;
113
- Ok ( ( ) )
106
+ write ! ( f, "[{:?} for {:?}]" , self . perm, self . tag)
114
107
}
115
108
}
116
109
@@ -138,6 +131,8 @@ pub struct GlobalStateInner {
138
131
next_call_id : CallId ,
139
132
/// Those call IDs corresponding to functions that are still running.
140
133
active_calls : FxHashSet < CallId > ,
134
+ /// All tags currently protected
135
+ pub ( crate ) protected_tags : FxHashSet < SbTag > ,
141
136
/// The pointer ids to trace
142
137
tracked_pointer_tags : HashSet < SbTag > ,
143
138
/// The call ids to trace
@@ -202,6 +197,7 @@ impl GlobalStateInner {
202
197
base_ptr_tags : FxHashMap :: default ( ) ,
203
198
next_call_id : NonZeroU64 :: new ( 1 ) . unwrap ( ) ,
204
199
active_calls : FxHashSet :: default ( ) ,
200
+ protected_tags : FxHashSet :: default ( ) ,
205
201
tracked_pointer_tags,
206
202
tracked_call_ids,
207
203
retag_fields,
@@ -230,10 +226,6 @@ impl GlobalStateInner {
230
226
assert ! ( self . active_calls. remove( & id) ) ;
231
227
}
232
228
233
- fn is_active ( & self , id : CallId ) -> bool {
234
- self . active_calls . contains ( & id)
235
- }
236
-
237
229
pub fn base_ptr_tag ( & mut self , id : AllocId ) -> SbTag {
238
230
self . base_ptr_tags . get ( & id) . copied ( ) . unwrap_or_else ( || {
239
231
let tag = self . new_ptr ( ) ;
@@ -333,24 +325,22 @@ impl<'tcx> Stack {
333
325
) ) ;
334
326
}
335
327
336
- if let Some ( call) = item. protector {
337
- if global. is_active ( call) {
338
- if let Some ( ( tag, _alloc_range, _offset, _access) ) = provoking_access {
339
- Err ( err_sb_ub (
340
- format ! (
341
- "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
342
- tag, item
343
- ) ,
344
- None ,
345
- tag. and_then ( |tag| alloc_history. get_logs_relevant_to ( tag, Some ( item. tag ) ) ) ,
346
- ) ) ?
347
- } else {
348
- Err ( err_sb_ub (
349
- format ! ( "deallocating while item is protected: {:?}" , item) ,
350
- None ,
351
- None ,
352
- ) ) ?
353
- }
328
+ if global. protected_tags . contains ( & item. tag ) {
329
+ if let Some ( ( tag, _alloc_range, _offset, _access) ) = provoking_access {
330
+ Err ( err_sb_ub (
331
+ format ! (
332
+ "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
333
+ tag, item
334
+ ) ,
335
+ None ,
336
+ tag. and_then ( |tag| alloc_history. get_logs_relevant_to ( tag, Some ( item. tag ) ) ) ,
337
+ ) ) ?
338
+ } else {
339
+ Err ( err_sb_ub (
340
+ format ! ( "deallocating while item is protected: {:?}" , item) ,
341
+ None ,
342
+ None ,
343
+ ) ) ?
354
344
}
355
345
}
356
346
Ok ( ( ) )
@@ -578,7 +568,7 @@ impl<'tcx> Stack {
578
568
impl < ' tcx > Stacks {
579
569
/// Creates new stack with initial tag.
580
570
fn new ( size : Size , perm : Permission , tag : SbTag ) -> Self {
581
- let item = Item { perm, tag, protector : None } ;
571
+ let item = Item { perm, tag } ;
582
572
let stack = Stack :: new ( item) ;
583
573
584
574
Stacks {
@@ -808,7 +798,6 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
808
798
} ) ;
809
799
}
810
800
811
- let protector = if protect { Some ( this. frame ( ) . extra . call_id ) } else { None } ;
812
801
trace ! (
813
802
"reborrow: {} reference {:?} derived from {:?} (pointee {}): {:?}, size {}" ,
814
803
kind,
@@ -819,6 +808,15 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
819
808
size. bytes( )
820
809
) ;
821
810
811
+ // FIXME: This just protects everything, which is wrong. At the very least, we should not
812
+ // protect anything that contains an UnsafeCell.
813
+ if protect {
814
+ this. frame_mut ( ) . extra . protected_tags . push ( new_tag) ;
815
+ this. machine . stacked_borrows . as_mut ( ) . unwrap ( ) . get_mut ( ) . protected_tags . insert ( new_tag) ;
816
+ }
817
+ // FIXME: can't hold the current span handle across the borrows of self above
818
+ let current_span = & mut this. machine . current_span ( ) ;
819
+
822
820
// Update the stacks.
823
821
// Make sure that raw pointers and mutable shared references are reborrowed "weak":
824
822
// There could be existing unique pointers reborrowed from them that should remain valid!
@@ -855,14 +853,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
855
853
} else {
856
854
Permission :: SharedReadWrite
857
855
} ;
858
- let protector = if frozen {
859
- protector
860
- } else {
861
- // We do not protect inside UnsafeCell.
862
- // This fixes https://github.com/rust-lang/rust/issues/55005.
863
- None
864
- } ;
865
- let item = Item { perm, tag : new_tag, protector } ;
856
+ let item = Item { perm, tag : new_tag } ;
866
857
let mut global = this. machine . stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
867
858
stacked_borrows. for_each ( range, |offset, stack, history, exposed_tags| {
868
859
stack. grant (
@@ -888,7 +879,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
888
879
. as_mut ( )
889
880
. expect ( "we should have Stacked Borrows data" )
890
881
. borrow_mut ( ) ;
891
- let item = Item { perm, tag : new_tag, protector } ;
882
+ let item = Item { perm, tag : new_tag } ;
892
883
let range = alloc_range ( base_offset, size) ;
893
884
let mut global = machine. stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
894
885
let current_span = & mut machine. current_span ( ) ; // `get_alloc_extra_mut` invalidated our old `current_span`
0 commit comments