Skip to content

Commit 8c097d5

Browse files
authored
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
2 parents eec86ba + 7de9511 commit 8c097d5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc_mir/interpret/machine.rs

+8
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ pub trait Machine<'mir, 'tcx>: Sized {
254254
kind: Option<MemoryKind<Self::MemoryKind>>,
255255
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);
256256

257+
/// Called to notify the machine before a deallocation occurs.
258+
fn before_deallocation(
259+
_memory_extra: &mut Self::MemoryExtra,
260+
_id: AllocId,
261+
) -> InterpResult<'tcx> {
262+
Ok(())
263+
}
264+
257265
/// Return the "base" tag for the given *global* allocation: the one that is used for direct
258266
/// accesses to this static/const/fn allocation. If `id` is not a global allocation,
259267
/// this will return an unusable tag (i.e., accesses will be UB)!

src/librustc_mir/interpret/memory.rs

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
254254
);
255255
}
256256

257+
M::before_deallocation(&mut self.extra, ptr.alloc_id)?;
258+
257259
let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) {
258260
Some(alloc) => alloc,
259261
None => {

0 commit comments

Comments
 (0)