use crate::trampoline;
use std::ffi::CStr;
unsafe extern "C" {
fn dlsym(handle: *mut libc::c_void, symbol: *const libc::c_char) -> *mut libc::c_void;
}
unsafe extern "C" fn hooked_dlsym(
handle: *mut libc::c_void,
symbol: *const libc::c_char,
) -> *mut libc::c_void {
let result = unsafe { dlsym(handle, symbol) };
if result.is_null() || symbol.is_null() {
return result;
}
let sym_name = unsafe { CStr::from_ptr(symbol) };
let sym_bytes = sym_name.to_bytes();
if !sym_bytes.starts_with(b"__rustc_proc_macro_decls_") {
return result;
}
unsafe { trampoline::intercept_proc_macro_table(result) }
}
#[repr(C)]
struct DyldInterpose {
replacement: unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char) -> *mut libc::c_void,
original: unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char) -> *mut libc::c_void,
}
unsafe impl Sync for DyldInterpose {}
#[used]
#[unsafe(link_section = "__DATA,__interpose")]
static INTERPOSE: DyldInterpose = DyldInterpose {
replacement: hooked_dlsym,
original: dlsym,
};