// argc, argv are the entire command line, including pin -t <toolname> -- ... int main(int argc, char * argv[]) { // Initialize pin PIN_Init(argc, argv); if (KnobLog) { out = fopen("emu_stack.txt", "w"); if (!out) fprintf(stderr, "Can't open log file emu_stack.txt\n"); } scratchReg = PIN_ClaimToolRegister(); if (!REG_valid(scratchReg)) { if (out) fprintf (out, "Cannot allocate a scratch register.\n"); fprintf (stderr, "Cannot allocate a scratch register.\n"); return 1; } // Register instruction instrumentation callback. INS_AddInstrumentFunction(Ins, 0); // Register Fini to be called when the application exits PIN_AddFiniFunction(Fini, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
int main(int argc, char * argv[]) { // We accumlate counts into a register, make sure it is 64 bits to // avoid overflow ASSERTX(sizeof(ADDRINT) == sizeof(UINT64)); if (PIN_Init(argc, argv)) return Usage(); OutFile.open(KnobOutputFile.Value().c_str()); ScratchReg = PIN_ClaimToolRegister(); if (!REG_valid(ScratchReg)) { std::cerr << "Cannot allocate a scratch register.\n"; std::cerr << std::flush; return 1; } PIN_AddThreadStartFunction(ThreadStart, 0); PIN_AddThreadFiniFunction(ThreadFini, 0); PIN_AddFiniFunction(Fini, 0); TRACE_AddInstrumentFunction(Trace, 0); PIN_StartProgram(); return 0; }
int main(int argc, char *argv[]) { if (PIN_Init(argc, argv)) return Usage(); if (PIN_GetDebugStatus() == DEBUG_STATUS_DISABLED) { std::cerr << "Application level debugging must be enabled to use this tool.\n"; std::cerr << "Start Pin with either -appdebug or -appdebug_enable.\n"; std::cerr << std::flush; return 1; } if (!KnobOut.Value().empty()) Output = new std::ofstream(KnobOut.Value().c_str()); // Allocate a virtual register that each thread uses to point to its // TINFO data. Threads can use this virtual register to quickly access // their own thread-private data. // RegTinfo = PIN_ClaimToolRegister(); if (!REG_valid(RegTinfo)) { std::cerr << "Cannot allocate a scratch register.\n"; std::cerr << std::flush; return 1; } PIN_AddDebugInterpreter(DebugInterpreter, 0); PIN_AddThreadStartFunction(OnThreadStart, 0); PIN_AddThreadFiniFunction(OnThreadEnd, 0); PIN_StartProgram(); return 0; }
int main(int argc, char **argv) { const int nScratch = REG_INST_TOOL_LAST-REG_INST_TOOL_FIRST+1; int seen[nScratch]; bool failed = false; PIN_Init(argc, argv); for (int i=0; i<nScratch; i++) seen[i] = 0; // Claim all the registers we expect to be able to claim for (int i=0; i<nScratch; i++) { REG scratch = PIN_ClaimToolRegister(); if (scratch < REG_INST_TOOL_FIRST || scratch > REG_INST_TOOL_LAST) { printf ("Failed: got a non-scratch register (%d)\n", int(scratch)); failed = true; } seen[scratch-REG_INST_TOOL_FIRST]++; } // Check that we fail when we try to allocate an extra one. if (PIN_ClaimToolRegister() != REG_INVALID()) { printf ("Failed: got register when we shouldn't have\n"); failed = true; } // Check that we got each register once for (int i=0; i<nScratch; i++) { if (seen[i] != 1) { printf ("Failed: saw REG_INST_G%d %d times\n", i, seen[i]); failed = true; } } if (!failed) printf ("Passed\n"); // No need to run the code... exit(failed ? 1 : 0); }
//get the first scratch register available //we build a vector in order to deal with multiple read operand static REG GetScratchReg(UINT32 index) { static std::vector<REG> regs; while (index >= regs.size()){ //get thefirst clean register REG reg = PIN_ClaimToolRegister(); regs.push_back(reg); } return regs[index]; }
int main(int argc, char * argv[]) { PIN_Init(argc, argv); for (unsigned i = 0; i < NUM_SCRATCH; i++) ScratchRegs[i] = PIN_ClaimToolRegister(); INS_AddInstrumentFunction(InstrumentIns, 0); PIN_StartProgram(); return 0; }
int main(int argc, char * argv[]) { PIN_InitSymbols(); PIN_Init(argc, argv); // Scratch register used to select // instrumentation version. version_reg = PIN_ClaimToolRegister(); TRACE_AddInstrumentFunction(Trace, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
REG GetScratchReg(UINT32 index) { static std::vector<REG> regs; while (index >= regs.size()) { REG reg = PIN_ClaimToolRegister(); if (reg == REG_INVALID()) { std::cerr << "*** Ran out of tool registers" << std::endl; PIN_ExitProcess(1); /* does not return */ } regs.push_back(reg); } return regs[index]; }
int main(int argc, char **argv) { PIN_Init(argc, argv); PIN_InitSymbols(); scratchReg = PIN_ClaimToolRegister(); if (!REG_valid(scratchReg)) { fprintf (stderr, "Cannot allocate a scratch register.\n"); return 1; } PIN_AddThreadStartFunction(OnThread, 0); IMG_AddInstrumentFunction(Image, 0); PIN_StartProgram(); return 0; }
int main(int argc, char * argv[]) { // prepare for image instrumentation mode PIN_InitSymbols(); // Initialize pin if (PIN_Init(argc, argv)) return -1; scratchReg = PIN_ClaimToolRegister(); // Register ImageLoad to be called when an image is loaded IMG_AddInstrumentFunction(ImageLoad, 0); // And our Fini function to check that we did all we expected to. PIN_AddFiniFunction(Fini, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
/* * initialize thread contexts * * spill a tool register for the thread * contexts and register a thread start callback * * returns: 0 on success, 1 on error */ static inline int thread_ctx_init(void) { /* claim a tool register; optimized branch */ if (unlikely( (thread_ctx_ptr = PIN_ClaimToolRegister()) == REG_INVALID())) { /* error message */ LOG(string(__FUNCTION__) + ": register claim failed\n"); /* failed */ return 1; } /* * thread start/stop hooks; * keep track of the threads and allocate/free space for the * per-thread logistics (i.e., syscall context, VCPU, etc) */ PIN_AddThreadStartFunction(thread_alloc, NULL); PIN_AddThreadFiniFunction(thread_free, NULL); /* success */ return 0; }
int main(int argc, char * argv[]) { PIN_Init(argc, argv); PIN_InitSymbols(); RegThreadInfo = PIN_ClaimToolRegister(); if (RegThreadInfo == REG_INVALID()) { std::cout << "Out of tool registers" << std::endl; PIN_ExitProcess(1); } // Get the test type and initialize the corresponding lock variable. // TestType = GetTestType(KnobTest.Value()); switch (TestType) { case TEST_NONE: std::cout << "Must specify a test to run with the '-test' knob" << std::endl; PIN_ExitProcess(1); break; case TEST_INVALID: std::cout << "Invalid test name: " << KnobTest.Value() << std::endl; PIN_ExitProcess(1); break; case TEST_LOCK_INTEGRITY: case TEST_LOCK_STRESS: PIN_InitLock(&Lock); break; case TEST_MUTEX_INTEGRITY: case TEST_MUTEX_STRESS: case TEST_MUTEX_TRYSTRESS: PIN_MutexInit(&Mutex); break; case TEST_WRITER_INTEGRITY: case TEST_WRITER_STRESS: case TEST_WRITER_TRYSTRESS: case TEST_READER_STRESS: case TEST_READER_TRYSTRESS: case TEST_RW_INTEGRITY: case TEST_RW_STRESS: case TEST_RW_TRYSTRESS: PIN_RWMutexInit(&RWMutex); break; case TEST_SEMAPHORE: PIN_SemaphoreInit(&Sem1); PIN_SemaphoreInit(&Sem2); PIN_SemaphoreSet(&Sem1); PIN_MutexInit(&Mutex); break; case TEST_TRYLOCKS: PIN_MutexInit(&Mutex); PIN_RWMutexInit(&RWMutex); PIN_SemaphoreInit(&Sem1); break; default: ASSERTX(0); } PIN_AddThreadStartFunction(OnThreadStart, 0); PIN_AddThreadFiniFunction(OnThreadFini, 0); RTN_AddInstrumentFunction(InstrumentRtn, 0); PIN_AddFiniFunction(OnExit, 0); PIN_StartProgram(); return 0; }