Skip to content

Commit a20fb71

Browse files
committed
give StackedBorrows access check access to the ThreadManager
1 parent f84a976 commit a20fb71

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
638638
tag,
639639
range,
640640
machine.stacked_borrows.as_ref().unwrap(),
641+
&machine.threads,
641642
)
642643
} else {
643644
Ok(())
@@ -661,6 +662,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
661662
tag,
662663
range,
663664
machine.stacked_borrows.as_mut().unwrap(),
665+
&machine.threads,
664666
)
665667
} else {
666668
Ok(())

src/stacked_borrows.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ impl<'tcx> Stack {
350350
tag: SbTag,
351351
(alloc_id, range, offset): (AllocId, AllocRange, Size), // just for debug printing and error messages
352352
global: &GlobalStateInner,
353+
_threads: &ThreadManager<'_, 'tcx>,
353354
) -> InterpResult<'tcx> {
354355
// Two main steps: Find granting item, remove incompatible items above.
355356

@@ -427,6 +428,7 @@ impl<'tcx> Stack {
427428
new: Item,
428429
(alloc_id, alloc_range, offset): (AllocId, AllocRange, Size), // just for debug printing and error messages
429430
global: &GlobalStateInner,
431+
threads: &ThreadManager<'_, 'tcx>,
430432
) -> InterpResult<'tcx> {
431433
// Figure out which access `perm` corresponds to.
432434
let access =
@@ -454,7 +456,7 @@ impl<'tcx> Stack {
454456
// A "safe" reborrow for a pointer that actually expects some aliasing guarantees.
455457
// Here, creating a reference actually counts as an access.
456458
// This ensures F2b for `Unique`, by removing offending `SharedReadOnly`.
457-
self.access(access, derived_from, (alloc_id, alloc_range, offset), global)?;
459+
self.access(access, derived_from, (alloc_id, alloc_range, offset), global, threads)?;
458460

459461
// We insert "as far up as possible": We know only compatible items are remaining
460462
// on top of `derived_from`, and we want the new item at the top so that we
@@ -630,6 +632,7 @@ impl Stacks {
630632
tag: SbTag,
631633
range: AllocRange,
632634
state: &GlobalState,
635+
threads: &ThreadManager<'_, 'tcx>,
633636
) -> InterpResult<'tcx> {
634637
trace!(
635638
"read access with tag {:?}: {:?}, size {}",
@@ -639,7 +642,7 @@ impl Stacks {
639642
);
640643
let global = &*state.borrow();
641644
self.for_each(range, move |offset, stack| {
642-
stack.access(AccessKind::Read, tag, (alloc_id, range, offset), global)
645+
stack.access(AccessKind::Read, tag, (alloc_id, range, offset), global, threads)
643646
})
644647
}
645648

@@ -650,6 +653,7 @@ impl Stacks {
650653
tag: SbTag,
651654
range: AllocRange,
652655
state: &mut GlobalState,
656+
threads: &ThreadManager<'_, 'tcx>,
653657
) -> InterpResult<'tcx> {
654658
trace!(
655659
"write access with tag {:?}: {:?}, size {}",
@@ -659,7 +663,7 @@ impl Stacks {
659663
);
660664
let global = state.get_mut();
661665
self.for_each_mut(range, move |offset, stack| {
662-
stack.access(AccessKind::Write, tag, (alloc_id, range, offset), global)
666+
stack.access(AccessKind::Write, tag, (alloc_id, range, offset), global, threads)
663667
})
664668
}
665669

@@ -765,7 +769,13 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
765769
};
766770
let item = Item { perm, tag: new_tag, protector };
767771
stacked_borrows.for_each(range, |offset, stack| {
768-
stack.grant(orig_tag, item, (alloc_id, range, offset), &*global)
772+
stack.grant(
773+
orig_tag,
774+
item,
775+
(alloc_id, range, offset),
776+
&*global,
777+
&this.machine.threads,
778+
)
769779
})
770780
})?;
771781
return Ok(());
@@ -774,14 +784,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
774784
// Here we can avoid `borrow()` calls because we have mutable references.
775785
// Note that this asserts that the allocation is mutable -- but since we are creating a
776786
// mutable pointer, that seems reasonable.
777-
let (alloc_extra, memory_extra) = this.get_alloc_extra_mut(alloc_id)?;
787+
let (alloc_extra, machine) = this.get_alloc_extra_mut(alloc_id)?;
778788
let stacked_borrows =
779789
alloc_extra.stacked_borrows.as_mut().expect("we should have Stacked Borrows data");
780-
let global = memory_extra.stacked_borrows.as_mut().unwrap().get_mut();
790+
let global = machine.stacked_borrows.as_mut().unwrap().get_mut();
781791
let item = Item { perm, tag: new_tag, protector };
782792
let range = alloc_range(base_offset, size);
783793
stacked_borrows.for_each_mut(alloc_range(base_offset, size), |offset, stack| {
784-
stack.grant(orig_tag, item, (alloc_id, range, offset), global)
794+
stack.grant(orig_tag, item, (alloc_id, range, offset), global, &machine.threads)
785795
})?;
786796
Ok(())
787797
}

0 commit comments

Comments
 (0)