Beispiel #1
0
// -------------------------------------------------------------
// Thread start function
// -------------------------------------------------------------
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v) {

    // create local thread data
    _STool_TThreadRec* tdata = (_STool_TThreadRec*)malloc(sizeof(_STool_TThreadRec) + gSetup.threadRecSize);
    if (tdata == NULL) panic(threadid, "Can't allocate thread specific info");

    // init local thread data
    tdata->threadID     = threadid;
    tdata->stackTop     = 0;
    tdata->stackMaxSize = INIT_STACK;
    
    // create initial shadow activation stack
    tdata->activationStack     = (_STool_TActivationRec*)malloc(tdata->stackMaxSize*sizeof(_STool_TActivationRec));
    if (tdata->activationStack == NULL) panic(threadid, "Can't allocate shadow activation stack");
    
    // create initial user stack (if any was requested by the analysis tool)
    if (gSetup.activationRecSize > 0) {
        tdata->userStack       = (char*)malloc(tdata->stackMaxSize*gSetup.activationRecSize);
        if (tdata->userStack   == NULL) panic(threadid, "Can't allocate user stack");
    }
    else tdata->userStack = NULL;
    
    // if using memory operations buffering, initialize trace buffer pointer
    if (gSetup.memBuf) tdata->buf_addr = PIN_GetBufferPointer(ctxt, buf_id);

    // call thread start callback (if any was specified by the analysis tool)
    if (gSetup.threadStart)
        gSetup.threadStart(tdata + 1);

    // associate thread-specific data to thread
    PIN_SetThreadData(gTlsKey, tdata, threadid);
}
Beispiel #2
0
/*
 * thread start callback (analysis function)
 *
 * allocate space for the syscall context and VCPUs
 * (i.e., thread context), and set the TLS-like pointer
 * (i.e., thread_ctx_ptr) accordingly
 *
 * @tid:	thread id
 * @ctx:	CPU context
 * @flags:	OS specific flags for the new thread
 * @v:		callback value
 */
static void
thread_alloc(THREADID tid, CONTEXT *ctx, INT32 flags, VOID *v)
{
	/* thread context pointer (ptr) */
	thread_ctx_t *tctx = NULL;

	/* allocate space for the thread context; optimized branch */
	if (unlikely((tctx = (thread_ctx_t *)calloc(1,
					sizeof(thread_ctx_t))) == NULL)) {
		/* error message */
		LOG(string(__func__) + ": thread_ctx_t allocation failed (" +
				string(strerror(errno)) + ")\n");

		/* die */
		libdft_die();
	}

	/* save the address of the per-thread context to the spilled register */
	PIN_SetContextReg(ctx, thread_ctx_ptr, (ADDRINT)tctx);

    char fileName[256];
    sprintf(fileName, "C:\\itrace_thread%u.txt", tid);
    thread_local *t_local = new thread_local;
    t_local->insaddr = 0;
    t_local->logfile = fopen(fileName, "w");
    PIN_SetThreadData(trace_tls_key, t_local, tid);
}
Beispiel #3
0
VOID ThreadFini(THREADID threadid, const CONTEXT *ctxt, INT32 flags, VOID *v)
{
  if(threadid!=0)return;
  delete tdata;
  tdata=NULL;
  PIN_SetThreadData(tls_key, NULL, threadid);
}
/*
 * Note that opening a file in a callback is only supported on Linux systems.
 * See buffer-win.cpp for how to work around this issue on Windows.
 */
VOID ThreadStart(THREADID tid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    // There is a new MLOG for every thread.  Opens the output file.
    MLOG * mlog = new MLOG(tid);

    // A thread will need to look up its MLOG, so save pointer in TLS
    PIN_SetThreadData(mlog_key, mlog, tid);

}
VOID ThreadFini(THREADID tid, const CONTEXT *ctxt, INT32 code, VOID *v)
{
    MLOG * mlog = static_cast<MLOG*>(PIN_GetThreadData(mlog_key, tid));

    cout << "Count[" << decstr(tid) << "]= " << mlog->_icount << endl;
    cout << "Total count[" << decstr(tid) << "]= " << mlog->_total << endl;
    delete mlog;

    PIN_SetThreadData(mlog_key, 0, tid);
}
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    GetLock(&lock, threadid+1);
    numThreads++;
    ReleaseLock(&lock);

    thread_data_t* tdata = new thread_data_t;

    PIN_SetThreadData(tls_key, tdata, threadid);
}
Beispiel #7
0
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
  if(threadid!=0)return;
  PIN_GetLock(&lock, threadid+1);
  numThreads++;
  PIN_ReleaseLock(&lock);    

  tdata = new thread_data_t (threadid);

  PIN_SetThreadData(tls_key, tdata, threadid);
}
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    PIN_GetLock(&lock, 0);

    thread_data *td = new thread_data;

    PIN_SetThreadData(tls_key, td, threadid);

    all_thread_data.push_back(td);

    PIN_ReleaseLock(&lock);
}
Beispiel #9
0
VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    PIN_GetLock(&lock, threadid+1);
    numThreads++;
    PIN_ReleaseLock(&lock);

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

    PIN_SetThreadData(tls_key, tdata, threadid);

}
    static void thread_start(THREADID tid, CONTEXT *ctxt, INT32 flags, VOID *v)
    {
        sse_aligner_t *pthis = static_cast<sse_aligner_t *>(v);

        if (pthis->verbose)
            *(pthis->out) << "thead begin " << static_cast<uint32_t>(tid) << endl;
        // This function is locked no need for a Pin Lock here
        pthis->num_threads++;
        pthis->active_threads++;

        thread_data_t* tdata = new thread_data_t;
        // remember my pointer for later
        PIN_SetThreadData(pthis->tls_key, tdata, tid);
    }
Beispiel #11
0
/*
 * thread finish callback (analysis function)
 *
 * free the space for the syscall context and VCPUs
 *
 * @tid:	thread id
 * @ctx:	CPU context
 * @code:	OS specific termination code for the thread
 * @v:		callback value
 */
static void
thread_free(THREADID tid, const CONTEXT *ctx, INT32 code, VOID *v)
{
	/* get the thread context */
	thread_ctx_t *tctx = (thread_ctx_t *)
		PIN_GetContextReg(ctx, thread_ctx_ptr);

	/* free the allocated space */
	free(tctx);

    thread_local *t_local = (thread_local *)PIN_GetThreadData(trace_tls_key, tid);
    PIN_SetThreadData(trace_tls_key, NULL, tid);
    fflush(t_local->logfile);
    fclose(t_local->logfile);
    delete(t_local);
}
Beispiel #12
0
VOID ThreadStart( THREADID tid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    PIN_GetLock(&lock, tid+1);

    tIds[numThreads] = tid;
    stringstream fn;

    if ( tid != numThreads ) {
	cout << " TID NOT SAME AS NUMTHREADS " << tid << " " << numThreads << endl;
    }

    fn.str("");
    fn << OUT_FILE << "_" << numThreads;
    OutFile[numThreads].open(fn.str().c_str(), ios::out);
    ++numThreads;
    PIN_ReleaseLock(&lock);

    thread_data_t *tdata = new thread_data_t(numThreads-1);
    PIN_SetThreadData(tls_key, tdata, tid);
}
Beispiel #13
0
VOID ThreadStart( THREADID tid, CONTEXT *ctxt, INT32 flags, VOID *v)
{
    PIN_GetLock(&lock, tid+1);

    tIds[numThreads] = tid;
    stringstream fn;

    /* If you ever see this then change the logic in code which uses tid to 
       index into open File streams to do File I/O */
    if ( tid != numThreads ) {
	cout << " TID NOT SAME AS NUMTHREADS " << tid << " " << numThreads << endl;
    }

    fn.str("");
    fn << OUT_FILE << "_" << numThreads;
    OutFile[numThreads].open(fn.str().c_str(), ios::out);
    ++numThreads;
    PIN_ReleaseLock(&lock);

    thread_data_t *tdata = new thread_data_t(numThreads-1);
    PIN_SetThreadData(tls_key, tdata, tid);
}
void ThreadStart(THREADID tid, CONTEXT * context, int flags, void * v)
{
    // We check that we got the right thing in the buffer full callback
    PIN_SetThreadData(buf_key, PIN_GetBufferPointer(context, bufId), tid);
}
Beispiel #15
0
VOID SaveEa(THREADID tid, VOID * ea)
{
    PIN_SetThreadData(ea_tls_key, ea, tid);
}
Beispiel #16
0
// PIN_SetThreadData and PIN_GetThreadData are overloaded,
// hence we use a detour to get a single function pointer
static BOOL PIN_SetThreadData_detour(
    TLS_KEY key, const void *data, THREADID thread_id)
{
    return PIN_SetThreadData(key, data, thread_id);
}