@@ -76,7 +76,7 @@ use rustc_target::abi::Size;
76
76
use crate :: {
77
77
ImmTy , Immediate , InterpResult , MPlaceTy , MemPlaceMeta , MiriEvalContext , MiriEvalContextExt ,
78
78
OpTy , Pointer , RangeMap , ScalarMaybeUninit , Tag , ThreadId , VClock , VTimestamp ,
79
- VectorIdx ,
79
+ VectorIdx , MemoryKind , MiriMemoryKind
80
80
} ;
81
81
82
82
pub type AllocExtra = VClockAlloc ;
@@ -674,6 +674,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
674
674
Ok ( ( ) )
675
675
}
676
676
}
677
+
678
+ fn reset_vector_clocks (
679
+ & mut self ,
680
+ ptr : Pointer < Tag > ,
681
+ size : Size
682
+ ) -> InterpResult < ' tcx > {
683
+ let this = self . eval_context_mut ( ) ;
684
+ if let Some ( data_race) = & mut this. memory . extra . data_race {
685
+ if data_race. multi_threaded . get ( ) {
686
+ let alloc_meta = this. memory . get_raw_mut ( ptr. alloc_id ) ?. extra . data_race . as_mut ( ) . unwrap ( ) ;
687
+ alloc_meta. reset_clocks ( ptr. offset , size) ;
688
+ }
689
+ }
690
+ Ok ( ( ) )
691
+ }
677
692
}
678
693
679
694
/// Vector clock metadata for a logical memory allocation.
@@ -688,7 +703,18 @@ pub struct VClockAlloc {
688
703
689
704
impl VClockAlloc {
690
705
/// Create a new data-race detector for newly allocated memory.
691
- pub fn new_allocation ( global : & MemoryExtra , len : Size , track_alloc : bool ) -> VClockAlloc {
706
+ pub fn new_allocation ( global : & MemoryExtra , len : Size , kind : MemoryKind < MiriMemoryKind > ) -> VClockAlloc {
707
+ let track_alloc = match kind {
708
+ // User allocated and stack memory should track allocation.
709
+ MemoryKind :: Machine (
710
+ MiriMemoryKind :: Rust | MiriMemoryKind :: C | MiriMemoryKind :: WinHeap
711
+ ) | MemoryKind :: Stack => true ,
712
+ // Other global memory should trace races but be allocated at the 0 timestamp.
713
+ MemoryKind :: Machine (
714
+ MiriMemoryKind :: Global | MiriMemoryKind :: Machine | MiriMemoryKind :: Env |
715
+ MiriMemoryKind :: ExternStatic | MiriMemoryKind :: Tls
716
+ ) | MemoryKind :: CallerLocation | MemoryKind :: Vtable => false
717
+ } ;
692
718
let ( alloc_timestamp, alloc_index) = if track_alloc {
693
719
let ( alloc_index, clocks) = global. current_thread_state ( ) ;
694
720
let alloc_timestamp = clocks. clock [ alloc_index] ;
@@ -704,6 +730,14 @@ impl VClockAlloc {
704
730
}
705
731
}
706
732
733
+ fn reset_clocks ( & mut self , offset : Size , len : Size ) {
734
+ let mut alloc_ranges = self . alloc_ranges . borrow_mut ( ) ;
735
+ for ( _, range) in alloc_ranges. iter_mut ( offset, len) {
736
+ // Reset the portion of the range
737
+ * range = MemoryCellClocks :: new ( 0 , VectorIdx :: MAX_INDEX ) ;
738
+ }
739
+ }
740
+
707
741
// Find an index, if one exists where the value
708
742
// in `l` is greater than the value in `r`.
709
743
fn find_gt_index ( l : & VClock , r : & VClock ) -> Option < VectorIdx > {
0 commit comments