BOOL SigFunc(THREADID tid, INT32 sig, CONTEXT *ctxt, BOOL hasHandler, const EXCEPTION_INFO *pExceptInfo, void *dummy) { ADDRINT address = PIN_GetContextReg(ctxt, REG_INST_PTR); cout << "Thread " << tid << ": Tool got signal " << sig << " at PC " << hex << address << dec << "\n"; numSignalsReceived++; if (numSignalsReceived == (NUM_SEGVS/2)) { // Invalidate this instruction in code cache so it will be reinstrumented cout << "invalidating after " << numSignalsReceived << endl; CODECACHE_InvalidateRange(address, address + 20); } return (TRUE); // skip to next instruction }
BOOL SegvHandler(THREADID, INT32, CONTEXT *ctxt, BOOL, const EXCEPTION_INFO *, void *) { ADDRINT address = PIN_GetContextReg(ctxt, REG_INST_PTR); //fprintf(stderr, "Fault at %p\n",(void*)address); if (SwizzleRefs.find(address) != SwizzleRefs.end()) { return true; } // The next time we see this address, it requires swizzling SwizzleRefs.insert(address); // Invalidate this instruction in code cache so it will be reinstrumented CODECACHE_InvalidateRange(address, address + 20); // returning from the signal handler will re-execute the instruction // this time it will be swizzled return false; }