How to interpose drop handlers?

I would like to interpose all drop handlers in a Rust program. Specifically, I want to wrap the actual drop handler call with a prologue and an epilogue.

fn drop(&mut self) {
    prologue();
    real_drop(self); // The actual drop handler defined by the original code
    epilogue();
}

In my specific case the prologue would be incrementing a counter at a fixed memory address and the epilogue decrementing it.

I believe this requires rustc compiler change, and I'm ready to do so. Actually, I am already building the program with a custom rustc and LLVM toolchain.

I am grateful to any help. Thanks in advance.

This forum is about using Rust, not modifying it.

So you might have better luck on IRLO or Zulip. Let us know here if you cross-post.

Thank you for your suggestion.

I have re-posted in IRLO

1 Like