用C构造函数调用

0x6*_*015 2 c linux gcc arguments function

鉴于我有一个指向函数的指针(dlsym()例如提供)和一个类型参数的链接列表,我如何用这些参数构造一个C函数调用?

例:

struct param {
   enum type { INT32, INT64, STRING, BOOL } type;
   union { int i32; long long i64; char *str; bool b; } value;
   struct param *next;
 };
 int call_this(int (*function)(), struct param *args)
 { 
     int result;
     /* magic here  that calls function(), which has a prototype of
     f(int, long long, char *, bool); , when args consist of a linked list of
     INT32, INT64, STRING, BOOL types. */
     return result;
 }
Run Code Online (Sandbox Code Playgroud)

操作系统是Linux.我希望该解决方案可以通过MIPS,PPC和x86(全32位)架构移植,使用GCC作为编译器.

谢谢!

Tom*_*ing 6

您可能需要使用libffi.