-
Notifications
You must be signed in to change notification settings - Fork 1
Function Pointer Wrapper Ideas
sehgalrohan edited this page Feb 2, 2015
·
1 revision
If we decide to wrap all function pointer args to external functions, we need to design the wrapper.
- The llvm pass can identify Value objects which are function pointers.
- It can also identify if these function pointers are to external functions.
- Once we have this collection of pointers to internal functions passed to external functions, we can create a wrapper for each, with the same type, and create a static member for this function to store the value.
- Then, at the site of the call we simply set the static member to the original argument and pass a pointer to the wrapper to the external function.
For example,
Original code
extern void atexit(void (*f)(void));
void main()
{
atexit(&f0);
}
New code:
static void (*wrap0_ptr)();
void wrap0()
{
wrap0_ptr();
}
void main()
{
wrap0_ptr = &f0;
atexit(&wrap0);
}