void Instruction(INS ins, VOID *v) { RTN rtn = INS_Rtn(ins); if (RTN_Valid(rtn) && ((RTN_Name(rtn) == "SegAccessRtn") || (RTN_Name(rtn) == "SegAccessStrRtn"))) { REG segReg = INS_SegmentRegPrefix(ins); if ((segReg != REG_SEG_GS) && (segReg != REG_SEG_FS)) return; REG baseReg = (segReg == REG_SEG_GS)? REG_SEG_GS_BASE : REG_SEG_FS_BASE; for (UINT32 memopIdx=0; memopIdx<INS_MemoryOperandCount(ins); memopIdx++) { REG scratchReg = REG(int(REG_INST_G0)+memopIdx); INS_RewriteMemoryOperand(ins, memopIdx, scratchReg); INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(ProcessAddress), IARG_REG_VALUE, baseReg, IARG_MEMORYOP_EA, memopIdx, IARG_INST_PTR, IARG_RETURN_REGS, scratchReg, IARG_END); } } }
static void InstrumentIns(INS ins, VOID *) { RTN rtn = INS_Rtn(ins); if (RTN_Valid(rtn) && RTN_Name(rtn) == "DoWorkInstrumentedWithPin") { FoundDoWork = true; INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(UseLocksWorker), IARG_END); } }
static VOID Ins(INS ins, VOID *v) { RTN rtn = INS_Rtn(ins); if (!RTN_Valid(rtn) || RTN_Name(rtn) != watch_rtn) { return; } if (INS_Address(ins) == RTN_Address(rtn)) { INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(Emit), IARG_PTR, "Ins instrumentation", IARG_CALL_ORDER, CALL_ORDER_FIRST+3, IARG_END); printf("Ins Instrumenting %s\n", watch_rtn, reinterpret_cast<void *>(RTN_Address(rtn))); } }
void Instruction(INS ins, VOID *v) { RTN rtn = INS_Rtn(ins); if (RTN_Valid(rtn) && ((RTN_Name(rtn) == "SegAccessRtn") || (RTN_Name(rtn) == "SegAccessStrRtn"))) { REG segReg = INS_SegmentRegPrefix(ins); if ((segReg != REG_SEG_GS) && (segReg != REG_SEG_FS)) return; REG baseReg = (segReg == REG_SEG_GS)? REG_SEG_GS_BASE : REG_SEG_FS_BASE; if (INS_RewriteMemoryAddressingToBaseRegisterOnly(ins, MEMORY_TYPE_READ, REG_INST_G0)) { INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(ProcessAddress), IARG_REG_VALUE, baseReg, IARG_MEMORYREAD_EA, IARG_INST_PTR, IARG_RETURN_REGS, REG_INST_G0, IARG_END); } if (INS_RewriteMemoryAddressingToBaseRegisterOnly(ins, MEMORY_TYPE_WRITE, REG_INST_G1)) { INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(ProcessAddress), IARG_REG_VALUE, baseReg, IARG_MEMORYWRITE_EA, IARG_INST_PTR, IARG_RETURN_REGS, REG_INST_G1, IARG_END); } if (INS_RewriteMemoryAddressingToBaseRegisterOnly(ins, MEMORY_TYPE_READ2, REG_INST_G2)) { INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(ProcessAddress), IARG_REG_VALUE, baseReg, IARG_MEMORYREAD2_EA, IARG_INST_PTR, IARG_RETURN_REGS, REG_INST_G2, IARG_END); } } }
static VOID Instruction(INS ins, VOID *v) { RTN rtn = INS_Rtn(ins); if (!RTN_Valid(rtn) || RTN_Name(rtn) != watch_rtn) { return; } if (INS_Address(ins) == RTN_Address(rtn)) { // Pin does not support issuing an RTN_Replace from the INS instrumentation callback // This will cause Pin to terminate with an error RTN_Replace(rtn, AFUNPTR(WatchRtnReplacement)); } }
// Pin calls this function every time a new instruction is encountered VOID Instruction(INS ins, VOID *v) { RTN rtn = INS_Rtn(ins); if (!RTN_Valid(rtn)) { ++insNoRtnDiscoveredCount; INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)InsNoRtnCount, IARG_END); } else if (RTN_IsDynamic(rtn)) { ++insDynamicDiscoveredCount; INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)InsDynamicCount, IARG_END); } else { ++insNativeDiscoveredCount; INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)InsNativeCount, IARG_END); } }
static VOID Instruction(INS ins, VOID *v) { RTN rtn = INS_Rtn(ins); if (!RTN_Valid(rtn) || RTN_Name(rtn) != watch_rtn) { return; } if (INS_Address(ins) == RTN_Address(rtn)) { // Pin does not support issuing an RTN_InsertCall from the INS instrumentation callback // This will cause Pin to terminate with an error RTN_Open(rtn); RTN_InsertCall(rtn, IPOINT_BEFORE, AFUNPTR(Emit), IARG_PTR, "Ins instrumentation1", IARG_END); RTN_Close(rtn); } }
// Is called for every instruction and instruments reads and writes VOID Instruction(INS ins, VOID *v) { if(fixed_pim_flag) { fixed_pim_count++; return; } UINT32 memOperands = INS_MemoryOperandCount(ins); if(gen_pim_flag) { if(memOperands != 0) gen_pim_mem_ref++; else gen_pim_comp_ref++; return; } if(memOperands != 0) reg_mem_ref++; else reg_comp_ref++; return; #if 0 UINT32 memOperands = INS_MemoryOperandCount(ins); RTN rtn = INS_Rtn(ins); if ( RTN_Valid(rtn) && fixed_pim_flag) { FixPimCount(); //INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)FixPimCount, IARG_END); // icount++;//++insNoRtnDiscoveredCount; //INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)InsNativeCount, IARG_END); } else if ( RTN_IsDynamic(rtn) && gen_pim_flag) { for (UINT32 memOp = 0; memOp < memOperands; memOp++) { if ((INS_MemoryOperandIsRead(ins, memOp) || INS_MemoryOperandIsWritten(ins, memOp)) ) { /* INS_InsertPredicatedCall( ins, IPOINT_BEFORE, (AFUNPTR)GenPimMemCount, IARG_INST_PTR, IARG_MEMORYOP_EA, memOp, IARG_END);*/ GenPimMemCount(); //INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)GenPimMemCount, IARG_END); } else { GenPimCoRef(); //INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)GenPimCoRef, IARG_END); } } } else { for (UINT32 memOp = 0; memOp < memOperands; memOp++) { if (INS_MemoryOperandIsRead(ins, memOp) || INS_MemoryOperandIsWritten(ins, memOp)) { /*INS_InsertPredicatedCall( ins, IPOINT_BEFORE, (AFUNPTR)RegMemRef, IARG_INST_PTR, IARG_MEMORYOP_EA, memOp, IARG_END);*/ RegMemRef(); //INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)RegMemRef, IARG_END); } else { RegCoRef(); // INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)RegCoRef, IARG_END); } } } INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)docount, IARG_END); INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)FixPimCount, IARG_END); INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)GenPimMemCount, IARG_END); INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)GenPimCoRef, IARG_END); INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)RegMemRef, IARG_END); INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)RegCoRef, IARG_END); #endif }