Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 1b20da07baaa3e3c424f62c927274e676e4295cd)
+++ kernel/generic/src/proc/thread.c	(revision 34e1206ec4dc79f0592077e3ee270fba91d1eb9d)
@@ -122,11 +122,11 @@
 	void *arg = THREAD->thread_arg;
 	THREAD->last_cycle = get_cycle();
-	
+
 	/* This is where each thread wakes up after its creation */
 	irq_spinlock_unlock(&THREAD->lock, false);
 	interrupts_enable();
-	
+
 	f(arg);
-	
+
 	/* Accumulate accounting to the task */
 	irq_spinlock_lock(&THREAD->lock, true);
@@ -137,5 +137,5 @@
 		uint64_t kcycles = THREAD->kcycles;
 		THREAD->kcycles = 0;
-		
+
 		irq_spinlock_pass(&THREAD->lock, &TASK->lock);
 		TASK->ucycles += ucycles;
@@ -144,7 +144,7 @@
 	} else
 		irq_spinlock_unlock(&THREAD->lock, true);
-	
+
 	thread_exit();
-	
+
 	/* Not reached */
 }
@@ -156,13 +156,13 @@
 {
 	thread_t *thread = (thread_t *) obj;
-	
+
 	irq_spinlock_initialize(&thread->lock, "thread_t_lock");
 	link_initialize(&thread->rq_link);
 	link_initialize(&thread->wq_link);
 	link_initialize(&thread->th_link);
-	
+
 	/* call the architecture-specific part of the constructor */
 	thr_constructor_arch(thread);
-	
+
 #ifdef CONFIG_FPU
 #ifdef CONFIG_FPU_LAZY
@@ -174,5 +174,5 @@
 #endif /* CONFIG_FPU_LAZY */
 #endif /* CONFIG_FPU */
-	
+
 	/*
 	 * Allocate the kernel stack from the low-memory to prevent an infinite
@@ -193,5 +193,5 @@
 	kmflags |= FRAME_LOWMEM;
 	kmflags &= ~FRAME_HIGHMEM;
-	
+
 	uintptr_t stack_phys =
 	    frame_alloc(STACK_FRAMES, kmflags, STACK_SIZE - 1);
@@ -203,11 +203,11 @@
 		return ENOMEM;
 	}
-	
+
 	thread->kstack = (uint8_t *) PA2KA(stack_phys);
-	
+
 #ifdef CONFIG_UDEBUG
 	mutex_initialize(&thread->udebug.lock, MUTEX_PASSIVE);
 #endif
-	
+
 	return EOK;
 }
@@ -217,15 +217,15 @@
 {
 	thread_t *thread = (thread_t *) obj;
-	
+
 	/* call the architecture-specific part of the destructor */
 	thr_destructor_arch(thread);
-	
+
 	frame_free(KA2PA(thread->kstack), STACK_FRAMES);
-	
+
 #ifdef CONFIG_FPU
 	if (thread->saved_fpu_context)
 		slab_free(fpu_context_cache, thread->saved_fpu_context);
 #endif
-	
+
 	return STACK_FRAMES;  /* number of frames freed */
 }
@@ -239,14 +239,14 @@
 {
 	THREAD = NULL;
-	
+
 	atomic_set(&nrdy, 0);
 	thread_cache = slab_cache_create("thread_t", sizeof(thread_t), 0,
 	    thr_constructor, thr_destructor, 0);
-	
+
 #ifdef CONFIG_FPU
 	fpu_context_cache = slab_cache_create("fpu_context_t",
 	    sizeof(fpu_context_t), FPU_CONTEXT_ALIGN, NULL, NULL, 0);
 #endif
-	
+
 	avltree_create(&threads_tree);
 }
@@ -282,9 +282,9 @@
 {
 	irq_spinlock_lock(&thread->lock, true);
-	
+
 	assert(thread->state != Ready);
 
 	before_thread_is_ready(thread);
-	
+
 	int i = (thread->priority < RQ_COUNT - 1) ?
 	    ++thread->priority : thread->priority;
@@ -305,18 +305,18 @@
 		cpu = CPU;
 	}
-	
+
 	thread->state = Ready;
-	
+
 	irq_spinlock_pass(&thread->lock, &(cpu->rq[i].lock));
-	
+
 	/*
 	 * Append thread to respective ready queue
 	 * on respective processor.
 	 */
-	
+
 	list_append(&thread->rq_link, &cpu->rq[i].rq);
 	cpu->rq[i].n++;
 	irq_spinlock_unlock(&(cpu->rq[i].lock), true);
-	
+
 	atomic_inc(&nrdy);
 	atomic_inc(&cpu->nrdy);
@@ -344,24 +344,24 @@
 	if (!thread)
 		return NULL;
-	
+
 	/* Not needed, but good for debugging */
 	memsetb(thread->kstack, STACK_SIZE, 0);
-	
+
 	irq_spinlock_lock(&tidlock, true);
 	thread->tid = ++last_tid;
 	irq_spinlock_unlock(&tidlock, true);
-	
+
 	context_save(&thread->saved_context);
 	context_set(&thread->saved_context, FADDR(cushion),
 	    (uintptr_t) thread->kstack, STACK_SIZE);
-	
+
 	the_initialize((the_t *) thread->kstack);
-	
+
 	ipl_t ipl = interrupts_disable();
 	thread->saved_context.ipl = interrupts_read();
 	interrupts_restore(ipl);
-	
+
 	str_cpy(thread->name, THREAD_NAME_BUFLEN, name);
-	
+
 	thread->thread_code = func;
 	thread->thread_arg = arg;
@@ -377,30 +377,30 @@
 	thread->uspace =
 	    ((flags & THREAD_FLAG_USPACE) == THREAD_FLAG_USPACE);
-	
+
 	thread->nomigrate = 0;
 	thread->state = Entering;
-	
+
 	timeout_initialize(&thread->sleep_timeout);
 	thread->sleep_interruptible = false;
 	thread->sleep_queue = NULL;
 	thread->timeout_pending = false;
-	
+
 	thread->in_copy_from_uspace = false;
 	thread->in_copy_to_uspace = false;
-	
+
 	thread->interrupted = false;
 	thread->detached = false;
 	waitq_initialize(&thread->join_wq);
-	
+
 	thread->task = task;
-	
+
 	thread->workq = NULL;
-	
+
 	thread->fpu_context_exists = false;
 	thread->fpu_context_engaged = false;
-	
+
 	avltree_node_initialize(&thread->threads_tree_node);
 	thread->threads_tree_node.key = (uintptr_t) thread;
-	
+
 #ifdef CONFIG_UDEBUG
 	/* Initialize debugging stuff */
@@ -408,13 +408,13 @@
 	udebug_thread_initialize(&thread->udebug);
 #endif
-	
+
 	/* Might depend on previous initialization */
 	thread_create_arch(thread);
-	
+
 	rcu_thread_init(thread);
-	
+
 	if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
 		thread_attach(thread, task);
-	
+
 	return thread;
 }
@@ -435,16 +435,16 @@
 	assert(thread->task);
 	assert(thread->cpu);
-	
+
 	irq_spinlock_lock(&thread->cpu->lock, false);
 	if (thread->cpu->fpu_owner == thread)
 		thread->cpu->fpu_owner = NULL;
 	irq_spinlock_unlock(&thread->cpu->lock, false);
-	
+
 	irq_spinlock_pass(&thread->lock, &threads_lock);
-	
+
 	avltree_delete(&threads_tree, &thread->threads_tree_node);
-	
+
 	irq_spinlock_pass(&threads_lock, &thread->task->lock);
-	
+
 	/*
 	 * Detach from the containing task.
@@ -452,5 +452,5 @@
 	list_remove(&thread->th_link);
 	irq_spinlock_unlock(&thread->task->lock, irq_res);
-	
+
 	/*
 	 * Drop the reference to the containing task.
@@ -475,16 +475,16 @@
 	 */
 	irq_spinlock_lock(&task->lock, true);
-	
+
 	/* Hold a reference to the task. */
 	task_hold(task);
-	
+
 	/* Must not count kbox thread into lifecount */
 	if (thread->uspace)
 		atomic_inc(&task->lifecount);
-	
+
 	list_append(&thread->th_link, &task->threads);
-	
+
 	irq_spinlock_pass(&task->lock, &threads_lock);
-	
+
 	/*
 	 * Register this thread in the system-wide list.
@@ -506,5 +506,5 @@
 		/* Generate udebug THREAD_E event */
 		udebug_thread_e_event();
-		
+
 		/*
 		 * This thread will not execute any code or system calls from
@@ -527,5 +527,5 @@
 		}
 	}
-	
+
 restart:
 	irq_spinlock_lock(&THREAD->lock, true);
@@ -535,10 +535,10 @@
 		goto restart;
 	}
-	
+
 	THREAD->state = Exiting;
 	irq_spinlock_unlock(&THREAD->lock, true);
-	
+
 	scheduler();
-	
+
 	/* Not reached */
 	while (true);
@@ -562,12 +562,12 @@
 {
 	assert(thread != NULL);
-	
+
 	irq_spinlock_lock(&thread->lock, true);
-	
+
 	thread->interrupted = true;
 	bool sleeping = (thread->state == Sleeping);
-	
+
 	irq_spinlock_unlock(&thread->lock, true);
-	
+
 	if (sleeping)
 		waitq_interrupt_sleep(thread);
@@ -583,11 +583,11 @@
 {
 	assert(thread != NULL);
-	
+
 	bool interrupted;
-	
+
 	irq_spinlock_lock(&thread->lock, true);
 	interrupted = thread->interrupted;
 	irq_spinlock_unlock(&thread->lock, true);
-	
+
 	return interrupted;
 }
@@ -597,5 +597,5 @@
 {
 	assert(THREAD);
-	
+
 	THREAD->nomigrate++;
 }
@@ -606,5 +606,5 @@
 	assert(THREAD);
 	assert(THREAD->nomigrate > 0);
-	
+
 	if (THREAD->nomigrate > 0)
 		THREAD->nomigrate--;
@@ -624,5 +624,5 @@
 	while (sec > 0) {
 		uint32_t period = (sec > 1000) ? 1000 : sec;
-		
+
 		thread_usleep(period * 1000000);
 		sec -= period;
@@ -643,14 +643,14 @@
 	if (thread == THREAD)
 		return EINVAL;
-	
+
 	/*
 	 * Since thread join can only be called once on an undetached thread,
 	 * the thread pointer is guaranteed to be still valid.
 	 */
-	
+
 	irq_spinlock_lock(&thread->lock, true);
 	assert(!thread->detached);
 	irq_spinlock_unlock(&thread->lock, true);
-	
+
 	return waitq_sleep_timeout(&thread->join_wq, usec, flags, NULL);
 }
@@ -672,5 +672,5 @@
 	irq_spinlock_lock(&thread->lock, true);
 	assert(!thread->detached);
-	
+
 	if (thread->state == Lingering) {
 		/*
@@ -683,5 +683,5 @@
 		thread->detached = true;
 	}
-	
+
 	irq_spinlock_unlock(&thread->lock, true);
 }
@@ -697,7 +697,7 @@
 {
 	waitq_t wq;
-	
+
 	waitq_initialize(&wq);
-	
+
 	(void) waitq_sleep_timeout(&wq, usec, SYNCH_FLAGS_NON_BLOCKING, NULL);
 }
@@ -707,10 +707,10 @@
 	bool *additional = (bool *) arg;
 	thread_t *thread = avltree_get_instance(node, thread_t, threads_tree_node);
-	
+
 	uint64_t ucycles, kcycles;
 	char usuffix, ksuffix;
 	order_suffix(thread->ucycles, &ucycles, &usuffix);
 	order_suffix(thread->kcycles, &kcycles, &ksuffix);
-	
+
 	char *name;
 	if (str_cmp(thread->name, "uinit") == 0)
@@ -718,5 +718,5 @@
 	else
 		name = thread->name;
-	
+
 #ifdef __32_BITS__
 	if (*additional)
@@ -729,5 +729,5 @@
 		    thread->task, thread->task->container);
 #endif
-	
+
 #ifdef __64_BITS__
 	if (*additional)
@@ -741,5 +741,5 @@
 		    thread->task, thread->task->container);
 #endif
-	
+
 	if (*additional) {
 		if (thread->cpu)
@@ -747,18 +747,18 @@
 		else
 			printf("none ");
-		
+
 		if (thread->state == Sleeping) {
 #ifdef __32_BITS__
 			printf(" %10p", thread->sleep_queue);
 #endif
-			
+
 #ifdef __64_BITS__
 			printf(" %18p", thread->sleep_queue);
 #endif
 		}
-		
+
 		printf("\n");
 	}
-	
+
 	return true;
 }
@@ -773,5 +773,5 @@
 	/* Messing with thread structures, avoid deadlock */
 	irq_spinlock_lock(&threads_lock, true);
-	
+
 #ifdef __32_BITS__
 	if (additional)
@@ -782,5 +782,5 @@
 		    " [ctn]\n");
 #endif
-	
+
 #ifdef __64_BITS__
 	if (additional) {
@@ -791,7 +791,7 @@
 		    " [task            ] [ctn]\n");
 #endif
-	
+
 	avltree_walk(&threads_tree, thread_walker, &additional);
-	
+
 	irq_spinlock_unlock(&threads_lock, true);
 }
@@ -814,5 +814,5 @@
 	avltree_node_t *node =
 	    avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) thread));
-	
+
 	return node != NULL;
 }
@@ -832,10 +832,10 @@
 	assert(interrupts_disabled());
 	assert(irq_spinlock_locked(&THREAD->lock));
-	
+
 	if (user)
 		THREAD->ucycles += time - THREAD->last_cycle;
 	else
 		THREAD->kcycles += time - THREAD->last_cycle;
-	
+
 	THREAD->last_cycle = time;
 }
@@ -846,10 +846,10 @@
 	    (thread_t *) avltree_get_instance(node, thread_t, threads_tree_node);
 	thread_iterator_t *iterator = (thread_iterator_t *) arg;
-	
+
 	if (thread->tid == iterator->thread_id) {
 		iterator->thread = thread;
 		return false;
 	}
-	
+
 	return true;
 }
@@ -869,12 +869,12 @@
 	assert(interrupts_disabled());
 	assert(irq_spinlock_locked(&threads_lock));
-	
+
 	thread_iterator_t iterator;
-	
+
 	iterator.thread_id = thread_id;
 	iterator.thread = NULL;
-	
+
 	avltree_walk(&threads_tree, thread_search_walker, (void *) &iterator);
-	
+
 	return iterator.thread;
 }
@@ -885,5 +885,5 @@
 {
 	irq_spinlock_lock(&threads_lock, true);
-	
+
 	thread_t *thread = thread_find_by_id(thread_id);
 	if (thread == NULL) {
@@ -892,7 +892,7 @@
 		return;
 	}
-	
+
 	irq_spinlock_lock(&thread->lock, false);
-	
+
 	/*
 	 * Schedule a stack trace to be printed
@@ -906,5 +906,5 @@
 	 * is probably justifiable.
 	 */
-	
+
 	bool sleeping = false;
 	istate_t *istate = thread->udebug.uspace_state;
@@ -916,10 +916,10 @@
 	} else
 		printf("Thread interrupt state not available.\n");
-	
+
 	irq_spinlock_unlock(&thread->lock, false);
-	
+
 	if (sleeping)
 		waitq_interrupt_sleep(thread);
-	
+
 	irq_spinlock_unlock(&threads_lock, true);
 }
@@ -935,12 +935,12 @@
 	if (name_len > THREAD_NAME_BUFLEN - 1)
 		name_len = THREAD_NAME_BUFLEN - 1;
-	
+
 	char namebuf[THREAD_NAME_BUFLEN];
 	errno_t rc = copy_from_uspace(namebuf, uspace_name, name_len);
 	if (rc != EOK)
 		return (sys_errno_t) rc;
-	
+
 	namebuf[name_len] = 0;
-	
+
 	/*
 	 * In case of failure, kernel_uarg will be deallocated in this function.
@@ -949,5 +949,5 @@
 	uspace_arg_t *kernel_uarg =
 	    (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
-	
+
 	rc = copy_from_uspace(kernel_uarg, uspace_uarg, sizeof(uspace_arg_t));
 	if (rc != EOK) {
@@ -955,5 +955,5 @@
 		return (sys_errno_t) rc;
 	}
-	
+
 	thread_t *thread = thread_create(uinit, kernel_uarg, TASK,
 	    THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf);
@@ -968,5 +968,5 @@
 				 * creation now.
 				 */
-				
+
 				/*
 				 * The new thread structure is initialized, but
@@ -976,9 +976,9 @@
 				slab_free(thread_cache, thread);
 				free(kernel_uarg);
-				
+
 				return (sys_errno_t) rc;
 			 }
 		}
-		
+
 #ifdef CONFIG_UDEBUG
 		/*
@@ -994,9 +994,9 @@
 #endif
 		thread_ready(thread);
-		
+
 		return 0;
 	} else
 		free(kernel_uarg);
-	
+
 	return (sys_errno_t) ENOMEM;
 }
