/* This is called magically, by its address being stuffed in a jmp_buf and being longjmp-d to.  */
void new_thread_handler(void)
/* This is called magically, by its address being stuffed in a jmp_buf and being longjmp-d to.  */
void new_thread_handler(void)
{
	int (*fn)(void *), n;
	void *arg;
	if (current->thread.prev_sched != NULL)
		schedule_tail(current->thread.prev_sched);
	current->thread.prev_sched = NULL;
	fn = current->thread.request.u.thread.proc;
	arg = current->thread.request.u.thread.arg;
	n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
	if (n == 1) {
		interrupt_end();
		userspace(&current->thread.regs.regs);
	}
	else do_exit(0);
}