Hook for pthread_create

只愿长相守 提交于 2019-12-07 22:42:51

问题


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:


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.



来源:https://stackoverflow.com/questions/3728857/hook-for-pthread-create

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!