Beispiel #1
0
int main(int argc, CHAR *argv[])
{
    PIN_InitSymbols();

	pagesize = getpagesize();

    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }

    //Initialize
    char *buf = (char*)malloc(sizeof(char)*200);
    char *buf2 = (char*)malloc(sizeof(char)*200);
    assert(buf);
    assert(buf2);

    int len = readlink("/proc/self/exe", buf, 200);
    buf[len] = '\0';
    int i;
    for(i=0; i<len; i++)
    {
    	if(buf[i] == '/')
    		buf[i] = '_';
    }
    /*
     * Output log file path
     * Some proccesses change working directory, so output file name should be absolute path
     */
    sprintf(buf2, "/home/jungjae/pin-2.13-61206-gcc.4.4.7-linux/source/tools/MyPinTool/obj-intel64/log");
    strcat(buf2, buf);
    pid = getpid();
    sprintf(buf, "_%x", pid);
    strcat(buf2, buf);

    trace = fopen(buf2, "a");
    assert(trace);
    free(buf);
    free(buf2);
    buf = NULL;
    buf2 = NULL;

    readid = 0;

	PIN_RWMutexInit(&malloc_lock);
	PIN_RWMutexInit(&thread_lock);
	PIN_RWMutexInit(&data_lock);
	PIN_MutexInit(&readid_lock);

	//Add Instrumentation Functions
    IMG_AddInstrumentFunction(ImageLoad, 0);
	INS_AddInstrumentFunction(Instruction, 0);
	PIN_AddSyscallEntryFunction(SyscallEntry, 0);
	PIN_AddThreadStartFunction(ThreadStart, 0);
	PIN_AddThreadFiniFunction(ThreadFini, 0);
	PIN_AddFiniFunction(Fini, 0);

	//Program Start. Never Returns
    PIN_StartProgram();

    return 0;
}
Beispiel #2
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;
}