1

I have a hook function like this

void newThreadCreated(void *ptid) {}

I want to insert this function into child thread's function. The issue is how to pass parent thread id (ptid) to this function. Any concrete solution or thoughts?

Thanks in Advance!

ruke
  • 55
  • 5
  • Why don't/can't you create a call? The call instruction is a Value. – arnt Oct 27 '21 at 08:27
  • Sorry, but could you elaborate. What do you mean by "The call instruction is a Value". – ruke Oct 27 '21 at 08:50
  • The [CallInst](https://llvm.org/doxygen/classllvm_1_1CallInst.html) class inherits Value (via a few intermediates), so if you have a `CallInst*`, you have a `Value*`. As you might guess, it represents the return value. – arnt Oct 28 '21 at 08:47
  • Could it be that you are mixing things here? I.e., the `thread::get_id` belongs to the process that generates the LLVM IR, while the IR is then used in another process (the generated program). Unless you are in the context of JIT, the thread_id will get a "garbage" value when used in the generated program. – AlexDenisov Oct 28 '21 at 10:01
  • @AlexDenisov yes you are right. I also noticed that after some time. What I aim to do is to get get parent tid and pass it to the child thread's function hook. Do you have solution about how to accomplish this, as there is no way of getting ptid inside child thread in linux as far as I know. – ruke Oct 28 '21 at 13:19

0 Answers0