I'd like to create C-linkage functions to intercept my program's calls via LD_PRELOAD
but I'm implementing the interception functions in Rust.
I have no problem creating the pub extern fn
to intercept the calls but I'd like to read/write from the program's global state somewhere since I can't alter the signature of the functions I'm intercepting to accept the metadata. I don't need heap allocation necessarily, I could live with some large statically initialized pool of HashSet
or Vec
entries. But I do need to be able to add and remove elements of the collection during the program's run.
I recognize that this pattern is contrary to many Rust design goals and yet it seems like a legitimate use case to me.
I'm brand new to Rust, so I'm hoping that there's an unsafe
option out there to do this.
If it's useful to see code examples:
static mut foo Vec<c_int> = Vec::new();
...fails because you can't have static
storage that requires a destructor, or does heap allocations. And lazy_static!
doesn't allow for mut
able structures.
Ideally I'd prefer a HashSet<c_int>
. If I can't get that to work, I suppose I could try a Vec::from_elem(100, 0)
. That's not ideal since I'll need to nominate some kind of sentry value, but if it works I think I'd be satisfied.