I have a rather unusual use-case. I'm in middle of porting part of my application to Rust (from C++)
Let's say I have a struct defined in a header and present in a prebuilt .so file (C++).
struct A {
int (*cb1)(struct A *s),
void (*cb2)(struct A *s, int *data),
const char * (*cb3)(struct A *s, int *data),
const char * (*cb4)(struct A *s, int *data),
int (*cb5)(struct A *s, int *data),
}
This struct is to be initialized in Rust side and the pointer is to be sent to C++ side.
The library will then copy its own functions to the callbacks which are then be called from Rust side.
I'm not sure how to solve this problem. Any help would be highly appreciated.
there are countless things could cause a ffi call to crash. that's why ffi is always unsafe. most common reasons including incorrect data structure layout or incorrect function type declaration. it's your responsibility to make sure the foreign types are declared correctly.
in your case, I suspect you forget the null terminator of the symbol name to load. also, the symbol type should be unsafe extern "C" fn(*mut A), I believe if you omit the "C" part, it default to "Rust" ABI.