钩住pthread_create [英] Hook for pthread_create

查看:214
本文介绍了钩住pthread_create的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(在glibc-2.5和更高版本中)是否存在一种为pthread_create定义钩子的方法?

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

有很多二进制应用程序,我想编写一个动态库以通过LD_PRELOAD加载

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

我可以在main(属性构造函数")上添加条目的钩子,但是如何在线程的函数运行之前强制在每个线程中执行我的代码.

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.

推荐答案

此答案显示

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

一旦插入pthread_create,就可以使其调用自己的函数,该函数将执行所需的任何操作,然后调用用户传递给pthread_create的原始函数.

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.

这篇关于钩住pthread_create的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆