@@ -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,
@@ -232,10 +228,6 @@ impl GlobalStateInner {
232
228
assert ! ( self . active_calls. remove( & id) ) ;
233
229
}
234
230
235
- fn is_active ( & self , id : CallId ) -> bool {
236
- self . active_calls . contains ( & id)
237
- }
238
-
239
231
pub fn base_ptr_tag ( & mut self , id : AllocId ) -> SbTag {
240
232
self . base_ptr_tags . get ( & id) . copied ( ) . unwrap_or_else ( || {
241
233
let tag = self . new_ptr ( ) ;
@@ -332,24 +324,22 @@ impl<'tcx> Stack {
332
324
) ) ;
333
325
}
334
326
335
- if let Some ( call) = item. protector {
336
- if global. is_active ( call) {
337
- if let Some ( ( tag, _alloc_range, _offset, _access) ) = provoking_access {
338
- Err ( err_sb_ub (
339
- format ! (
340
- "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
341
- tag, item
342
- ) ,
343
- None ,
344
- tag. and_then ( |tag| alloc_history. get_logs_relevant_to ( tag, Some ( item. tag ) ) ) ,
345
- ) ) ?
346
- } else {
347
- Err ( err_sb_ub (
348
- format ! ( "deallocating while item is protected: {:?}" , item) ,
349
- None ,
350
- None ,
351
- ) ) ?
352
- }
327
+ if global. protected_tags . contains ( & item. tag ) {
328
+ if let Some ( ( tag, _alloc_range, _offset, _access) ) = provoking_access {
329
+ Err ( err_sb_ub (
330
+ format ! (
331
+ "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
332
+ tag, item
333
+ ) ,
334
+ None ,
335
+ tag. and_then ( |tag| alloc_history. get_logs_relevant_to ( tag, Some ( item. tag ) ) ) ,
336
+ ) ) ?
337
+ } else {
338
+ Err ( err_sb_ub (
339
+ format ! ( "deallocating while item is protected: {:?}" , item) ,
340
+ None ,
341
+ None ,
342
+ ) ) ?
353
343
}
354
344
}
355
345
Ok ( ( ) )
@@ -577,7 +567,7 @@ impl<'tcx> Stack {
577
567
impl < ' tcx > Stacks {
578
568
/// Creates new stack with initial tag.
579
569
fn new ( size : Size , perm : Permission , tag : SbTag ) -> Self {
580
- let item = Item { perm, tag, protector : None } ;
570
+ let item = Item { perm, tag } ;
581
571
let stack = Stack :: new ( item) ;
582
572
583
573
Stacks {
@@ -792,7 +782,6 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
792
782
} ) ;
793
783
}
794
784
795
- let protector = if protect { Some ( this. frame ( ) . extra . call_id ) } else { None } ;
796
785
trace ! (
797
786
"reborrow: {} reference {:?} derived from {:?} (pointee {}): {:?}, size {}" ,
798
787
kind,
@@ -803,6 +792,15 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
803
792
size. bytes( )
804
793
) ;
805
794
795
+ // FIXME: This just protects everything, which is wrong. At the very least, we should not
796
+ // protect anything that contains an UnsafeCell.
797
+ if protect {
798
+ this. frame_mut ( ) . extra . protected_tags . push ( new_tag) ;
799
+ this. machine . stacked_borrows . as_mut ( ) . unwrap ( ) . get_mut ( ) . protected_tags . insert ( new_tag) ;
800
+ }
801
+ // FIXME: can't hold the current span handle across the borrows of self above
802
+ let current_span = & mut this. machine . current_span ( ) ;
803
+
806
804
// Update the stacks.
807
805
// Make sure that raw pointers and mutable shared references are reborrowed "weak":
808
806
// There could be existing unique pointers reborrowed from them that should remain valid!
@@ -839,14 +837,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
839
837
} else {
840
838
Permission :: SharedReadWrite
841
839
} ;
842
- let protector = if frozen {
843
- protector
844
- } else {
845
- // We do not protect inside UnsafeCell.
846
- // This fixes https://github.com/rust-lang/rust/issues/55005.
847
- None
848
- } ;
849
- let item = Item { perm, tag : new_tag, protector } ;
840
+ let item = Item { perm, tag : new_tag } ;
850
841
let mut global = this. machine . stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
851
842
stacked_borrows. for_each ( range, |offset, stack, history, exposed_tags| {
852
843
stack. grant (
@@ -872,7 +863,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
872
863
. as_mut ( )
873
864
. expect ( "we should have Stacked Borrows data" )
874
865
. borrow_mut ( ) ;
875
- let item = Item { perm, tag : new_tag, protector } ;
866
+ let item = Item { perm, tag : new_tag } ;
876
867
let range = alloc_range ( base_offset, size) ;
877
868
let mut global = machine. stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
878
869
let current_span = & mut machine. current_span ( ) ; // `get_alloc_extra_mut` invalidated our old `current_span`
0 commit comments