2

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.

osgx
  • 90,338
  • 53
  • 357
  • 513

1 Answers1

3

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.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Why this don't work in 32-bit? а если статические приложения нужно инструментировать? Я думал, может есть что по типу malloc_hook – osgx Sep 18 '10 at 12:51