11//! Global machine state as well as implementation of the interpreter engine
22//! `Machine` trait.
33
4+ use std:: any:: Any ;
45use std:: borrow:: Cow ;
56use std:: cell:: RefCell ;
67use std:: collections:: hash_map:: Entry ;
@@ -336,6 +337,11 @@ pub struct AllocExtra<'tcx> {
336337 /// if this allocation is leakable. The backtrace is not
337338 /// pruned yet; that should be done before printing it.
338339 pub backtrace : Option < Vec < FrameInfo < ' tcx > > > ,
340+ /// Synchronization primitives like to attach extra data to particular addresses. We store that
341+ /// inside the relevant allocation, to ensure that everything is removed when the allocation is
342+ /// freed.
343+ /// This maps offsets to synchronization-primitive-specific data.
344+ pub sync : FxHashMap < Size , Box < dyn Any > > ,
339345}
340346
341347// We need a `Clone` impl because the machine passes `Allocation` through `Cow`...
@@ -348,7 +354,7 @@ impl<'tcx> Clone for AllocExtra<'tcx> {
348354
349355impl VisitProvenance for AllocExtra < ' _ > {
350356 fn visit_provenance ( & self , visit : & mut VisitWith < ' _ > ) {
351- let AllocExtra { borrow_tracker, data_race, weak_memory, backtrace : _ } = self ;
357+ let AllocExtra { borrow_tracker, data_race, weak_memory, backtrace : _, sync : _ } = self ;
352358
353359 borrow_tracker. visit_provenance ( visit) ;
354360 data_race. visit_provenance ( visit) ;
@@ -1187,7 +1193,13 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11871193 . insert ( id, ( ecx. machine . current_span ( ) , None ) ) ;
11881194 }
11891195
1190- interp_ok ( AllocExtra { borrow_tracker, data_race, weak_memory, backtrace } )
1196+ interp_ok ( AllocExtra {
1197+ borrow_tracker,
1198+ data_race,
1199+ weak_memory,
1200+ backtrace,
1201+ sync : FxHashMap :: default ( ) ,
1202+ } )
11911203 }
11921204
11931205 fn adjust_alloc_root_pointer (
0 commit comments