@@ -65,7 +65,6 @@ use std::{
65
65
cell:: { Cell , Ref , RefCell , RefMut } ,
66
66
fmt:: Debug ,
67
67
mem,
68
- rc:: Rc ,
69
68
} ;
70
69
71
70
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -80,7 +79,7 @@ use crate::{
80
79
} ;
81
80
82
81
pub type AllocExtra = VClockAlloc ;
83
- pub type MemoryExtra = Rc < GlobalState > ;
82
+ pub type MemoryExtra = GlobalState ;
84
83
85
84
/// Valid atomic read-write operations, alias of atomic::Ordering (not non-exhaustive).
86
85
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
@@ -488,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
488
487
) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
489
488
let this = self . eval_context_ref ( ) ;
490
489
let scalar = this. allow_data_races_ref ( move |this| this. read_scalar ( & place. into ( ) ) ) ?;
491
- self . validate_atomic_load ( place, atomic) ?;
490
+ this . validate_atomic_load ( place, atomic) ?;
492
491
Ok ( scalar)
493
492
}
494
493
@@ -501,7 +500,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
501
500
) -> InterpResult < ' tcx > {
502
501
let this = self . eval_context_mut ( ) ;
503
502
this. allow_data_races_mut ( move |this| this. write_scalar ( val, & ( * dest) . into ( ) ) ) ?;
504
- self . validate_atomic_store ( dest, atomic)
503
+ this . validate_atomic_store ( dest, atomic)
505
504
}
506
505
507
506
/// Perform a atomic operation on a memory location.
@@ -733,9 +732,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
733
732
pub struct VClockAlloc {
734
733
/// Assigning each byte a MemoryCellClocks.
735
734
alloc_ranges : RefCell < RangeMap < MemoryCellClocks > > ,
736
-
737
- /// Pointer to global state.
738
- global : MemoryExtra ,
739
735
}
740
736
741
737
impl VClockAlloc {
@@ -767,7 +763,6 @@ impl VClockAlloc {
767
763
| MemoryKind :: Vtable => ( 0 , VectorIdx :: MAX_INDEX ) ,
768
764
} ;
769
765
VClockAlloc {
770
- global : Rc :: clone ( global) ,
771
766
alloc_ranges : RefCell :: new ( RangeMap :: new (
772
767
len,
773
768
MemoryCellClocks :: new ( alloc_timestamp, alloc_index) ,
@@ -888,21 +883,19 @@ impl VClockAlloc {
888
883
/// being created or if it is temporarily disabled during a racy read or write
889
884
/// operation for which data-race detection is handled separately, for example
890
885
/// atomic read operations.
891
- pub fn read < ' tcx > ( & self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
892
- if self . global . multi_threaded . get ( ) {
893
- let ( index, clocks) = self . global . current_thread_state ( ) ;
886
+ pub fn read < ' tcx > (
887
+ & self ,
888
+ pointer : Pointer < Tag > ,
889
+ len : Size ,
890
+ global : & GlobalState ,
891
+ ) -> InterpResult < ' tcx > {
892
+ if global. multi_threaded . get ( ) {
893
+ let ( index, clocks) = global. current_thread_state ( ) ;
894
894
let mut alloc_ranges = self . alloc_ranges . borrow_mut ( ) ;
895
895
for ( _, range) in alloc_ranges. iter_mut ( pointer. offset , len) {
896
896
if let Err ( DataRace ) = range. read_race_detect ( & * clocks, index) {
897
897
// Report data-race.
898
- return Self :: report_data_race (
899
- & self . global ,
900
- range,
901
- "Read" ,
902
- false ,
903
- pointer,
904
- len,
905
- ) ;
898
+ return Self :: report_data_race ( global, range, "Read" , false , pointer, len) ;
906
899
}
907
900
}
908
901
Ok ( ( ) )
@@ -917,14 +910,15 @@ impl VClockAlloc {
917
910
pointer : Pointer < Tag > ,
918
911
len : Size ,
919
912
write_type : WriteType ,
913
+ global : & mut GlobalState ,
920
914
) -> InterpResult < ' tcx > {
921
- if self . global . multi_threaded . get ( ) {
922
- let ( index, clocks) = self . global . current_thread_state ( ) ;
915
+ if global. multi_threaded . get ( ) {
916
+ let ( index, clocks) = global. current_thread_state ( ) ;
923
917
for ( _, range) in self . alloc_ranges . get_mut ( ) . iter_mut ( pointer. offset , len) {
924
918
if let Err ( DataRace ) = range. write_race_detect ( & * clocks, index, write_type) {
925
919
// Report data-race
926
920
return Self :: report_data_race (
927
- & self . global ,
921
+ global,
928
922
range,
929
923
write_type. get_descriptor ( ) ,
930
924
false ,
@@ -943,16 +937,26 @@ impl VClockAlloc {
943
937
/// data-race threads if `multi-threaded` is false, either due to no threads
944
938
/// being created or if it is temporarily disabled during a racy read or write
945
939
/// operation
946
- pub fn write < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
947
- self . unique_access ( pointer, len, WriteType :: Write )
940
+ pub fn write < ' tcx > (
941
+ & mut self ,
942
+ pointer : Pointer < Tag > ,
943
+ len : Size ,
944
+ global : & mut GlobalState ,
945
+ ) -> InterpResult < ' tcx > {
946
+ self . unique_access ( pointer, len, WriteType :: Write , global)
948
947
}
949
948
950
949
/// Detect data-races for an unsynchronized deallocate operation, will not perform
951
950
/// data-race threads if `multi-threaded` is false, either due to no threads
952
951
/// being created or if it is temporarily disabled during a racy read or write
953
952
/// operation
954
- pub fn deallocate < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
955
- self . unique_access ( pointer, len, WriteType :: Deallocate )
953
+ pub fn deallocate < ' tcx > (
954
+ & mut self ,
955
+ pointer : Pointer < Tag > ,
956
+ len : Size ,
957
+ global : & mut GlobalState ,
958
+ ) -> InterpResult < ' tcx > {
959
+ self . unique_access ( pointer, len, WriteType :: Deallocate , global)
956
960
}
957
961
}
958
962
@@ -1035,15 +1039,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
1035
1039
) ;
1036
1040
1037
1041
// Perform the atomic operation.
1038
- let data_race = & alloc_meta. global ;
1039
1042
data_race. maybe_perform_sync_operation ( |index, mut clocks| {
1040
1043
for ( _, range) in
1041
1044
alloc_meta. alloc_ranges . borrow_mut ( ) . iter_mut ( place_ptr. offset , size)
1042
1045
{
1043
1046
if let Err ( DataRace ) = op ( range, & mut * clocks, index, atomic) {
1044
1047
mem:: drop ( clocks) ;
1045
1048
return VClockAlloc :: report_data_race (
1046
- & alloc_meta . global ,
1049
+ data_race ,
1047
1050
range,
1048
1051
description,
1049
1052
true ,
0 commit comments