interpret: pass MemoryKind to before_memory_deallocation

This commit is contained in:
Ralf Jung 2024-04-16 16:37:34 +02:00
parent 63f70b3d10
commit 18bfca50f1
10 changed files with 21 additions and 18 deletions

View File

@ -427,6 +427,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
_prov: (AllocId, Self::ProvenanceExtra), _prov: (AllocId, Self::ProvenanceExtra),
_size: Size, _size: Size,
_align: Align, _align: Align,
_kind: MemoryKind<Self::MemoryKind>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
Ok(()) Ok(())
} }

View File

@ -355,6 +355,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
(alloc_id, prov), (alloc_id, prov),
size, size,
alloc.align, alloc.align,
kind,
)?; )?;
// Don't forget to remember size and align of this now-dead allocation // Don't forget to remember size and align of this now-dead allocation

View File

@ -260,7 +260,7 @@ impl GlobalStateInner {
&mut self, &mut self,
id: AllocId, id: AllocId,
alloc_size: Size, alloc_size: Size,
kind: MemoryKind<machine::MiriMemoryKind>, kind: MemoryKind,
machine: &MiriMachine<'_, '_>, machine: &MiriMachine<'_, '_>,
) -> AllocState { ) -> AllocState {
match self.borrow_tracker_method { match self.borrow_tracker_method {

View File

@ -509,7 +509,7 @@ impl Stacks {
id: AllocId, id: AllocId,
size: Size, size: Size,
state: &mut GlobalStateInner, state: &mut GlobalStateInner,
kind: MemoryKind<MiriMemoryKind>, kind: MemoryKind,
machine: &MiriMachine<'_, '_>, machine: &MiriMachine<'_, '_>,
) -> Self { ) -> Self {
let (base_tag, perm) = match kind { let (base_tag, perm) = match kind {

View File

@ -34,7 +34,7 @@ impl<'tcx> Tree {
id: AllocId, id: AllocId,
size: Size, size: Size,
state: &mut GlobalStateInner, state: &mut GlobalStateInner,
_kind: MemoryKind<machine::MiriMemoryKind>, _kind: MemoryKind,
machine: &MiriMachine<'_, 'tcx>, machine: &MiriMachine<'_, 'tcx>,
) -> Self { ) -> Self {
let tag = state.base_ptr_tag(id, machine); // Fresh tag for the root let tag = state.base_ptr_tag(id, machine); // Fresh tag for the root

View File

@ -844,7 +844,7 @@ impl VClockAlloc {
global: &GlobalState, global: &GlobalState,
thread_mgr: &ThreadManager<'_, '_>, thread_mgr: &ThreadManager<'_, '_>,
len: Size, len: Size,
kind: MemoryKind<MiriMemoryKind>, kind: MemoryKind,
current_span: Span, current_span: Span,
) -> VClockAlloc { ) -> VClockAlloc {
let (alloc_timestamp, alloc_index) = match kind { let (alloc_timestamp, alloc_index) = match kind {

View File

@ -115,7 +115,7 @@ pub enum NonHaltingDiagnostic {
/// This `Item` was popped from the borrow stack. The string explains the reason. /// This `Item` was popped from the borrow stack. The string explains the reason.
PoppedPointerTag(Item, String), PoppedPointerTag(Item, String),
CreatedCallId(CallId), CreatedCallId(CallId),
CreatedAlloc(AllocId, Size, Align, MemoryKind<MiriMemoryKind>), CreatedAlloc(AllocId, Size, Align, MemoryKind),
FreedAlloc(AllocId), FreedAlloc(AllocId),
AccessedAlloc(AllocId, AccessKind), AccessedAlloc(AllocId, AccessKind),
RejectedIsolatedOp(String), RejectedIsolatedOp(String),
@ -414,7 +414,7 @@ pub fn report_error<'tcx, 'mir>(
pub fn report_leaks<'mir, 'tcx>( pub fn report_leaks<'mir, 'tcx>(
ecx: &InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>, ecx: &InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>,
leaks: Vec<(AllocId, MemoryKind<MiriMemoryKind>, Allocation<Provenance, AllocExtra<'tcx>>)>, leaks: Vec<(AllocId, MemoryKind, Allocation<Provenance, AllocExtra<'tcx>>)>,
) { ) {
let mut any_pruned = false; let mut any_pruned = false;
for (id, kind, mut alloc) in leaks { for (id, kind, mut alloc) in leaks {

View File

@ -125,7 +125,7 @@ pub use crate::eval::{
}; };
pub use crate::helpers::{AccessKind, EvalContextExt as _}; pub use crate::helpers::{AccessKind, EvalContextExt as _};
pub use crate::machine::{ pub use crate::machine::{
AllocExtra, FrameExtra, MiriInterpCx, MiriInterpCxExt, MiriMachine, MiriMemoryKind, AllocExtra, FrameExtra, MemoryKind, MiriInterpCx, MiriInterpCxExt, MiriMachine, MiriMemoryKind,
PrimitiveLayouts, Provenance, ProvenanceExtra, PrimitiveLayouts, Provenance, ProvenanceExtra,
}; };
pub use crate::mono_hash_map::MonoHashMap; pub use crate::mono_hash_map::MonoHashMap;

View File

@ -135,9 +135,9 @@ pub enum MiriMemoryKind {
Mmap, Mmap,
} }
impl From<MiriMemoryKind> for MemoryKind<MiriMemoryKind> { impl From<MiriMemoryKind> for MemoryKind {
#[inline(always)] #[inline(always)]
fn from(kind: MiriMemoryKind) -> MemoryKind<MiriMemoryKind> { fn from(kind: MiriMemoryKind) -> MemoryKind {
MemoryKind::Machine(kind) MemoryKind::Machine(kind)
} }
} }
@ -185,6 +185,8 @@ impl fmt::Display for MiriMemoryKind {
} }
} }
pub type MemoryKind = interpret::MemoryKind<MiriMemoryKind>;
/// Pointer provenance. /// Pointer provenance.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum Provenance { pub enum Provenance {
@ -863,10 +865,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
type ProvenanceExtra = ProvenanceExtra; type ProvenanceExtra = ProvenanceExtra;
type Bytes = Box<[u8]>; type Bytes = Box<[u8]>;
type MemoryMap = MonoHashMap< type MemoryMap =
AllocId, MonoHashMap<AllocId, (MemoryKind, Allocation<Provenance, Self::AllocExtra, Self::Bytes>)>;
(MemoryKind<MiriMemoryKind>, Allocation<Provenance, Self::AllocExtra, Self::Bytes>),
>;
const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global); const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);
@ -1088,7 +1088,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
ecx: &MiriInterpCx<'mir, 'tcx>, ecx: &MiriInterpCx<'mir, 'tcx>,
id: AllocId, id: AllocId,
alloc: Cow<'b, Allocation>, alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKind>>, kind: Option<MemoryKind>,
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra>>> { ) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra>>> {
let kind = kind.expect("we set our STATIC_KIND so this cannot be None"); let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
if ecx.machine.tracked_alloc_ids.contains(&id) { if ecx.machine.tracked_alloc_ids.contains(&id) {
@ -1280,6 +1280,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
(alloc_id, prove_extra): (AllocId, Self::ProvenanceExtra), (alloc_id, prove_extra): (AllocId, Self::ProvenanceExtra),
size: Size, size: Size,
align: Align, align: Align,
_kind: MemoryKind,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
if machine.tracked_alloc_ids.contains(&alloc_id) { if machine.tracked_alloc_ids.contains(&alloc_id) {
machine.emit_diagnostic(NonHaltingDiagnostic::FreedAlloc(alloc_id)); machine.emit_diagnostic(NonHaltingDiagnostic::FreedAlloc(alloc_id));

View File

@ -136,7 +136,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
fn alloc_os_str_as_c_str( fn alloc_os_str_as_c_str(
&mut self, &mut self,
os_str: &OsStr, os_str: &OsStr,
memkind: MemoryKind<MiriMemoryKind>, memkind: MemoryKind,
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> { ) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator. let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator.
let this = self.eval_context_mut(); let this = self.eval_context_mut();
@ -152,7 +152,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
fn alloc_os_str_as_wide_str( fn alloc_os_str_as_wide_str(
&mut self, &mut self,
os_str: &OsStr, os_str: &OsStr,
memkind: MemoryKind<MiriMemoryKind>, memkind: MemoryKind,
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> { ) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator. let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator.
let this = self.eval_context_mut(); let this = self.eval_context_mut();
@ -229,7 +229,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
fn alloc_path_as_c_str( fn alloc_path_as_c_str(
&mut self, &mut self,
path: &Path, path: &Path,
memkind: MemoryKind<MiriMemoryKind>, memkind: MemoryKind,
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> { ) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let os_str = let os_str =
@ -242,7 +242,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
fn alloc_path_as_wide_str( fn alloc_path_as_wide_str(
&mut self, &mut self,
path: &Path, path: &Path,
memkind: MemoryKind<MiriMemoryKind>, memkind: MemoryKind,
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> { ) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let os_str = let os_str =