Пример #1
0
/*
* FIXME: global handler for internal errors (i.e., errors from libdft)
*
* for unknown reasons, when an analysis function is executed,
* the EFLAGS.AC bit (i.e., bit 18) is asserted, thus leading
* into a runtime exception whenever an unaligned read/write
* is performed from libdft. This callback can be registered
* with PIN_AddInternalExceptionHandler() so as to trap the
* generated signal and remediate
*
* @tid:		thread id
* @pExceptInfo:	exception descriptor
* @pPhysCtxt:		physical processor state
* @v:			callback value
*/
static EXCEPT_HANDLING_RESULT
fix_eflags(THREADID tid, EXCEPTION_INFO *pExceptInfo,
	PHYSICAL_CONTEXT *pPhysCtxt, VOID *v)
{
	/* we only care about unaligned memory accesses */
	if (PIN_GetExceptionCode(pExceptInfo) ==
		EXCEPTCODE_ACCESS_MISALIGNED) {
			/* clear EFLAGS.AC */
			PIN_SetPhysicalContextReg(pPhysCtxt, REG_EFLAGS,
				CLEAR_EFLAGS_AC(PIN_GetPhysicalContextReg(pPhysCtxt,
				REG_EFLAGS)));

			/* the exception is handled gracefully; commence execution */
			return EHR_HANDLED;
	}
	else
		/* unknown exception; pass to the application */
		return EHR_UNHANDLED;
}
Пример #2
0
EXCEPT_HANDLING_RESULT DivideHandler(THREADID tid, EXCEPTION_INFO * pExceptInfo, 
                                        PHYSICAL_CONTEXT * pPhysCtxt, VOID *appContextArg)
{
    if(PIN_GetExceptionCode(pExceptInfo) == EXCEPTCODE_INT_DIVIDE_BY_ZERO) 
    {
#if 1
        //Temporary work-around, Remove when Mantis #1986 is resolved
        string str = PIN_ExceptionToString(pExceptInfo);
        printf("GlobalHandler: Caught divide by zero exception. %s\n", str.c_str());
#else
        cout << "GlobalHandler: Caught divide by zero exception. " << PIN_ExceptionToString(pExceptInfo) << endl;
#endif
        CONTEXT * appCtxt = (CONTEXT *)appContextArg;
        ADDRINT faultIp = PIN_GetContextReg(appCtxt, REG_INST_PTR);
        PIN_SetExceptionAddress(pExceptInfo, faultIp);
        PIN_RaiseException(appCtxt, tid, pExceptInfo); //never returns 
    }
    return EHR_CONTINUE_SEARCH;
}