I am using Pin
for some execution monitoring tasks towards x64 ELF
binary code.
During the monitoring, for any memory write/read operation of the original code, I would like to record it as long as it refers the heap
. However, given a memory address, I have no idea whether it refers the heap
memory region or not.
One possible solution I can come up with is that, before every memory operation, I acquire the runtime memory region information of the target process, and check whether the current memory address is within the heap
region. This can be done by following the steps below inside the Pintool.
- acquire the process ID of monitored process (This step can use
Pin
APIPin_GetPid
) - read the process memory region information in
/proc/XXX/maps
- find the
heap
memory region - check whether the current address is within the
heap
region
However, this is tedious and my test shows that this is extremely slow, as the size of memory heap
can change during the runtime which means I need to go through the above steps everytime before memory operation.
So I am wondering, does Pin
has APIs to provide the heap
memory region information? Or is there any solution more efficient that the above one?
===================== update ===============================