add: TRACE(("thread_exit: thread 0x%lx now a kernel thread!\n", t->id));
context: thread_exit(void){	cpu_status state;	struct thread *t = thread_get_current_thread();	struct team *team = t->team;	thread_id mainParentThread = -1;	bool delete_team = false;	unsigned int death_stack;	sem_id cached_death_sem;	status_t status;	if (!are_interrupts_enabled())		dprintf("thread_exit() called with interrupts disabled!\n");	TRACE(("thread 0x%lx exiting %s w/return code 0x%x\n", t->id,		t->return_flags & THREAD_RETURN_INTERRUPTED ? "due to signal" : "normally",		(int)t->return_code));	// boost our priority to get this over with	t->priority = B_FIRST_REAL_TIME_PRIORITY;		// ToDo: is it really that urgent?	// shutdown the thread messaging	status = acquire_sem_etc(t->msg.write_sem, 1, B_RELATIVE_TIMEOUT, 0);	if (status == B_WOULD_BLOCK) {		// there is data waiting for us, so let us eat it		thread_id sender;		delete_sem(t->msg.write_sem);			// first, let's remove all possibly waiting writers		receive_data_etc(&sender, NULL, 0, B_RELATIVE_TIMEOUT);	} else {		// we probably own the semaphore here, and we're the last to do so		delete_sem(t->msg.write_sem);	}	// now we can safely remove the msg.read_sem	delete_sem(t->msg.read_sem);	// Cancel previously installed alarm timer, if any	cancel_timer(&t->alarm);		// delete the user stack region first	if (team->_aspace_id >= 0 && t->user_stack_region_id >= 0) {		region_id rid = t->user_stack_region_id;		t->user_stack_region_id = -1;		delete_area_etc(team, rid);	}	if (team != team_get_kernel_team()) {		// remove this thread from the current team and add it to the kernel		// put the thread into the kernel team until it dies		state = disable_interrupts();		GRAB_TEAM_LOCK();		remove_thread_from_team(team, t);		insert_thread_into_team(team_get_kernel_team(), t);		if (team->main_thread == t) {			// this was main thread in this team			delete_team = true;			// remember who our parent was so we can send a signal			mainParentThread = team->parent->main_thread->id;			team_remove_team(team);		}		RELEASE_TEAM_LOCK();		// swap address spaces, to make sure we're running on the kernel's pgdir		vm_aspace_swap(team_get_kernel_team()->kaspace);		restore_interrupts(state);//		dprintf("thread_exit: thread 0x%x now a kernel thread!\n", t->id);	}	// delete the team if we're its main thread	if (delete_team) {		team_delete_team(team);		send_signal_etc(mainParentThread, SIGCHLD, B_DO_NOT_RESCHEDULE);		cached_death_sem = -1;	} else		cached_death_sem = team->death_sem;	// delete the sem that others will use to wait on us and get the retcode	{		sem_id s = t->return_code_sem;		t->return_code_sem = -1;		delete_sem_etc(s, t->return_code, t->return_flags & THREAD_RETURN_INTERRUPTED ? true : false);	}	death_stack = get_death_stack();	{		struct thread_exit_args args;		args.t = t;		args.old_kernel_stack = t->kernel_stack_region_id;		args.death_stack = death_stack;		args.death_sem = cached_death_sem;		// disable the interrupts. Must remain disabled until the kernel stack pointer can be officially switched		args.int_state = disable_interrupts();		// set the new kernel stack officially to the death stack, wont be really switched until		// the next function is called. This bookkeeping must be done now before a context switch		// happens, or the processor will interrupt to the old stack		t->kernel_stack_region_id = death_stacks[death_stack].rid;		t->kernel_stack_base = death_stacks[death_stack].address;		// we will continue in thread_exit2(), on the new stack		arch_thread_switch_kstack_and_call(t, t->kernel_stack_base + KSTACK_SIZE, thread_exit2, &args);	}	panic("never can get here\n");}