EXPORT_C void CloseTestUpdateReceiver(CTContentUpdateReceiver* aReceiver)
	{
	if(!aReceiver)
		return;

	TBuf<64> contentUpdateReceiverThreadName;
	contentUpdateReceiverThreadName.Format(KMaskBackend, aReceiver->Screen());
	TBuf<64> contentUpdateReceiverThreadMask;
	contentUpdateReceiverThreadMask = contentUpdateReceiverThreadName;
	contentUpdateReceiverThreadMask.Insert(0, _L("*"));
	contentUpdateReceiverThreadMask.Append('*');
	TFindThread findThread(contentUpdateReceiverThreadMask);
	TFullName name;
	RThread thread;
	if((findThread.Next(name)!=KErrNone) ||
		(thread.Open(findThread) != KErrNone))
		{
		thread.Close();
		return;
		}
	TRequestStatus status; 
	thread.Logon(status);
	if(aReceiver)
		aReceiver->Stop();
	User::WaitForRequest(status);
	thread.Close();
	}
Example #2
0
void
vp_os_thread_priority(THREAD_HANDLE handle, int32_t priority)
{
  vp_os_mutex_lock(&thread_mutex);

  pthread_data_t* freeSlot = findThread( handle );

  vp_os_mutex_unlock(&thread_mutex);

  if( freeSlot != NULL )
  {
    int rc, policy = SCHED_OTHER;
    struct sched_param param;

    vp_os_memset(&param, 0, sizeof(param));

    rc = pthread_getschedparam(handle, &policy, &param);

    if( policy == SCHED_OTHER)
    {
      policy = SCHED_FIFO;
    }
    param.__sched_priority = 99-priority;
    rc = pthread_setschedparam(handle, policy, &param);
  }
}
Example #3
0
int
main(int argc, char *argv[])
{
	if (argc != 4)
		errx(1, "need four args: binary, types db, and output file");
	init_sli();
	const char *binary = argv[1];
	const char *typesdb = argv[2];
	const char *out = argv[3];

	auto ms = MachineState::readELFExec(binary);
	auto thr = ms->findThread(ThreadId(1));
	auto oracle = new Oracle(ms, thr, typesdb);
	
	FILE *f = fopen(out, "w");
	if (!f)
		err(1, "opening %s", out);
	for (auto instrIterator = oracle->type_db->enumerateAllInstructions();
	     !instrIterator->finished();
	     instrIterator->advance()) {
		DynAnalysisRip dar;
		instrIterator->fetch(&dar);
		fprintf(f, "%s\n", dar.name());
	}

	if (fclose(f) != 0)
		err(1, "closing %s", out);

	return 0;
}
Example #4
0
void
vp_os_thread_create(THREAD_ROUTINE f, THREAD_PARAMS parameters, THREAD_HANDLE *handle, ...)
{
  int32_t priority;
  char* name;
  void* stack_base;
  unsigned int stack_size;
  va_list va;

  pthread_data_t* freeSlot = NULL;

  pthread_once(&once,&init_thread);

  vp_os_mutex_lock(&thread_mutex);

  freeSlot = findThread( NULL_THREAD_HANDLE );
  while(freeSlot == NULL)
  {
    int old_size = threadTabSize;
    threadTabSize += 128;
    threadTab = ( pthread_data_t* )vp_os_realloc( threadTab, threadTabSize * sizeof( pthread_data_t ) );
    vp_os_memset( threadTab + old_size, 0, threadTabSize * sizeof( pthread_data_t ) );

    freeSlot = findThread( NULL_THREAD_HANDLE );
  }

  vp_os_mutex_unlock(&thread_mutex);

  pthread_attr_init( &freeSlot->attr );

  va_start(va, handle);
  priority    = va_arg(va, int32_t);
  name        = va_arg(va, char *);
  stack_base  = va_arg(va, void *);
  stack_size  = va_arg(va, unsigned int);
/*  thread = va_arg(va, cyg_thread *);*/
  va_end(va);

  pthread_create( &freeSlot->handle, &freeSlot->attr, f, parameters);

  *handle = freeSlot->handle;

  vp_os_thread_priority(freeSlot->handle, priority);
}
EXPORT_C TInt StartTestUpdateReceiver(CTContentUpdateReceiver*& aReceiver, TInt aScreen)
	{
	RThread compositionThread;
	TInt res = KErrGeneral;
	TBuf<64> contentUpdateReceiverThreadName;
	TBuf<64> contentUpdateReceiverThreadMask;
	
	// Guarantee uniqueness of thread name by using timestamp
	TTime tm;
	TBuf<32> timeStamp;
	tm.UniversalTime();
	TRAP(res, tm.FormatL(timeStamp, _L("_%H%T%S%C")));
	if(res != KErrNone)
		{
		return res;
		}

	contentUpdateReceiverThreadName.Format(KMaskBackend, aScreen);
	contentUpdateReceiverThreadName.Append(timeStamp);
	contentUpdateReceiverThreadMask = contentUpdateReceiverThreadName;
	contentUpdateReceiverThreadMask.Insert(0, _L("*"));
	TFindThread findThread(contentUpdateReceiverThreadMask);
	TFullName name;
	  // Need to check that the thread exists.
	if (findThread.Next(name)!=KErrNone)
		{
		aReceiver = reinterpret_cast <CTContentUpdateReceiver*> (aScreen);
		
		  // Create the thread for the server.
		res = compositionThread.Create(contentUpdateReceiverThreadName,
			CTContentUpdateReceiver::ThreadFunction,
			KDefaultStackSize,
			KDefaultHeapSize,
			KDefaultHeapSize,
			(TAny*) &aReceiver
			);
			
          // The thread has been created OK so get it started - however
          // we need to make sure that it has started before we continue.
		if (res==KErrNone)
			{
			TRequestStatus rendezvousStatus;
			compositionThread.SetPriority(EPriorityNormal);
			compositionThread.Rendezvous(rendezvousStatus);
			compositionThread.Resume();
			User::WaitForRequest(rendezvousStatus);
			res = rendezvousStatus.Int();
			}
		}
		compositionThread.Close();
		return res;
	}
Example #6
0
int read_proc(char *buf,char **start,off_t offset,int count,int *eof,void *data )
{

	char outputBuffer[1001];
	int len = 0;

	struct processInfo* curProcess;
	struct threadInfo* curThread;

	if(DEBUG) printk("Entering read_proc\n");
	
	if (offset>0){
		return 0;
	}

	//Find if current process exists; if not create it
	curProcess = findProcess(current);
//	if (DEBUG) curProcess = headProcess;
//	if (DEBUG) current->pid = headProcess->headThread->pid;
	if (curProcess==NULL){
		if(DEBUG) printk("current process does not exist\n");
		curProcess=addProcess(current);
		curProcess->seed = A_PRNG;
		if(DEBUG) printk("numThreads:%lu", curProcess->numThreads);		
	}else{
		printk("Process already exists. Process not being reseeded");
	}


	//Find if current thread exists; if not create it
	curThread = findThread(curProcess,current);
	if (curThread==NULL){
		if(DEBUG) printk("creating curret thread\n");
		curThread=addThread(curProcess,current);		
	}
	len = sprintf(outputBuffer, "%ld\n", curThread->nextRandom);
	if(DEBUG) printk("nextRandom: %lu\n",curThread->nextRandom);
	curThread->nextRandom = nextRandomGen(curThread->nextRandom, curProcess->numThreads);
	if (DEBUG) printk("nextnextRandom %lu\n", curThread->nextRandom);
	if (DEBUG) printk("thread %d\n", curThread->pid);
	memcpy(buf, outputBuffer, len);

	/*if()){*/
		/*if(DEBUG) printk("copy to user failed\n");*/
		/*return -EFAULT;	*/
	/*}*/
	*eof = 1;
	if(DEBUG) printk("Leaving read_proc\n");
	return len;
}
Example #7
0
void
ThreadHandleSigchld(pid_t const pid) {
/*----------------------------------------------------------------------------
   Handle a death of a child signal for process 'pid', which may be one
   of our threads.
-----------------------------------------------------------------------------*/
    struct abyss_thread * const threadP = findThread(pid);

    if (threadP) {
        if (threadP->threadDone)
            threadP->threadDone(threadP->userHandle);
        threadP->pid = 0;
    }
    /* Note that threadDone might free *threadP */
}
Example #8
0
void
vp_os_thread_resume(THREAD_HANDLE handle)
{
  vp_os_mutex_lock(&thread_mutex);

  pthread_data_t* freeSlot = findThread( handle );

  vp_os_mutex_unlock(&thread_mutex);

  if( freeSlot != NULL )
  {
    if(freeSlot->isSleeping)
    {
      pthread_kill(handle,SIGRESUME);
      freeSlot->isSleeping = 0;
    }
  }
}
Example #9
0
void
vp_os_thread_suspend(THREAD_HANDLE handle)
{
  vp_os_mutex_lock(&thread_mutex);

  pthread_data_t* freeSlot = findThread( handle );

  vp_os_mutex_unlock(&thread_mutex);

  if( freeSlot != NULL )
  {
    if(!freeSlot->isSleeping)
    {
      freeSlot->isSleeping = 1;
      pthread_kill(handle,SIGSUSPEND);
    }
  }
}
Example #10
0
void
vp_os_thread_join(THREAD_HANDLE handle)
{
  PRINT("vp_os_thread_join\n %d\n", (int)handle);

  vp_os_mutex_lock(&thread_mutex);

  pthread_data_t* freeSlot = findThread( handle );

  vp_os_mutex_unlock(&thread_mutex);

  if( freeSlot != NULL )
  {
    void *res;

    vp_os_memset(freeSlot, 0, sizeof(pthread_data_t));
    pthread_join( handle, &res);
  }
}
FrameStackItem *FramestackWidget::findFrame(int frameNo, int threadNo)
{
	ThreadStackItem * thread = findThread(threadNo);
	if (thread == 0) {
		kdDebug(9012) << "FramestackWidget::findFrame: no matching thread " << 
					frameNo << " thread: " << threadNo << endl;
		return 0;     // no matching thread?
	}

	QListViewItem * frameItem = thread->firstChild();

    while (frameItem != 0) {
        if (((FrameStackItem *) frameItem)->frameNo() == frameNo) {
            return (FrameStackItem *) frameItem;
		}

        frameItem = frameItem->nextSibling();
    }
	
    return 0;
}
Example #12
0
int write_proc(struct file *file,const char *buf,int count,void *data )
{

	char bufCopy[1001];
	long seed = 0;
	/*int numThreads = 0;*/
	/*int len = 0;*/
	struct processInfo* curProcess;
	struct threadInfo* curThread;
	struct task_struct* taskNext;



	//Nothing to write
	if (count==0){
		return 0;
	}

	//Set upper limit on size
	if(count > MAX_PROC_SIZE)
	    count = MAX_PROC_SIZE;

	//Copy from user to kernal space
	if(copy_from_user(bufCopy,buf, count))
		return -EFAULT;

	//Set terminating character
		/*bufCopy[count] = '\0';*/

	//Pull out numbers from user
	sscanf(bufCopy, "%lu",&seed);
	//If no seed chosen	
	if (seed==0){
		seed = A_PRNG;
	}
	printk("proccess id: %d", current->tgid);
	//Find if current process exists; if not create it
	curProcess = findProcess(current);
	if (curProcess==NULL){
		curProcess=addProcess(current);
		curProcess->seed = seed;		
	}else{
		printk("Process already exists. Process not being reseeded.");
		curProcess->numThreads++;
		printk("threads:%d\n", curProcess->numThreads);        
/*	taskNext = next_task(current);
        	while (taskNext&&taskNext->pid!=current->pid){
                        curProcess->numThreads++;
			printk("threads:\n",curProcess->numThreads );
                        taskNext = next_task(taskNext);
        	}*/

	}

	//Find if current thread exists; if not create it
	curThread = findThread(curProcess,current);
	if (curThread==NULL){
		curThread=addThread(curProcess,current);		
	}

	if(DEBUG) printk("Exiting write proc\n");
	memcpy(proc_data,bufCopy,count);

	if(DEBUG) 	printk("Exiting write_proc seed:%lu s\n",seed);
	return count;

}