CCTLib
Calling-context and data-object attribution library for Intel Pin
snippet.cpp
Go to the documentation of this file.
1 // @COPYRIGHT@
2 // Licensed under MIT license.
3 // See LICENSE.TXT file in the project root for more information.
4 // ==============================================================
5 
6 static inline void CopyRegionToShadowMemory(uint8_t* address, uint64_t length) {
7  uint64_t remainingBytesToCopy = length;
8  uint8_t* curAddress = address;
9 
10  while (remainingBytesToCopy) {
11  uint8_t* showPageStartAddress = GetOrCreateShadowBaseAddress((uint64_t)address);
12  uint8_t* shadowPageCopyBeginAddress = showPageStartAddress + PAGE_OFFSET((uint64_t)curAddress);
13  uint64_t bytesToCopy = (remainingBytesToCopy < PAGE_SIZE ? remainingBytesToCopy : PAGE_SIZE);
14  memcpy(shadowPageCopyBeginAddress, originalAddress, bytesToCopy);
15  remainingBytesToCopy -= bytesToCopy;
16  curAddress += bytesToCopy;
17  }
18 }
19 
20 
21 // On each Load of an image copy the image data onto the shadow memory.
22 static VOID ImageLoad(IMG img, VOID* v) {
23  uint32_t numRegions = IMG_NumRegions(img);
24  // copy bytes of each region to shadow memory
25  for (uint32_t regionIndex = 0; regionIndex < numRegions; regionIndex++) {
26  ADDRINT regionLowAddr = IMG_RegionLowAddress(img, regionIndex);
27  /* Tells the highest address of any code or data loaded by the image. This is the address of the last byte loaded by the image. */
28  ADDRINT regionHighAddr = IMG_RegionHighAddress(img, regionIndex);
29  CopyRegionToShadowMemory((uint8_t*)regionLowAddr, regionHighAddr - regionLowAddr + 1);
30  }
31 }
uint8_t * GetOrCreateShadowBaseAddress(void *address)
#define PAGE_SIZE
void * address
#define PAGE_OFFSET(addr)
Definition: shadow_memory.H:15
static VOID ImageLoad(IMG img, VOID *v)
Definition: snippet.cpp:22
static void CopyRegionToShadowMemory(uint8_t *address, uint64_t length)
Definition: snippet.cpp:6