示例#1
0
文件: haiku-nat.c 项目: mariuz/haiku
static char *
haiku_pid_to_str (ptid_t ptid)
{
	static char buffer[B_OS_NAME_LENGTH + 64 + 64];
	team_info teamInfo;
	thread_info threadInfo;
	status_t error;

	// get the team info for the target team
	error = get_team_info(ptid_get_pid(ptid), &teamInfo);
	if (error != B_OK) {
		sprintf(buffer, "invalid team ID %d", ptid_get_pid(ptid));
		return buffer;
	}

	// get the thread info for the target thread
	error = get_thread_info(ptid_get_tid(ptid), &threadInfo);
	if (error != B_OK) {
		sprintf(buffer, "team %.*s (%ld) invalid thread ID %ld",
			(int)sizeof(teamInfo.args), teamInfo.args, teamInfo.team,
			ptid_get_tid(ptid));
		return buffer;
	}

	sprintf(buffer, "team %.*s (%ld) thread %s (%ld)",
		(int)sizeof(teamInfo.args), teamInfo.args, teamInfo.team,
		threadInfo.name, threadInfo.thread);

	return buffer;
}
static team_id getTeamID(void)
{
    thread_info info;
    thread_id tid = find_thread(NULL);
    get_thread_info(tid, &info);
    return info.team;
} /* getTeamID */
示例#3
0
文件: heap.c 项目: dholroyd/pup
static int set_local_region(struct PupHeap *heap, struct PupHeapRegion *region)
{
	ABORT_ON(!region, "set_local_region() given null region");
	get_thread_info(heap)->local_region = region;
	// TODO: error handling?
	return 0;
}
static void print_thread_info(int pid)
{
	struct task_struct *ptask;
	struct pid *k;
    struct thread_info *threadinfo = NULL;
    union thread_union *threadunion = NULL;
    /* find tak by pid */
	k = find_vpid(pid);
	ptask = pid_task(k, PIDTYPE_PID);

	printk(KERN_INFO "process   : %s, pid   : %d\n", ptask->comm, ptask->pid);

    /*  ptask->stack point to thread_unuion  */
    threadinfo = get_thread_info(ptask);

    /* union thread_union
     * {
     *     struct thread_info thread_info;
     *     unsigned long stack[THREAD_SIZE/sizeof(long)];
     * };
     */
    threadunion = get_thread_union(threadinfo);

    show_kstack(threadunion);

    //printk(KERN_INFO "task stack            : %p\n", ptask->stack);
}
示例#5
0
文件: heap.c 项目: dholroyd/pup
static void pup_heap_thread_destroy(struct PupHeap *heap)
{
	struct PupHeapRegion *local_region = get_thread_info(heap)->local_region;
	if (local_region) {
		free_region(local_region);
	}
}
BReferenceable::~BReferenceable()
{
#ifdef DEBUG
	bool enterDebugger = false;
	if (fReferenceCount == 1) {
		// Simple heuristic to test if this object was allocated
		// on the stack: check if this is within 1KB in either
		// direction of the current stack address, and the reference
		// count is 1. If so, we don't flag a warning since that would
		// imply the object was allocated/destroyed on the stack
		// without any references being acquired or released.
		char test;
		size_t testOffset = (addr_t)this - (addr_t)&test;
		if (testOffset > 1024 || -testOffset > 1024) {
			// might still be a stack object, check the thread's
			// stack range to be sure.
			thread_info info;
			status_t result = get_thread_info(find_thread(NULL), &info);
			if (result != B_OK || this < info.stack_base
				|| this > info.stack_end) {
				enterDebugger = true;
			}
		}
	} else if (fReferenceCount != 0)
		enterDebugger = true;

	if (enterDebugger)
		debugger("Deleted referenceable object with non-zero ref count.");
#endif
}
void
BMediaTrack::SetupWorkaround()
{
    app_info	ainfo;
    thread_info	tinfo;

    get_thread_info(find_thread(0), &tinfo);
    be_roster->GetRunningAppInfo(tinfo.team, &ainfo);

    if (strcmp(ainfo.signature, "application/x-vnd.marcone-soundplay") == 0) {
        fWorkaroundFlags = FORCE_RAW_AUDIO | FORCE_RAW_AUDIO_INT16_FORMAT
                           | FORCE_RAW_AUDIO_HOST_ENDIAN;
        printf("BMediaTrack::SetupWorkaround: SoundPlay workaround active\n");
    }
    if (strcmp(ainfo.signature, "application/x-vnd.Be.MediaPlayer") == 0) {
        fWorkaroundFlags = IGNORE_ENCODED_AUDIO | IGNORE_ENCODED_VIDEO;
        printf("BMediaTrack::SetupWorkaround: MediaPlayer workaround active\n");
    }

#if CONVERT_TO_INT32
    // TODO: Test
    if (!(fWorkaroundFlags & FORCE_RAW_AUDIO_INT16_FORMAT))
        fWorkaroundFlags |= FORCE_RAW_AUDIO_INT32_FORMAT;
#endif
}
示例#8
0
文件: pm.c 项目: BackupTheBerlios/uuu
     /****************************************************************************
     REMARKS:
     Increase the thread priority to maximum, if possible.
     ****************************************************************************/
     int PMAPI PM_setMaxThreadPriority(void)
     {
     thread_id thid = find_thread(NULL);
     thread_info tinfo;
     get_thread_info(thid, &tinfo);
     set_thread_priority(thid, B_REAL_TIME_PRIORITY);
     return tinfo.priority;
 }
示例#9
0
int
mp3_init(
	int stereo,
	float framerate,
	float bitrate,
	void ** cookie)
{
	//fprintf(stderr, "mp3_init(%s, %g, %g)\n", stereo ? "stereo" : "mono", framerate, bitrate);


	int32 v = atomic_or(&inited, 1);
	if (v == 0) {
		g_lock = create_sem(1, "EncoderGlobals");
		atomic_or(&inited, 2);
	}
	else while (!(v & 2)) {
		snooze(10000);
		v = atomic_or(&inited, 0);
	}
	thread_info tinfo;
	get_thread_info(find_thread(NULL), &tinfo);
	//fprintf(stderr,
	//		"thread %d (%s) tries to lock blade_mp3_globals\n",
	//		tinfo.thread,
	//		tinfo.name);
	status_t ret = acquire_sem(g_lock);
	if (ret == B_OK) 
	{
		//fprintf(stderr,
		//		"blade_mp3_globals holder is thread %d (%s)\n",
		//		tinfo.thread,
		//		tinfo.name);

		CodecInitIn info;
		info.frequency = (int32)framerate;
		info.mode = (stereo ? 0 : 3);
		info.bitrate = (int32)(128000.0/1000);
		info.emphasis = 0;
		info.fPrivate = 0;
		info.fCRC = 0;
		info.fCopyright = 1;
		info.fOriginal = 1;

		CodecInitOut * p = codecInit(&info);
		if (p == 0) 
		{
			//fprintf(stderr, "codecInit returns error\n");
			ret = B_ERROR;
		}
		else 
		{
			//fprintf(stderr, "p->nSamples = %d\n", p->nSamples);
			assert(p->nSamples == 1152*(stereo ? 2 : 1));
			*cookie = (void *)1;
		}
	}
	return ret;
}
示例#10
0
文件: haiku-nat.c 项目: mariuz/haiku
static int
haiku_child_thread_alive (ptid_t ptid)
{
	thread_info info;

	TRACE(("haiku_child_thread_alive(`%s')\n", haiku_pid_to_str(ptid)));

	return (get_thread_info(ptid_get_tid(ptid), &info) == B_OK);
}
示例#11
0
void
mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
	thread_info ti;
	get_thread_info(get_pthread_thread_id(pthread_self()), &ti);

	*staddr = ti.stack_base;
	*stsize = ti.stack_end - ti.stack_base;
}
示例#12
0
/*!	\brief Returns the ID of the current team.
	\return The ID of the current team.
*/
team_id
current_team()
{
	if (sCurrentTeam < 0) {
		thread_info info;
		if (get_thread_info(find_thread(NULL), &info) == B_OK)
			sCurrentTeam = info.team;
	}
	return sCurrentTeam;
}
示例#13
0
int32 xmain(void* data) {
  char sig[50];
  thread_info info;
  strcpy(sig, "application/x-");
  get_thread_info(find_thread(NULL), &info);
  strcat(sig, info.name);
  XApp myapp(sig);
  myapp.Run();
  return 0;
};
示例#14
0
int
mp3_done(
	void * cookie)
{
	if (cookie == 0) return B_BAD_VALUE;
	thread_info info;
	get_thread_info(find_thread(NULL), &info);
	//fprintf(stderr, "thread %d (%s) releases blade_mp3_globals\n", info.thread, info.name);
	return release_sem(g_lock);
}
示例#15
0
status_t
ExpanderThread::SuspendExternalExpander()
{
	thread_info info;
	status_t status = get_thread_info(fThreadId, &info);

	if (status == B_OK)
		return send_signal(-fThreadId, SIGSTOP);
	else
		return status;
}
示例#16
0
status_t
ExpanderThread::WaitOnExternalExpander()
{
	thread_info info;
	status_t status = get_thread_info(fThreadId, &info);

	if (status == B_OK)
		return wait_for_thread(fThreadId, &status);
	else
		return status;
}
示例#17
0
文件: AppMisc.cpp 项目: mariuz/haiku
/*!	\brief Returns the ID of the current team.
	\return The ID of the current team.
*/
team_id
current_team()
{
	static team_id team = -1;
	if (team < 0) {
		thread_info info;
		if (get_thread_info(find_thread(NULL), &info) == B_OK)
			team = info.team;
	}
	return team;
}
示例#18
0
status_t
ExpanderThread::ResumeExternalExpander()
{
	thread_info info;
	status_t status = get_thread_info(fThreadId, &info);

	if (status == B_OK)
		return send_signal(-fThreadId, SIGCONT);
	else
		return status;
}
示例#19
0
int32 LoadIcon(void)
{
	thread_info threadInfo;
	status_t error = get_thread_info(find_thread(NULL), &threadInfo);
	if (error != B_OK) {
		return 0;
	}
	team_id sTeam = threadInfo.team;
	
	return LoadIcon(sTeam);
}
示例#20
0
文件: heap.c 项目: dholroyd/pup
void pup_heap_safepoint(struct PupHeap *heap)
{
	struct PupThreadInfo *tinfo = get_thread_info(heap);
	// the thread-local gc_waiting flag is set from a signal handler on
	// this thread, hence we don't use explicit atomic ops or locking
	// for this access
	if (tinfo->gc_waiting) {
		pup_gc_scan_stack(get_gc_state(heap));
		announce_mutator_arrival(heap, tinfo);
	}
}
示例#21
0
status_t
LocalDebuggerInterface::GetThreadInfo(thread_id thread, ThreadInfo& info)
{
	thread_info threadInfo;
	status_t error = get_thread_info(thread, &threadInfo);
	if (error != B_OK)
		return error;

	info.SetTo(threadInfo.team, threadInfo.thread, threadInfo.name);
	return B_OK;
}
示例#22
0
static void remove_most_recently_locked(MutexInfo* mrl) {
    ThreadInfo* tinfo = get_thread_info(gettid());
    if (mrl->next) {
        (mrl->next)->prev = mrl->prev;
    }
    if (mrl->prev) {
        (mrl->prev)->next = mrl->next;
    }
    if (tinfo->mrl == mrl) {
        tinfo->mrl = mrl->next;
    }
}
/* check this every 1msec */
void CNatRxManager::handle_aging() {
    int i;
    dsec_t now=now_sec();
    for (i=0; i<m_max_threads; i++) {
        CNatPerThreadInfo * thread_info=get_thread_info( i );
        if ( thread_info->m_cur_nat_msg ) {
            if ( now - thread_info->m_last_time > MAX_TIME_MSG_IN_QUEUE_SEC ) {
                flush_node(thread_info);
            }
        }
    }
}
示例#24
0
文件: clock.c 项目: rickcaudill/Pyro
/* Return the time used by the program so far (user time + system time).  */
clock_t
clock ()
{
  thread_id thread;
  thread_info info;

  thread = get_thread_id(NULL);
  if( get_thread_info(thread,&info) != 0 )
    return (clock_t) -1;

  return (clock_t) info.ti_real_time;
}
示例#25
0
文件: main.c 项目: 26597925/iovyroot
int getroot(struct offsets* o)
{
	int ret = 1;
	int dev;
	unsigned long fp;
	struct thread_info* ti;
	void* jopdata;

	if((jopdata = mmap((void*)((unsigned long)MMAP_ADDR + MMAP_SIZE), PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED | MAP_FIXED | MAP_ANONYMOUS, -1, 0)) == (void*)-1)
		return -ENOMEM;

	printf("[+] Installing JOP\n");
	if(write_at_address(o->check_flags, (unsigned long)o->joploc))
		goto end2;

	sidtab = o->sidtab;
	policydb = o->policydb;
	preparejop(jopdata, o->jopret);
	if((dev = open("/dev/ptmx", O_RDWR)) < 0)
		goto end2;

	//we only get the lower 32bit because the return of fcntl is int
	fp = (unsigned)fcntl(dev, F_SETFL, jopdata);
	fp += KERNEL_START;
	ti = get_thread_info(fp);

	printf("[+] Patching addr_limit\n");
	if(write_at_address(&ti->addr_limit, -1))
		goto end;
	printf("[+] Removing JOP\n");
	if(writel_at_address_pipe(o->check_flags, 0))
		goto end;

	if((ret = modify_task_cred_uc(ti)))
		goto end;

	//Z5 has domain auto trans from init to init_shell (restricted) so disable selinux completely
	{
		int zero = 0;
		if(o->selinux_enabled)
			write_at_address_pipe(o->selinux_enabled, &zero, sizeof(zero));
		if(o->selinux_enforcing)
			write_at_address_pipe(o->selinux_enforcing, &zero, sizeof(zero));
	}

	ret = 0;
end:
	close(dev);
end2:
	munmap(jopdata, PAGE_SIZE);
	return ret;
}
示例#26
0
文件: heap.c 项目: dholroyd/pup
static void siguser1_handler(int sig, siginfo_t *si, void *unused)
{
	ABORTF_ON(si->si_code != SI_QUEUE, "expected SI_QUEUE(%d), got %d", SI_QUEUE, si->si_code);
	struct PupHeap *heap = (struct PupHeap *)si->si_value.sival_ptr;
	struct PupThreadInfo *tinfo = get_thread_info(heap);
	// set the thread-local variable indicating that when the (non-signal-
	// handler) code in this thread reaches a safepoint, it should notify
	// the gc thread that this has happened
	tinfo->gc_waiting = true;
	// sync the mark value used for thread local allocations with the
	// current global value
	tinfo->current_gc_mark = pup_gc_get_current_mark(get_gc_state(heap));
}
示例#27
0
void
HTGTimeLineView::updateTimeLine()
{
	// Kill ongoing updates
	thread_info info;
	if(get_thread_info(previousThread, &info) == B_OK) {
		kill_thread(info.thread);
	}
		
	previousThread = spawn_thread(updateTimeLineThread, Name(), 10, this);
	resume_thread(previousThread);
	waitingForUpdate = false;
}
示例#28
0
status_t
ExpanderThread::InterruptExternalExpander()
{
	thread_info info;
	status_t status = get_thread_info(fThreadId, &info);

	if (status == B_OK) {
		status = send_signal(-fThreadId, SIGINT);
		WaitOnExternalExpander();
	}

	return status;
}
示例#29
0
extern "C" Display* XOpenDisplay(const char *name) {
  Display* display = new _XDisplay;
  memset(display, 0, sizeof(Display));
  main_thread = find_thread(NULL);
  thread_info info;
  get_thread_info(main_thread, &info);
  rename_thread(main_thread, "X Server"); 
  server_thread = spawn_thread(xmain, info.name, B_NORMAL_PRIORITY, 0);
  resume_thread(server_thread);
  suspend_thread(main_thread);
  init_font();
  set_display(display);
  return display;
}
示例#30
0
文件: thread.c 项目: mmadia/zfs-haiku
int
thr_main(void)
{
	thread_id curThreadID = find_thread(NULL);
	
	if (curThreadID != B_OK)
		return -1;
	
	thread_info curThreadInfo;
	if (get_thread_info(curThreadID, &curThreadInfo) != B_OK)
		return -1;

	return curThreadInfo.team == curThreadID;
}