Open itamarst opened 4 years ago
The traditional generic solution for this sort of thing is a flag that tells you whether you're reentrantly calling the same function again, and if so not applying the hook. And that's problematic to implement already, but impossible given heap allocation inside the hook implementation.
I've seen a couple of crates that implement static allocators, I wonder if they would solve my problem without this having to be fixed in redhook. Will go try that.
redhook::initialized()
.The underlying problem here is described in https://github.com/geofft/redhook/blob/master/src/lib.rs - we're trying to work around another infinite loop by forcing Rust libstd to fully initialize itself in a static constructor. The approach doesn't seem to be working right, though, and anyway Rust switched away from jemalloc, so maybe the right approach is to remove this workaround and bump the MSRV (I think Rust 1.29?), or at least make the workaround conditional on whether jemalloc is in use, somehow.
Thanks for the quick response. My current thought for my own project is to write the LD_PRELOAD part in C and call into Rust with dlopen/dlsym
+ RTLD_DEEPBIND, because overriding memory allocation is so fraught anyway.
Thanks for you work on redhook, in any case, this isn't an easy problem!
I've merged the change to remove redhook::initialized
, but I think that doesn't actually fix the problem, so reopening.
Hi,
I'm trying to use redhook to hook memory allocation functions, including
malloc
andcalloc
. The problem is that the hook implementation ends up allocating memory on the heap. This leads to infinite regress—here's part of the stack from gdb: