header files - C typedef for function prototype dlsym -
header files - C typedef for function prototype dlsym -
i writing shared library ld_preload , intercept calls existing library (in linux).
i have 50+ different function prototypes , attribute declaration write , want maintain code short possible because function prototypes large.
the issue having following: lets want intercept calls dostuff(int, void*)
i have next code:
header file:
typedef int (*dostuffprototype) (int, void*); extern dostuffprototype dlsym_dostuff; extern int dostuff(int, void*);
c file
dostuffprototype dlsym_dostuff; __attribute__((constructor)) void libsomething() { void* lib_ptr; dlerror(); lib_ptr = dlopen(lib_name, rtld_lazy); ... // loading references real library dlsym_dostuff = (dostuffprototype) dlsym(lib_ptr, "dostuff"); }
ok works fine i'd replace next line in header:
extern int dostuff(int, void*);
with like:
extern dostuffprototype dostuff;
but
'dostuff' redeclared different kind of symbol
since declared in real library...but...it has no problem current syntax...the 1 have write arguments on again... if take dereferencing off typedef:
typedef int (dostuffprototype) (int, void*);
then extern dostuffprototype dostuff;
works dlsym_dostuff = (dostuffprototype) dlsym(lib_ptr, "dostuff");
not compile...
i have tried many things: possible?
it's clear
typedef int (*dostuffprototype) (int, void*);
and
typedef int (dostuffprototype) (int, void*);
create different typedef
s.
my suggestion create 2 different typedef
s , utilize each 1 appropriately.
typedef int (dostuffprototype) (int, void*); typedef dostuffprototype* dostuffprototypeptr
and utilize them like:
extern dostuffprototypeptr dlsym_dostuff; extern dostuffprototype dostuff; ... dlsym_dostuff = (dostuffprototypeptr) dlsym(lib_ptr, "dostuff");
c header-files dlsym
Comments
Post a Comment