From 7de9511d25e31fbb8a42d82738016ec1645b898b Mon Sep 17 00:00:00 2001 From: Ozaren Date: Thu, 9 Apr 2020 14:48:06 -0400 Subject: [PATCH] added machine hooks to track deallocations --- src/librustc_mir/interpret/machine.rs | 8 ++++++++ src/librustc_mir/interpret/memory.rs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 23e39f433f53b..fd67b088c93cf 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -254,6 +254,14 @@ pub trait Machine<'mir, 'tcx>: Sized { kind: Option>, ) -> (Cow<'b, Allocation>, Self::PointerTag); + /// Called to notify the machine before a deallocation occurs. + fn before_deallocation( + _memory_extra: &mut Self::MemoryExtra, + _id: AllocId, + ) -> InterpResult<'tcx> { + Ok(()) + } + /// Return the "base" tag for the given *global* allocation: the one that is used for direct /// accesses to this static/const/fn allocation. If `id` is not a global allocation, /// this will return an unusable tag (i.e., accesses will be UB)! diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index c16c59715e40c..539537e9de80c 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -254,6 +254,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { ); } + M::before_deallocation(&mut self.extra, ptr.alloc_id)?; + let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) { Some(alloc) => alloc, None => {