redhook
redhook copied to clipboard
intercepting readlink hangs when used on rustc
I took the readlink intercept example and tried it rustc
LD_PRELOAD=examples/readlinkspy/target/debug/libreadlinkspy.so rustc And it hangs. More details here https://users.rust-lang.org/t/intercepting-libc-readlink-with-a-rust-ld-preload-program-hangs-when-applying-to-cargo-build/48057/5
On debugging, it looks like its because of the recursionn refered to below. This seems to suggest, that the code below addresses that. Bbut it doesnt seem to be in my case. Am I missing something?
I see the following comment in the redhook code.
/* Some Rust library functionality (e.g., jemalloc) initializes
* lazily, after the hooking library has inserted itself into the call
* path. If the initialization uses any hooked functions, this will lead
* to an infinite loop. Work around this by running some initialization
* code in a static constructor, and bypassing all hooks until it has
* completed. */
static INIT_STATE: atomic::AtomicBool = atomic::AtomicBool::new(false);
pub fn initialized() -> bool {
INIT_STATE.load(atomic::Ordering::SeqCst)
}
extern "C" fn initialize() {
Box::new(0u8);
INIT_STATE.store(true, atomic::Ordering::SeqCst);
}
/* Rust doesn't directly expose __attribute__((constructor)), but this
* is how GNU implements it. */
#[link_section = ".init_array"]
pub static INITIALIZE_CTOR: extern "C" fn() = ::initialize;