diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-04-11 01:52:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-11 01:52:27 +0200 |
| commit | 8c097d5c38f906ec1f77685714f7b7f403f5420d (patch) | |
| tree | c01112bde7f789f3817292983116a7d98334da3a | |
| parent | eec86ba3bdec9599b451593c4d16ca5581d190c9 (diff) | |
| parent | 7de9511d25e31fbb8a42d82738016ec1645b898b (diff) | |
| download | rust-8c097d5c38f906ec1f77685714f7b7f403f5420d.tar.gz rust-8c097d5c38f906ec1f77685714f7b7f403f5420d.zip | |
Rollup merge of #70962 - KrishnaSannasi:track-dealloc, r=RalfJung
added machine hooks to track deallocations This is part of rust-lang/miri#1314 in order to allow miri to show stack traces for on deallocation in order to debug use-after-free bugs
| -rw-r--r-- | src/librustc_mir/interpret/machine.rs | 8 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 2 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 23e39f433f5..fd67b088c93 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<MemoryKind<Self::MemoryKind>>, ) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, 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 c16c59715e4..539537e9de8 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 => { |
