tags:

views:

22

answers:

1

Hi

Is there (in glibc-2.5 and newer) a way to define a hook for pthread_create?

There is a lot of binary applications and I want to write a dynamic lib to be loaded via LD_PRELOAD

I can add hook on entry to main (''attributte constructor''), but how can I force my code to be executed in every thread just before the thread's function will run.

+1  A: 

This answer shows how to interpose pthread_create. (Beware: it will work correctly in 64-bit, but not 32-bit programs.)

Once you interpose pthread_create, you can make it call your own function, which will do whatever you want, and then call the original function the user passed to pthread_create.

Employed Russian
Why this don't work in 32-bit? а если статические приложения нужно инструментировать? Я думал, может есть что по типу malloc_hook
osgx