handle get_alloc_extra the same throughout Stacked Borrows

This commit is contained in:
Ralf Jung 2022-07-20 17:40:49 -04:00
parent 167e5dcad3
commit 59f9a918ed
3 changed files with 41 additions and 23 deletions

View File

@ -94,16 +94,21 @@ impl<'mir, 'tcx> GlobalStateInner {
None None
} }
pub fn expose_ptr(ecx: &mut MiriEvalContext<'mir, 'tcx>, alloc_id: AllocId, sb: SbTag) { pub fn expose_ptr(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
alloc_id: AllocId,
sb: SbTag,
) -> InterpResult<'tcx> {
let global_state = ecx.machine.intptrcast.get_mut(); let global_state = ecx.machine.intptrcast.get_mut();
// In strict mode, we don't need this, so we can save some cycles by not tracking it. // In strict mode, we don't need this, so we can save some cycles by not tracking it.
if global_state.provenance_mode != ProvenanceMode::Strict { if global_state.provenance_mode != ProvenanceMode::Strict {
trace!("Exposing allocation id {alloc_id:?}"); trace!("Exposing allocation id {alloc_id:?}");
global_state.exposed.insert(alloc_id); global_state.exposed.insert(alloc_id);
if ecx.machine.stacked_borrows.is_some() { if ecx.machine.stacked_borrows.is_some() {
ecx.expose_tag(alloc_id, sb); ecx.expose_tag(alloc_id, sb)?;
} }
} }
Ok(())
} }
pub fn ptr_from_addr_transmute( pub fn ptr_from_addr_transmute(

View File

@ -754,15 +754,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
ptr: Pointer<Self::Provenance>, ptr: Pointer<Self::Provenance>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
match ptr.provenance { match ptr.provenance {
Provenance::Concrete { alloc_id, sb } => { Provenance::Concrete { alloc_id, sb } =>
intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, sb); intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, sb),
}
Provenance::Wildcard => { Provenance::Wildcard => {
// No need to do anything for wildcard pointers as // No need to do anything for wildcard pointers as
// their provenances have already been previously exposed. // their provenances have already been previously exposed.
Ok(())
} }
} }
Ok(())
} }
/// Convert a pointer with provenance into an allocation-offset pair, /// Convert a pointer with provenance into an allocation-offset pair,

View File

@ -777,20 +777,31 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
return Ok(()) return Ok(())
}; };
let extra = this.get_alloc_extra(alloc_id)?; let (_size, _align, kind) = this.get_alloc_info(alloc_id);
let mut stacked_borrows = extra match kind {
.stacked_borrows AllocKind::LiveData => {
.as_ref() // This should have alloc_extra data, but `get_alloc_extra` can still fail
.expect("we should have Stacked Borrows data") // if converting this alloc_id from a global to a local one
.borrow_mut(); // uncovers a non-supported `extern static`.
stacked_borrows.history.log_creation( let extra = this.get_alloc_extra(alloc_id)?;
Some(orig_tag), let mut stacked_borrows = extra
new_tag, .stacked_borrows
alloc_range(base_offset, size), .as_ref()
current_span, .expect("we should have Stacked Borrows data")
); .borrow_mut();
if protect { stacked_borrows.history.log_creation(
stacked_borrows.history.log_protector(orig_tag, new_tag, current_span); Some(orig_tag),
new_tag,
alloc_range(base_offset, size),
current_span,
);
if protect {
stacked_borrows.history.log_protector(orig_tag, new_tag, current_span);
}
}
AllocKind::Function | AllocKind::Dead => {
// No stacked borrows on these allocations.
}
} }
Ok(()) Ok(())
}; };
@ -1116,7 +1127,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
} }
/// Mark the given tag as exposed. It was found on a pointer with the given AllocId. /// Mark the given tag as exposed. It was found on a pointer with the given AllocId.
fn expose_tag(&mut self, alloc_id: AllocId, tag: SbTag) { fn expose_tag(&mut self, alloc_id: AllocId, tag: SbTag) -> InterpResult<'tcx> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
// Function pointers and dead objects don't have an alloc_extra so we ignore them. // Function pointers and dead objects don't have an alloc_extra so we ignore them.
@ -1125,8 +1136,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let (_size, _align, kind) = this.get_alloc_info(alloc_id); let (_size, _align, kind) = this.get_alloc_info(alloc_id);
match kind { match kind {
AllocKind::LiveData => { AllocKind::LiveData => {
// This should have alloc_extra data. // This should have alloc_extra data, but `get_alloc_extra` can still fail
let alloc_extra = this.get_alloc_extra(alloc_id).unwrap(); // if converting this alloc_id from a global to a local one
// uncovers a non-supported `extern static`.
let alloc_extra = this.get_alloc_extra(alloc_id)?;
trace!("Stacked Borrows tag {tag:?} exposed in {alloc_id:?}"); trace!("Stacked Borrows tag {tag:?} exposed in {alloc_id:?}");
alloc_extra.stacked_borrows.as_ref().unwrap().borrow_mut().exposed_tags.insert(tag); alloc_extra.stacked_borrows.as_ref().unwrap().borrow_mut().exposed_tags.insert(tag);
} }
@ -1134,5 +1147,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// No stacked borrows on these allocations. // No stacked borrows on these allocations.
} }
} }
Ok(())
} }
} }