刚刚做了一个试验,答案是:存在越界问题。
[root@FC5 thread]# gcc -o hk hookpthread.c -lpthread;./hk;cat hookpthread.c
&a:[b7f77464]-----a:[20]
&b:[b7576464]
hook-->&a:[20]
&a:[b7f77464]-----a:[30]
#include
#include
void * fun(void * i)
{
int a=20;
printf("&a:[%x]-----a:[%d]\n", &a,a);
sleep(1);
printf("&a:[%x]-----a:[%d]\n", &a,a);
pthread_exit(NULL);
}
void * hook(void * a)
{
int b=10;
printf("&b:[%x]\n", &b);
printf("hook-->&a:[%d]\n", *(&b+2622464));
*(&b+2622464)=30;
pthread_exit(NULL);
}
int main()
{
pthread_t pidfun,pidhook;
pthread_create(&pidfun, NULL, fun, NULL);
pthread_create(&pidhook, NULL, hook, NULL);
sleep(2);
return 0;
}