Example #1
0
int main(INT32 argc, CHAR **argv)
{
    PIN_Init(argc, argv);
    // Use symbols to test handling of RTN of size 200000
    PIN_InitSymbols();
    
    ea_tls_key = PIN_CreateThreadDataKey(0);

    INS_AddInstrumentFunction(Instruction, 0);
    PIN_AddSyscallEntryFunction(SyscallEntry, 0);

    PIN_AddFiniFunction(Fini, 0);
    
    // Never returns
    PIN_StartProgram();
    
    return 0;
}
/*!
 * The main procedure of the tool.
 * This function is called when the application image is loaded but not yet started.
 * @param[in]   argc            total number of elements in the argv array
 * @param[in]   argv            array of command line arguments, 
 *                              including pin -t <toolname> -- ...
 */
int main(int argc, char *argv[])
{
    // Initialize PIN library. Print help message if -h(elp) is specified
    // in the command line or the command line is invalid 
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }
    
    // Initialize the memory reference buffer
    bufId = PIN_DefineTraceBuffer(sizeof(struct MEMREF), NUM_BUF_PAGES,
                                  BufferFull, 0);

    if(bufId == BUFFER_ID_INVALID){
        cerr << "Error allocating initial buffer" << endl;
        return 1;
    }

    outfile = fopen("bufferaddr.out", "w");
    if(!outfile){
        cerr << "Couldn't open bufferaddr.out" << endl;
        return 1;
    }

    PIN_InitLock(&fileLock);

    // add an instrumentation function
    TRACE_AddInstrumentFunction(Trace, 0);
    
    // Register function to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);

    buf_key = PIN_CreateThreadDataKey(0);
    PIN_AddThreadStartFunction(ThreadStart, 0);
    
    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Example #3
0
/*
 * initialization of the core tagging engine;
 * it must be called before using everything else
 *
 * returns: 0 on success, 1 on error
 */
int
libdft_init()
{
	/* initialize thread contexts; optimized branch */
	if (unlikely(thread_ctx_init()))
		/* thread contexts failed */
		return 1;

	/* initialize the tagmap; optimized branch */
	if (unlikely(tagmap_alloc()))
		/* tagmap initialization failed */
		return 1;
    trace_tls_key = PIN_CreateThreadDataKey(0);

	/*
	 * syscall hooks; store the context of every syscall
	 * and invoke registered callbacks (if any)
	 */

	/* register sysenter_save() to be called before every syscall */
	PIN_AddSyscallEntryFunction(sysenter_save, NULL);

	/* register sysexit_save() to be called after every syscall */
	PIN_AddSyscallExitFunction(sysexit_save, NULL);

	/* initialize the ins descriptors */
	(void)memset(ins_desc, 0, sizeof(ins_desc));

	/* register trace_ins() to be called for every trace */
	TRACE_AddInstrumentFunction(trace_inspect, NULL);

	/* FIXME: ugly hack for bypassing unaligned address checks */
	PIN_AddInternalExceptionHandler(fix_eflags, NULL);

	/* success */
	return 0;
}
Example #4
0
int main(int argc, char * argv[])
{
    //  Initialize pin
    if (PIN_Init(argc, argv)) return Usage();
    PIN_InitSymbols();
    
    OutFile.open(KnobOutputFile.Value().c_str());

    // Initialize the lock
    PIN_InitLock(&lock);

    // Obtain  a key for TLS storage.
    tls_key = PIN_CreateThreadDataKey(0);

    // Register ImageLoad to be called when each image is loaded.
    IMG_AddInstrumentFunction(ImageLoad, 0);
    
    // Register Analysis routines to be called when a thread begins/ends
    PIN_AddThreadStartFunction(ThreadStart, 0);
    PIN_AddThreadFiniFunction(ThreadFini, 0);

    // Register Fini to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);
   
    //c
    calcAvgTimes();
 
    clock_gettime(CLOCK_MONOTONIC, &start);

    thread_data_t* tdata = new thread_data_t;
    clock_gettime(CLOCK_MONOTONIC, &tdata->tstart);

    // Start the program, never returns
    PIN_StartProgram();
                         
    return 0;
}
int main(int argc, char * argv[])
{
    InitLock(&lock);
    // Initialize pin
    if (PIN_Init(argc, argv)) return Usage();

    //OutFile.open(KnobOutputFile.Value().c_str());
    mlog_key = PIN_CreateThreadDataKey(0);
    //trace = fopen("mem.trace", "w");

    // Register Instruction to be called to instrument instructions
    INS_AddInstrumentFunction(Instruction, 0);

    // Register Fini to be called when the application exits
 //   PIN_AddFiniFunction(Fini, 0);
    
 // add callbacks
    PIN_AddThreadStartFunction(ThreadStart, 0);
    PIN_AddThreadFiniFunction(ThreadFini, 0);
    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Example #6
0
int pintoolInit()
{ 
    int returnValue = INIT_ERROR;

    // option du pintool('taint' ou 'checkscore')    
    g_option = KOption.Value();
    
    /**** OPTION TAINT ***/
    if ("taint" == g_option)
    {
        returnValue = OPTION_TAINT;

        // instanciation des classes globales : marquage mémoire et formule SMT2
        pTmgrGlobal   = new TaintManager_Global;
        g_pFormula    = new TranslateIR;
        if (!pTmgrGlobal || !g_pFormula)  return (INIT_ERROR);

        /*** RECUPERATION DES ARGUMENTS DE LA LIGNE DE COMMANDE ***/
        // 1) si pipe => ouverture, sinon récupération de l'option 'input'
        g_nopipe = KNoPipe.Value();
        if (!g_nopipe)
        {
            // erreur si pipe ne peut pas être ouvert
            if (EXIT_FAILURE == openPipe()) return (INIT_ERROR);
            // récupération de l'entrée étudiée via le pipe
            g_inputFile = readFromPipe();
            if (g_inputFile.empty()) return (INIT_ERROR);
        }
        else
        {
            // si pas de pipe, nom de l'entrée passée par ligne de commande
            g_inputFile = KInputFile.Value();    
            // l'écriture des resultats (formule SMT2) se fera dans un fichier
            // donc récupérer le handle du fichier qui sera utilisé
            std::string formulaFile(g_inputFile + "_formula.smt2");
            g_hPipe = WINDOWS::CreateFile(
                formulaFile.c_str(), // nom du fichier 
                GENERIC_WRITE, // acces en ecriture
                0,             // pas de partage 
                nullptr,       // attributs de sécurité par défaut
                CREATE_ALWAYS, // écrasement du précédent fichier, si existant
                0,             // attributs par défaut
                nullptr);	   // pas de modèle

            if ((HANDLE)(WINDOWS::LONG_PTR) (-1) == g_hPipe)  return (INIT_ERROR);
        }

        // 2) mode verbeux : création des fichiers de log
        g_verbose = KVerbose.Value();
        if (g_verbose)
        {
            // création et ouverture du fichier de log dessasemblage
            std::string logfile(g_inputFile + "_asm.log");
            g_debug.open(logfile); 

            // création et ouverture du fichier de log de marquage
            std::string taintfile(g_inputFile + "_taint.log");
            g_taint.open(taintfile);
            if (!g_taint.good() || !g_debug.good()) return (INIT_ERROR);

            // stockage de l'heure du top départ pour statistiques
            g_timeBegin = clock();
        }

        // 4) intervalles d'octets source à marquer, si option présente
        if (!KBytes.Value().empty())  pTmgrGlobal->setBytesToTaint(KBytes.Value());

        // 5) nombre maximal de contraintes ((0 si aucune)
        g_maxConstraints = KMaxConstr.Value();
        
        // 6) type d'OS hote (déterminé par le programme appelant)
        g_osType = static_cast<OSTYPE>(KOsType.Value());
        // détermination des numéros de syscalls à monitorer (dépend de l'OS)
        if (HOST_UNKNOWN == g_osType) return (INIT_ERROR);
        else SYSCALLS::defineSyscallsNumbers(g_osType);
            
        // initialisation de variable globale indiquant le départ de l'instrumentation
        // est mise à vrai par la partie syscalls lorsque les premières données
        // marquées sont créées (= lecture dans l'entrée)
        g_beginInstrumentationOfInstructions = false;

        // création des clefs pour les TLS, pas de fonction de destruction
        g_tlsKeyTaint       = PIN_CreateThreadDataKey(nullptr);
        g_tlsKeySyscallData = PIN_CreateThreadDataKey(nullptr);
    }
    else if ("checkscore" == g_option) // option....checkscore :)   
    {
        // erreur si pipe ne peut pas être ouvert
        if (EXIT_FAILURE == openPipe()) return (INIT_ERROR);
        returnValue = OPTION_CHECKSCORE;
    }
    else return (INIT_ERROR); // option inconnue : erreur

    /**** DERNIERES INITIALISATIONS COMMUNES AUX DEUX OPTIONS **/

    // Initialisation des verrous pour le multithreading
    PIN_InitLock(&g_lock);
  
    // temps maximal d'exécution (valable en 'taint' et en 'checkscore')
    g_maxTime = KMaxTime.Value();
    // si non nul, création d'un thread interne au pintool : 
    // sert à la surveillance du temps maximal d'execution 
    if (g_maxTime)
    {
        THREADID tid = PIN_SpawnInternalThread(maxTimeThread, nullptr, 0, nullptr);
        if (INVALID_THREADID == tid)   return (INIT_ERROR);  
    }

    return (returnValue); // option choisie (taint ou checkScore), ou erreur d'init
} // pintoolInit()
Example #7
0
File: mica.cpp Project: ucmsuri/ilp
/************
 *   MAIN   *
 ************/
int main(int argc, char* argv[]){

	int i;
	setup_mica_log(&log);
	MODE mode;
	read_config(&log,&mode, &_ilp_win_size, &_block_size, &_page_size, &_itypes_spec_file);

	
	for(i=0; i < MAX_MEM_TABLE_ENTRIES; i++){
		ins_buffer[i] = (ins_buffer_entry*)NULL;
	}

	switch(mode){
	/*	case MODE_ALL:
			init_all();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_all, 0);
    			PIN_AddFiniFunction(Fini_all, 0);
			break;
		case MODE_ILP:
			init_ilp_all();
			PIN_InitSymbols();
			PIN_Init(argc, argv);
			InitLock(&lock);
			// Obtain  a key for TLS storage.
		    	tls_key = PIN_CreateThreadDataKey(0);
		        // Register ThreadStart to be called when a thread starts.
		        PIN_AddThreadStartFunction(ThreadStart, 0);
			INS_AddInstrumentFunction(Instruction_ilp_all_only, 0);
    			PIN_AddFiniFunction(Fini_ilp_all_only, 0);
			break;*/
		case MODE_ILP_ONE:
			//init_ilp_one();
			PIN_InitSymbols();
			PIN_Init(argc, argv);
			InitLock(&lock);
			// Obtain  a key for TLS storage.
		    	tls_key = PIN_CreateThreadDataKey(0);
		        // Register ThreadStart to be called when a thread starts.
		        PIN_AddThreadStartFunction(ThreadStart, 0);
			INS_AddInstrumentFunction(Instruction_ilp_one_only, 0);
    			PIN_AddFiniFunction(Fini_ilp_one_only, 0);
			break;
	/*	case MODE_ITYPES:
			init_itypes();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_itypes_only, 0);
    			PIN_AddFiniFunction(Fini_itypes_only, 0);
			break;
		case MODE_PPM:
			init_ppm();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_ppm_only, 0);
    			PIN_AddFiniFunction(Fini_ppm_only, 0);
			break;
		case MODE_REG:
			init_reg();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_reg_only, 0);
    			PIN_AddFiniFunction(Fini_reg_only, 0);
			break;
		case MODE_STRIDE:
			init_stride();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_stride_only, 0);
    			PIN_AddFiniFunction(Fini_stride_only, 0);
			break;
		case MODE_MEMFOOTPRINT:
			init_memfootprint();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_memfootprint_only, 0);
    			PIN_AddFiniFunction(Fini_memfootprint_only, 0);
			break;
		case MODE_MEMREUSEDIST:
			init_memreusedist();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_memreusedist_only, 0);
    			PIN_AddFiniFunction(Fini_memreusedist_only, 0);
			break;
		case MODE_CUSTOM:
			init_custom();
			PIN_Init(argc, argv);
			INS_AddInstrumentFunction(Instruction_custom, 0);
    			PIN_AddFiniFunction(Fini_custom, 0);
			break;*/
		default:
			cerr << "FATAL ERROR: Unknown mode while trying to allocate memory for Pin tool!" << endl;
			log << "FATAL ERROR: Unknown mode while trying to allocate memory for Pin tool!" << endl;
			exit(1);
	}

	// starts program, never returns
	PIN_StartProgram();
}