Index: kernel/generic/src/udebug/udebug.c
===================================================================
--- kernel/generic/src/udebug/udebug.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ kernel/generic/src/udebug/udebug.c	(revision b7398c034409791e32e89439b6f1e7e895d99e10)
@@ -33,9 +33,9 @@
 /**
  * @file
- * @brief	Udebug hooks and data structure management.
+ * @brief Udebug hooks and data structure management.
  *
  * Udebug is an interface that makes userspace debuggers possible.
  */
- 
+
 #include <synch/waitq.h>
 #include <debug.h>
@@ -45,9 +45,9 @@
 #include <arch.h>
 
-
 /** Initialize udebug part of task structure.
  *
  * Called as part of task structure initialization.
- * @param ut	Pointer to the structure to initialize.
+ * @param ut Pointer to the structure to initialize.
+ *
  */
 void udebug_task_init(udebug_task_t *ut)
@@ -63,5 +63,7 @@
  *
  * Called as part of thread structure initialization.
- * @param ut	Pointer to the structure to initialize.
+ *
+ * @param ut Pointer to the structure to initialize.
+ *
  */
 void udebug_thread_initialize(udebug_thread_t *ut)
@@ -70,5 +72,5 @@
 	waitq_initialize(&ut->go_wq);
 	condvar_initialize(&ut->active_cv);
-
+	
 	ut->go_call = NULL;
 	ut->uspace_state = NULL;
@@ -76,5 +78,5 @@
 	ut->stoppable = true;
 	ut->active = false;
-	ut->cur_event = 0; /* none */
+	ut->cur_event = 0;  /* None */
 }
 
@@ -85,16 +87,14 @@
  * is received.
  *
- * @param wq	The wait queue used by the thread to wait for GO messages.
+ * @param wq The wait queue used by the thread to wait for GO messages.
+ *
  */
 static void udebug_wait_for_go(waitq_t *wq)
 {
-	int rc;
-	ipl_t ipl;
-
-	ipl = waitq_sleep_prepare(wq);
-
-	wq->missed_wakeups = 0;	/* Enforce blocking. */
-	rc = waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
-
+	ipl_t ipl = waitq_sleep_prepare(wq);
+	
+	wq->missed_wakeups = 0;  /* Enforce blocking. */
+	int rc = waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
+	
 	waitq_sleep_finish(wq, rc, ipl);
 }
@@ -102,69 +102,68 @@
 /** Start of stoppable section.
  *
- * A stoppable section is a section of code where if the thread can be stoped. In other words,
- * if a STOP operation is issued, the thread is guaranteed not to execute
- * any userspace instructions until the thread is resumed.
+ * A stoppable section is a section of code where if the thread can
+ * be stoped. In other words, if a STOP operation is issued, the thread
+ * is guaranteed not to execute any userspace instructions until the
+ * thread is resumed.
  *
  * Having stoppable sections is better than having stopping points, since
  * a thread can be stopped even when it is blocked indefinitely in a system
  * call (whereas it would not reach any stopping point).
+ *
  */
 void udebug_stoppable_begin(void)
 {
-	int nsc;
-	call_t *db_call, *go_call;
-
 	ASSERT(THREAD);
 	ASSERT(TASK);
-
+	
 	mutex_lock(&TASK->udebug.lock);
-
-	nsc = --TASK->udebug.not_stoppable_count;
-
+	
+	int nsc = --TASK->udebug.not_stoppable_count;
+	
 	/* Lock order OK, THREAD->udebug.lock is after TASK->udebug.lock */
 	mutex_lock(&THREAD->udebug.lock);
 	ASSERT(THREAD->udebug.stoppable == false);
 	THREAD->udebug.stoppable = true;
-
-	if (TASK->udebug.dt_state == UDEBUG_TS_BEGINNING && nsc == 0) {
+	
+	if ((TASK->udebug.dt_state == UDEBUG_TS_BEGINNING) && (nsc == 0)) {
 		/*
 		 * This was the last non-stoppable thread. Reply to
 		 * DEBUG_BEGIN call.
+		 *
 		 */
-
-		db_call = TASK->udebug.begin_call;
+		
+		call_t *db_call = TASK->udebug.begin_call;
 		ASSERT(db_call);
-
+		
 		TASK->udebug.dt_state = UDEBUG_TS_ACTIVE;
 		TASK->udebug.begin_call = NULL;
-
+		
 		IPC_SET_RETVAL(db_call->data, 0);
-		ipc_answer(&TASK->answerbox, db_call);		
-
+		ipc_answer(&TASK->answerbox, db_call);
 	} else if (TASK->udebug.dt_state == UDEBUG_TS_ACTIVE) {
 		/*
 		 * Active debugging session
 		 */
-
+		
 		if (THREAD->udebug.active == true &&
 		    THREAD->udebug.go == false) {
 			/*
 			 * Thread was requested to stop - answer go call
+			 *
 			 */
-
+			
 			/* Make sure nobody takes this call away from us */
-			go_call = THREAD->udebug.go_call;
+			call_t *go_call = THREAD->udebug.go_call;
 			THREAD->udebug.go_call = NULL;
 			ASSERT(go_call);
-
+			
 			IPC_SET_RETVAL(go_call->data, 0);
 			IPC_SET_ARG1(go_call->data, UDEBUG_EVENT_STOP);
-
+			
 			THREAD->udebug.cur_event = UDEBUG_EVENT_STOP;
-
-	    		ipc_answer(&TASK->answerbox, go_call);
+			ipc_answer(&TASK->answerbox, go_call);
 		}
 	}
-
+	
 	mutex_unlock(&THREAD->udebug.lock);
         mutex_unlock(&TASK->udebug.lock);
@@ -174,5 +173,7 @@
  *
  * This is the point where the thread will block if it is stopped.
- * (As, by definition, a stopped thread must not leave its stoppable section).
+ * (As, by definition, a stopped thread must not leave its stoppable
+ * section).
+ *
  */
 void udebug_stoppable_end(void)
@@ -181,11 +182,11 @@
 	mutex_lock(&TASK->udebug.lock);
 	mutex_lock(&THREAD->udebug.lock);
-
-	if (THREAD->udebug.active && THREAD->udebug.go == false) {
+	
+	if ((THREAD->udebug.active) && (THREAD->udebug.go == false)) {
 		mutex_unlock(&THREAD->udebug.lock);
 		mutex_unlock(&TASK->udebug.lock);
-
+		
 		udebug_wait_for_go(&THREAD->udebug.go_wq);
-
+		
 		goto restart;
 		/* Must try again - have to lose stoppability atomically. */
@@ -194,5 +195,5 @@
 		ASSERT(THREAD->udebug.stoppable == true);
 		THREAD->udebug.stoppable = false;
-
+		
 		mutex_unlock(&THREAD->udebug.lock);
 		mutex_unlock(&TASK->udebug.lock);
@@ -203,4 +204,5 @@
  *
  * This function is called from clock().
+ *
  */
 void udebug_before_thread_runs(void)
@@ -215,4 +217,5 @@
  * Must be called before and after servicing a system call. This generates
  * a SYSCALL_B or SYSCALL_E event, depending on the value of @a end_variant.
+ *
  */
 void udebug_syscall_event(unative_t a1, unative_t a2, unative_t a3,
@@ -220,12 +223,10 @@
     bool end_variant)
 {
-	call_t *call;
-	udebug_event_t etype;
-
-	etype = end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B;
-
+	udebug_event_t etype =
+	    end_variant ? UDEBUG_EVENT_SYSCALL_E : UDEBUG_EVENT_SYSCALL_B;
+	
 	mutex_lock(&TASK->udebug.lock);
 	mutex_lock(&THREAD->udebug.lock);
-
+	
 	/* Must only generate events when in debugging session and is go. */
 	if (THREAD->udebug.active != true || THREAD->udebug.go == false ||
@@ -235,14 +236,14 @@
 		return;
 	}
-
+	
 	/* Fill in the GO response. */
-	call = THREAD->udebug.go_call;
+	call_t *call = THREAD->udebug.go_call;
 	THREAD->udebug.go_call = NULL;
-
+	
 	IPC_SET_RETVAL(call->data, 0);
 	IPC_SET_ARG1(call->data, etype);
 	IPC_SET_ARG2(call->data, id);
 	IPC_SET_ARG3(call->data, rc);
-
+	
 	THREAD->udebug.syscall_args[0] = a1;
 	THREAD->udebug.syscall_args[1] = a2;
@@ -251,18 +252,19 @@
 	THREAD->udebug.syscall_args[4] = a5;
 	THREAD->udebug.syscall_args[5] = a6;
-
+	
 	/*
 	 * Make sure udebug.go is false when going to sleep
 	 * in case we get woken up by DEBUG_END. (At which
 	 * point it must be back to the initial true value).
+	 *
 	 */
 	THREAD->udebug.go = false;
 	THREAD->udebug.cur_event = etype;
-
+	
 	ipc_answer(&TASK->answerbox, call);
-
+	
 	mutex_unlock(&THREAD->udebug.lock);
 	mutex_unlock(&TASK->udebug.lock);
-
+	
 	udebug_wait_for_go(&THREAD->udebug.go_wq);
 }
@@ -280,49 +282,52 @@
  * and get a THREAD_B event for them.
  *
- * @param t	Structure of the thread being created. Not locked, as the
- *		thread is not executing yet.
- * @param ta	Task to which the thread should be attached.
- */
-void udebug_thread_b_event_attach(struct thread *t, struct task *ta)
-{
-	call_t *call;
-
+ * @param thread Structure of the thread being created. Not locked, as the
+ *               thread is not executing yet.
+ * @param task   Task to which the thread should be attached.
+ *
+ */
+void udebug_thread_b_event_attach(struct thread *thread, struct task *task)
+{
 	mutex_lock(&TASK->udebug.lock);
 	mutex_lock(&THREAD->udebug.lock);
-
-	thread_attach(t, ta);
-
+	
+	thread_attach(thread, task);
+	
 	LOG("Check state");
-
+	
 	/* Must only generate events when in debugging session */
 	if (THREAD->udebug.active != true) {
 		LOG("udebug.active: %s, udebug.go: %s",
-			THREAD->udebug.active ? "Yes(+)" : "No",
-			THREAD->udebug.go ? "Yes(-)" : "No");
+		    THREAD->udebug.active ? "Yes(+)" : "No",
+		    THREAD->udebug.go ? "Yes(-)" : "No");
+		
 		mutex_unlock(&THREAD->udebug.lock);
 		mutex_unlock(&TASK->udebug.lock);
 		return;
 	}
-
+	
 	LOG("Trigger event");
-	call = THREAD->udebug.go_call;
+	
+	call_t *call = THREAD->udebug.go_call;
+	
 	THREAD->udebug.go_call = NULL;
 	IPC_SET_RETVAL(call->data, 0);
 	IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_B);
-	IPC_SET_ARG2(call->data, (unative_t)t);
-
+	IPC_SET_ARG2(call->data, (unative_t) thread);
+	
 	/*
 	 * Make sure udebug.go is false when going to sleep
 	 * in case we get woken up by DEBUG_END. (At which
 	 * point it must be back to the initial true value).
+	 *
 	 */
 	THREAD->udebug.go = false;
 	THREAD->udebug.cur_event = UDEBUG_EVENT_THREAD_B;
-
+	
 	ipc_answer(&TASK->answerbox, call);
-
+	
 	mutex_unlock(&THREAD->udebug.lock);
 	mutex_unlock(&TASK->udebug.lock);
-
+	
 	LOG("Wait for Go");
 	udebug_wait_for_go(&THREAD->udebug.go_wq);
@@ -333,128 +338,125 @@
  * Must be called when the current thread is terminating.
  * Generates a THREAD_E event.
+ *
  */
 void udebug_thread_e_event(void)
 {
-	call_t *call;
-
 	mutex_lock(&TASK->udebug.lock);
 	mutex_lock(&THREAD->udebug.lock);
-
+	
 	LOG("Check state");
-
+	
 	/* Must only generate events when in debugging session. */
 	if (THREAD->udebug.active != true) {
 		LOG("udebug.active: %s, udebug.go: %s",
-			THREAD->udebug.active ? "Yes" : "No",
-			THREAD->udebug.go ? "Yes" : "No");
+		    THREAD->udebug.active ? "Yes" : "No",
+		    THREAD->udebug.go ? "Yes" : "No");
+		
 		mutex_unlock(&THREAD->udebug.lock);
 		mutex_unlock(&TASK->udebug.lock);
 		return;
 	}
-
+	
 	LOG("Trigger event");
-	call = THREAD->udebug.go_call;
+	
+	call_t *call = THREAD->udebug.go_call;
+	
 	THREAD->udebug.go_call = NULL;
 	IPC_SET_RETVAL(call->data, 0);
 	IPC_SET_ARG1(call->data, UDEBUG_EVENT_THREAD_E);
-
+	
 	/* Prevent any further debug activity in thread. */
 	THREAD->udebug.active = false;
-	THREAD->udebug.cur_event = 0;		/* none */
-	THREAD->udebug.go = false;	/* set to initial value */
-
+	THREAD->udebug.cur_event = 0;   /* None */
+	THREAD->udebug.go = false;      /* Set to initial value */
+	
 	ipc_answer(&TASK->answerbox, call);
-
+	
 	mutex_unlock(&THREAD->udebug.lock);
 	mutex_unlock(&TASK->udebug.lock);
-
-	/* 
+	
+	/*
 	 * This event does not sleep - debugging has finished
 	 * in this thread.
+	 *
 	 */
 }
 
-/**
- * Terminate task debugging session.
- *
- * Gracefully terminates the debugging session for a task. If the debugger
+/** Terminate task debugging session.
+ *
+ * Gracefully terminate the debugging session for a task. If the debugger
  * is still waiting for events on some threads, it will receive a
  * FINISHED event for each of them.
  *
- * @param ta	Task structure. ta->udebug.lock must be already locked.
- * @return	Zero on success or negative error code.
- */
-int udebug_task_cleanup(struct task *ta)
-{
-	thread_t *t;
+ * @param task Task structure. ta->udebug.lock must be already locked.
+ *
+ * @return Zero on success or negative error code.
+ *
+ */
+int udebug_task_cleanup(struct task *task)
+{
+	if ((task->udebug.dt_state != UDEBUG_TS_BEGINNING) &&
+	    (task->udebug.dt_state != UDEBUG_TS_ACTIVE)) {
+		return EINVAL;
+	}
+	
+	LOG("Task %" PRIu64, task->taskid);
+	
+	/* Finish debugging of all userspace threads */
 	link_t *cur;
-	int flags;
-	ipl_t ipl;
-
-	if (ta->udebug.dt_state != UDEBUG_TS_BEGINNING &&
-	    ta->udebug.dt_state != UDEBUG_TS_ACTIVE) {
-		return EINVAL;
-	}
-
-	LOG("Task %" PRIu64, ta->taskid);
-
-	/* Finish debugging of all userspace threads */
-	for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
-		t = list_get_instance(cur, thread_t, th_link);
-
-		mutex_lock(&t->udebug.lock);
-
-		ipl = interrupts_disable();
-		spinlock_lock(&t->lock);
-
-		flags = t->flags;
-
-		spinlock_unlock(&t->lock);
-		interrupts_restore(ipl);
-
+	for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
+		thread_t *thread = list_get_instance(cur, thread_t, th_link);
+		
+		mutex_lock(&thread->udebug.lock);
+		unsigned int flags = thread->flags;
+		
 		/* Only process userspace threads. */
 		if ((flags & THREAD_FLAG_USPACE) != 0) {
 			/* Prevent any further debug activity in thread. */
-			t->udebug.active = false;
-			t->udebug.cur_event = 0;	/* none */
-
+			thread->udebug.active = false;
+			thread->udebug.cur_event = 0;   /* None */
+			
 			/* Is the thread still go? */
-			if (t->udebug.go == true) {
+			if (thread->udebug.go == true) {
 				/*
-				* Yes, so clear go. As active == false,
+				 * Yes, so clear go. As active == false,
 				 * this doesn't affect anything.
+				 (
 				 */
-				t->udebug.go = false;	
-
+				thread->udebug.go = false;
+				
 				/* Answer GO call */
 				LOG("Answer GO call with EVENT_FINISHED.");
-				IPC_SET_RETVAL(t->udebug.go_call->data, 0);
-				IPC_SET_ARG1(t->udebug.go_call->data,
+				
+				IPC_SET_RETVAL(thread->udebug.go_call->data, 0);
+				IPC_SET_ARG1(thread->udebug.go_call->data,
 				    UDEBUG_EVENT_FINISHED);
-
-				ipc_answer(&ta->answerbox, t->udebug.go_call);
-				t->udebug.go_call = NULL;
+				
+				ipc_answer(&task->answerbox, thread->udebug.go_call);
+				thread->udebug.go_call = NULL;
 			} else {
 				/*
 				 * Debug_stop is already at initial value.
 				 * Yet this means the thread needs waking up.
+				 *
 				 */
-
+				
 				/*
-				 * t's lock must not be held when calling
+				 * thread's lock must not be held when calling
 				 * waitq_wakeup.
+				 *
 				 */
-				waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST);
+				waitq_wakeup(&thread->udebug.go_wq, WAKEUP_FIRST);
 			}
-			mutex_unlock(&t->udebug.lock);
-			condvar_broadcast(&t->udebug.active_cv);
-		} else {
-			mutex_unlock(&t->udebug.lock);
-		}
-	}
-
-	ta->udebug.dt_state = UDEBUG_TS_INACTIVE;
-	ta->udebug.debugger = NULL;
-
+			
+			mutex_unlock(&thread->udebug.lock);
+			condvar_broadcast(&thread->udebug.active_cv);
+		} else
+			mutex_unlock(&thread->udebug.lock);
+	}
+	
+	task->udebug.dt_state = UDEBUG_TS_INACTIVE;
+	task->udebug.debugger = NULL;
+	
 	return 0;
 }
@@ -466,9 +468,10 @@
  * a chance to examine the faulting thead/task. When the debugging session
  * is over, this function returns (so that thread/task cleanup can continue).
+ *
  */
 void udebug_thread_fault(void)
 {
 	udebug_stoppable_begin();
-
+	
 	/* Wait until a debugger attends to us. */
 	mutex_lock(&THREAD->udebug.lock);
@@ -476,5 +479,5 @@
 		condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock);
 	mutex_unlock(&THREAD->udebug.lock);
-
+	
 	/* Make sure the debugging session is over before proceeding. */
 	mutex_lock(&THREAD->udebug.lock);
@@ -482,5 +485,5 @@
 		condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock);
 	mutex_unlock(&THREAD->udebug.lock);
-
+	
 	udebug_stoppable_end();
 }
Index: kernel/generic/src/udebug/udebug_ops.c
===================================================================
--- kernel/generic/src/udebug/udebug_ops.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ kernel/generic/src/udebug/udebug_ops.c	(revision b7398c034409791e32e89439b6f1e7e895d99e10)
@@ -33,5 +33,5 @@
 /**
  * @file
- * @brief	Udebug operations.
+ * @brief Udebug operations.
  *
  * Udebug operations on tasks and threads are implemented here. The
@@ -39,5 +39,5 @@
  * when servicing udebug IPC messages.
  */
- 
+
 #include <debug.h>
 #include <proc/task.h>
@@ -53,6 +53,5 @@
 #include <memstr.h>
 
-/**
- * Prepare a thread for a debugging operation.
+/** Prepare a thread for a debugging operation.
  *
  * Simply put, return thread t with t->udebug.lock held,
@@ -73,89 +72,84 @@
  * the t->lock spinlock to the t->udebug.lock mutex.
  *
- * @param t		Pointer, need not at all be valid.
- * @param being_go	Required thread state.
+ * @param thread   Pointer, need not at all be valid.
+ * @param being_go Required thread state.
  *
  * Returns EOK if all went well, or an error code otherwise.
- */
-static int _thread_op_begin(thread_t *t, bool being_go)
-{
-	ipl_t ipl;
-
-	mutex_lock(&TASK->udebug.lock);
-
+ *
+ */
+static int _thread_op_begin(thread_t *thread, bool being_go)
+{
+	mutex_lock(&TASK->udebug.lock);
+	
 	/* thread_exists() must be called with threads_lock held */
-	ipl = interrupts_disable();
-	spinlock_lock(&threads_lock);
-
-	if (!thread_exists(t)) {
-		spinlock_unlock(&threads_lock);
-		interrupts_restore(ipl);
+	irq_spinlock_lock(&threads_lock, true);
+	
+	if (!thread_exists(thread)) {
+		irq_spinlock_unlock(&threads_lock, true);
 		mutex_unlock(&TASK->udebug.lock);
 		return ENOENT;
 	}
-
-	/* t->lock is enough to ensure the thread's existence */
-	spinlock_lock(&t->lock);
-	spinlock_unlock(&threads_lock);
-
-	/* Verify that 't' is a userspace thread. */
-	if ((t->flags & THREAD_FLAG_USPACE) == 0) {
+	
+	/* thread->lock is enough to ensure the thread's existence */
+	irq_spinlock_exchange(&threads_lock, &thread->lock);
+	
+	/* Verify that 'thread' is a userspace thread. */
+	if ((thread->flags & THREAD_FLAG_USPACE) == 0) {
 		/* It's not, deny its existence */
-		spinlock_unlock(&t->lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&thread->lock, true);
 		mutex_unlock(&TASK->udebug.lock);
 		return ENOENT;
 	}
-
+	
 	/* Verify debugging state. */
-	if (t->udebug.active != true) {
+	if (thread->udebug.active != true) {
 		/* Not in debugging session or undesired GO state */
-		spinlock_unlock(&t->lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&thread->lock, true);
 		mutex_unlock(&TASK->udebug.lock);
 		return ENOENT;
 	}
-
+	
 	/*
 	 * Since the thread has active == true, TASK->udebug.lock
 	 * is enough to ensure its existence and that active remains
 	 * true.
+	 *
 	 */
-	spinlock_unlock(&t->lock);
-	interrupts_restore(ipl);
-
+	irq_spinlock_unlock(&thread->lock, true);
+	
 	/* Only mutex TASK->udebug.lock left. */
 	
 	/* Now verify that the thread belongs to the current task. */
-	if (t->task != TASK) {
+	if (thread->task != TASK) {
 		/* No such thread belonging this task*/
 		mutex_unlock(&TASK->udebug.lock);
 		return ENOENT;
 	}
-
+	
 	/*
 	 * Now we need to grab the thread's debug lock for synchronization
 	 * of the threads stoppability/stop state.
+	 *
 	 */
-	mutex_lock(&t->udebug.lock);
-
+	mutex_lock(&thread->udebug.lock);
+	
 	/* The big task mutex is no longer needed. */
 	mutex_unlock(&TASK->udebug.lock);
-
-	if (t->udebug.go != being_go) {
+	
+	if (thread->udebug.go != being_go) {
 		/* Not in debugging session or undesired GO state. */
-		mutex_unlock(&t->udebug.lock);
+		mutex_unlock(&thread->udebug.lock);
 		return EINVAL;
 	}
-
-	/* Only t->udebug.lock left. */
-
-	return EOK;	/* All went well. */
+	
+	/* Only thread->udebug.lock left. */
+	
+	return EOK;  /* All went well. */
 }
 
 /** End debugging operation on a thread. */
-static void _thread_op_end(thread_t *t)
-{
-	mutex_unlock(&t->udebug.lock);
+static void _thread_op_end(thread_t *thread)
+{
+	mutex_unlock(&thread->udebug.lock);
 }
 
@@ -171,49 +165,48 @@
  * all the threads become stoppable (i.e. they can be considered stopped).
  *
- * @param call	The BEGIN call we are servicing.
- * @return 	0 (OK, but not done yet), 1 (done) or negative error code.
+ * @param call The BEGIN call we are servicing.
+ *
+ * @return 0 (OK, but not done yet), 1 (done) or negative error code.
+ *
  */
 int udebug_begin(call_t *call)
 {
-	int reply;
-
-	thread_t *t;
-	link_t *cur;
-
-	LOG("Debugging task %llu", TASK->taskid);
-	mutex_lock(&TASK->udebug.lock);
-
+	LOG("Debugging task %" PRIu64, TASK->taskid);
+	
+	mutex_lock(&TASK->udebug.lock);
+	
 	if (TASK->udebug.dt_state != UDEBUG_TS_INACTIVE) {
 		mutex_unlock(&TASK->udebug.lock);
 		return EBUSY;
 	}
-
+	
 	TASK->udebug.dt_state = UDEBUG_TS_BEGINNING;
 	TASK->udebug.begin_call = call;
 	TASK->udebug.debugger = call->sender;
-
+	
+	int reply;
+	
 	if (TASK->udebug.not_stoppable_count == 0) {
 		TASK->udebug.dt_state = UDEBUG_TS_ACTIVE;
 		TASK->udebug.begin_call = NULL;
-		reply = 1; /* immediate reply */
-	} else {
-		reply = 0; /* no reply */
-	}
+		reply = 1;  /* immediate reply */
+	} else
+		reply = 0;  /* no reply */
 	
 	/* Set udebug.active on all of the task's userspace threads. */
-
+	
+	link_t *cur;
 	for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
-		t = list_get_instance(cur, thread_t, th_link);
-
-		mutex_lock(&t->udebug.lock);
-		if ((t->flags & THREAD_FLAG_USPACE) != 0) {
-			t->udebug.active = true;
-			mutex_unlock(&t->udebug.lock);
-			condvar_broadcast(&t->udebug.active_cv);
-		} else {
-			mutex_unlock(&t->udebug.lock);
-		}
-	}
-
+		thread_t *thread = list_get_instance(cur, thread_t, th_link);
+		
+		mutex_lock(&thread->udebug.lock);
+		if ((thread->flags & THREAD_FLAG_USPACE) != 0) {
+			thread->udebug.active = true;
+			mutex_unlock(&thread->udebug.lock);
+			condvar_broadcast(&thread->udebug.active_cv);
+		} else
+			mutex_unlock(&thread->udebug.lock);
+	}
+	
 	mutex_unlock(&TASK->udebug.lock);
 	return reply;
@@ -223,16 +216,16 @@
  *
  * Closes the debugging session for the current task.
+ *
  * @return Zero on success or negative error code.
+ *
  */
 int udebug_end(void)
 {
-	int rc;
-
 	LOG("Task %" PRIu64, TASK->taskid);
-
-	mutex_lock(&TASK->udebug.lock);
-	rc = udebug_task_cleanup(TASK);
-	mutex_unlock(&TASK->udebug.lock);
-
+	
+	mutex_lock(&TASK->udebug.lock);
+	int rc = udebug_task_cleanup(TASK);
+	mutex_unlock(&TASK->udebug.lock);
+	
 	return rc;
 }
@@ -242,21 +235,23 @@
  * Sets the event mask that determines which events are enabled.
  *
- * @param mask	Or combination of events that should be enabled.
- * @return	Zero on success or negative error code.
+ * @param mask Or combination of events that should be enabled.
+ *
+ * @return Zero on success or negative error code.
+ *
  */
 int udebug_set_evmask(udebug_evmask_t mask)
 {
 	LOG("mask = 0x%x", mask);
-
-	mutex_lock(&TASK->udebug.lock);
-
+	
+	mutex_lock(&TASK->udebug.lock);
+	
 	if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
 		mutex_unlock(&TASK->udebug.lock);
 		return EINVAL;
 	}
-
+	
 	TASK->udebug.evmask = mask;
 	mutex_unlock(&TASK->udebug.lock);
-
+	
 	return 0;
 }
@@ -268,28 +263,27 @@
  * a debugging event or STOP occurs, at which point the thread loses GO.
  *
- * @param t	The thread to operate on (unlocked and need not be valid).
- * @param call	The GO call that we are servicing.
- */
-int udebug_go(thread_t *t, call_t *call)
-{
-	int rc;
-
-	/* On success, this will lock t->udebug.lock. */
-	rc = _thread_op_begin(t, false);
-	if (rc != EOK) {
+ * @param thread The thread to operate on (unlocked and need not be valid).
+ * @param call   The GO call that we are servicing.
+ *
+ */
+int udebug_go(thread_t *thread, call_t *call)
+{
+	/* On success, this will lock thread->udebug.lock. */
+	int rc = _thread_op_begin(thread, false);
+	if (rc != EOK)
 		return rc;
-	}
-
-	t->udebug.go_call = call;
-	t->udebug.go = true;
-	t->udebug.cur_event = 0;	/* none */
-
+	
+	thread->udebug.go_call = call;
+	thread->udebug.go = true;
+	thread->udebug.cur_event = 0;  /* none */
+	
 	/*
-	 * Neither t's lock nor threads_lock may be held during wakeup.
+	 * Neither thread's lock nor threads_lock may be held during wakeup.
+	 *
 	 */
-	waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST);
-
-	_thread_op_end(t);
-
+	waitq_wakeup(&thread->udebug.go_wq, WAKEUP_FIRST);
+	
+	_thread_op_end(thread);
+	
 	return 0;
 }
@@ -300,50 +294,50 @@
  * can be considered stopped).
  *
- * @param t	The thread to operate on (unlocked and need not be valid).
- * @param call	The GO call that we are servicing.
- */
-int udebug_stop(thread_t *t, call_t *call)
-{
-	int rc;
-
+ * @param thread The thread to operate on (unlocked and need not be valid).
+ * @param call   The GO call that we are servicing.
+ *
+ */
+int udebug_stop(thread_t *thread, call_t *call)
+{
 	LOG("udebug_stop()");
-
+	
 	/*
-	 * On success, this will lock t->udebug.lock. Note that this makes sure
-	 * the thread is not stopped.
+	 * On success, this will lock thread->udebug.lock. Note that this
+	 * makes sure the thread is not stopped.
+	 *
 	 */
-	rc = _thread_op_begin(t, true);
-	if (rc != EOK) {
+	int rc = _thread_op_begin(thread, true);
+	if (rc != EOK)
 		return rc;
-	}
-
+	
 	/* Take GO away from the thread. */
-	t->udebug.go = false;
-
-	if (t->udebug.stoppable != true) {
+	thread->udebug.go = false;
+	
+	if (thread->udebug.stoppable != true) {
 		/* Answer will be sent when the thread becomes stoppable. */
-		_thread_op_end(t);
+		_thread_op_end(thread);
 		return 0;
 	}
-
+	
 	/*
 	 * Answer GO call.
+	 *
 	 */
-
+	
 	/* Make sure nobody takes this call away from us. */
-	call = t->udebug.go_call;
-	t->udebug.go_call = NULL;
-
+	call = thread->udebug.go_call;
+	thread->udebug.go_call = NULL;
+	
 	IPC_SET_RETVAL(call->data, 0);
 	IPC_SET_ARG1(call->data, UDEBUG_EVENT_STOP);
-
+	
 	THREAD->udebug.cur_event = UDEBUG_EVENT_STOP;
-
-	_thread_op_end(t);
-
+	
+	_thread_op_end(thread);
+	
 	mutex_lock(&TASK->udebug.lock);
 	ipc_answer(&TASK->answerbox, call);
 	mutex_unlock(&TASK->udebug.lock);
-
+	
 	return 0;
 }
@@ -365,29 +359,20 @@
  * a maximum size for the userspace buffer.
  *
- * @param buffer	The buffer for storing thread hashes.
- * @param buf_size	Buffer size in bytes.
- * @param stored	The actual number of bytes copied will be stored here.
- * @param needed	Total number of hashes that could have been saved.
+ * @param buffer   The buffer for storing thread hashes.
+ * @param buf_size Buffer size in bytes.
+ * @param stored   The actual number of bytes copied will be stored here.
+ * @param needed   Total number of hashes that could have been saved.
+ *
  */
 int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored,
     size_t *needed)
 {
-	thread_t *t;
-	link_t *cur;
-	unative_t tid;
-	size_t copied_ids;
-	size_t extra_ids;
-	ipl_t ipl;
-	unative_t *id_buffer;
-	int flags;
-	size_t max_ids;
-
 	LOG("udebug_thread_read()");
-
+	
 	/* Allocate a buffer to hold thread IDs */
-	id_buffer = malloc(buf_size + 1, 0);
-
-	mutex_lock(&TASK->udebug.lock);
-
+	unative_t *id_buffer = malloc(buf_size + 1, 0);
+	
+	mutex_lock(&TASK->udebug.lock);
+	
 	/* Verify task state */
 	if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
@@ -395,43 +380,41 @@
 		return EINVAL;
 	}
-
-	ipl = interrupts_disable();
-	spinlock_lock(&TASK->lock);
+	
+	irq_spinlock_lock(&TASK->lock, true);
+	
 	/* Copy down the thread IDs */
-
-	max_ids = buf_size / sizeof(unative_t);
-	copied_ids = 0;
-	extra_ids = 0;
-
+	
+	size_t max_ids = buf_size / sizeof(unative_t);
+	size_t copied_ids = 0;
+	size_t extra_ids = 0;
+	
 	/* FIXME: make sure the thread isn't past debug shutdown... */
+	link_t *cur;
 	for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
-		t = list_get_instance(cur, thread_t, th_link);
-
-		spinlock_lock(&t->lock);
-		flags = t->flags;
-		spinlock_unlock(&t->lock);
-
+		thread_t *thread = list_get_instance(cur, thread_t, th_link);
+		
+		irq_spinlock_lock(&thread->lock, false);
+		int flags = thread->flags;
+		irq_spinlock_unlock(&thread->lock, false);
+		
 		/* Not interested in kernel threads. */
 		if ((flags & THREAD_FLAG_USPACE) == 0)
 			continue;
-
+		
 		if (copied_ids < max_ids) {
 			/* Using thread struct pointer as identification hash */
-			tid = (unative_t) t;
-			id_buffer[copied_ids++] = tid;
-		} else {
+			id_buffer[copied_ids++] = (unative_t) thread;
+		} else
 			extra_ids++;
-		}
-	}
-
-	spinlock_unlock(&TASK->lock);
-	interrupts_restore(ipl);
-
-	mutex_unlock(&TASK->udebug.lock);
-
+	}
+	
+	irq_spinlock_unlock(&TASK->lock, true);
+	
+	mutex_unlock(&TASK->udebug.lock);
+	
 	*buffer = id_buffer;
 	*stored = copied_ids * sizeof(unative_t);
 	*needed = (copied_ids + extra_ids) * sizeof(unative_t);
-
+	
 	return 0;
 }
@@ -442,19 +425,19 @@
  * Also returns the size of the data.
  *
- * @param data		Place to store pointer to newly allocated block.
- * @param data_size	Place to store size of the data.
- *
- * @returns		EOK.
+ * @param data      Place to store pointer to newly allocated block.
+ * @param data_size Place to store size of the data.
+ *
+ * @returns EOK.
+ *
  */
 int udebug_name_read(char **data, size_t *data_size)
 {
-	size_t name_size;
-
-	name_size = str_size(TASK->name) + 1;
+	size_t name_size = str_size(TASK->name) + 1;
+	
 	*data = malloc(name_size, 0);
 	*data_size = name_size;
-
+	
 	memcpy(*data, TASK->name, name_size);
-
+	
 	return 0;
 }
@@ -470,35 +453,33 @@
  * this function will fail with an EINVAL error code.
  *
- * @param t		Thread where call arguments are to be read.
- * @param buffer	Place to store pointer to new buffer.
- * @return		EOK on success, ENOENT if @a t is invalid, EINVAL
- *			if thread state is not valid for this operation.
- */
-int udebug_args_read(thread_t *t, void **buffer)
-{
-	int rc;
-	unative_t *arg_buffer;
-
+ * @param thread Thread where call arguments are to be read.
+ * @param buffer Place to store pointer to new buffer.
+ *
+ * @return EOK on success, ENOENT if @a t is invalid, EINVAL
+ *         if thread state is not valid for this operation.
+ *
+ */
+int udebug_args_read(thread_t *thread, void **buffer)
+{
 	/* Prepare a buffer to hold the arguments. */
-	arg_buffer = malloc(6 * sizeof(unative_t), 0);
-
+	unative_t *arg_buffer = malloc(6 * sizeof(unative_t), 0);
+	
 	/* On success, this will lock t->udebug.lock. */
-	rc = _thread_op_begin(t, false);
-	if (rc != EOK) {
+	int rc = _thread_op_begin(thread, false);
+	if (rc != EOK)
 		return rc;
-	}
-
+	
 	/* Additionally we need to verify that we are inside a syscall. */
-	if (t->udebug.cur_event != UDEBUG_EVENT_SYSCALL_B &&
-	    t->udebug.cur_event != UDEBUG_EVENT_SYSCALL_E) {
-		_thread_op_end(t);
+	if ((thread->udebug.cur_event != UDEBUG_EVENT_SYSCALL_B) &&
+	    (thread->udebug.cur_event != UDEBUG_EVENT_SYSCALL_E)) {
+		_thread_op_end(thread);
 		return EINVAL;
 	}
-
+	
 	/* Copy to a local buffer before releasing the lock. */
-	memcpy(arg_buffer, t->udebug.syscall_args, 6 * sizeof(unative_t));
-
-	_thread_op_end(t);
-
+	memcpy(arg_buffer, thread->udebug.syscall_args, 6 * sizeof(unative_t));
+	
+	_thread_op_end(thread);
+	
 	*buffer = arg_buffer;
 	return 0;
@@ -514,35 +495,33 @@
  * call (as opposed to an exception). This is an implementation limit.
  *
- * @param t		Thread whose state is to be read.
- * @param buffer	Place to store pointer to new buffer.
- * @return		EOK on success, ENOENT if @a t is invalid, EINVAL
- *			if thread is not in valid state, EBUSY if istate
- *			is not available.
- */
-int udebug_regs_read(thread_t *t, void **buffer)
-{
-	istate_t *state, *state_buf;
-	int rc;
-
+ * @param thread Thread whose state is to be read.
+ * @param buffer Place to store pointer to new buffer.
+ *
+ * @return EOK on success, ENOENT if @a t is invalid, EINVAL
+ *         if thread is not in valid state, EBUSY if istate
+ *         is not available.
+ *
+ */
+int udebug_regs_read(thread_t *thread, void **buffer)
+{
 	/* Prepare a buffer to hold the data. */
-	state_buf = malloc(sizeof(istate_t), 0);
-
+	istate_t *state_buf = malloc(sizeof(istate_t), 0);
+	
 	/* On success, this will lock t->udebug.lock */
-	rc = _thread_op_begin(t, false);
-	if (rc != EOK) {
+	int rc = _thread_op_begin(thread, false);
+	if (rc != EOK)
 		return rc;
-	}
-
-	state = t->udebug.uspace_state;
+	
+	istate_t *state = thread->udebug.uspace_state;
 	if (state == NULL) {
-		_thread_op_end(t);
+		_thread_op_end(thread);
 		return EBUSY;
 	}
-
+	
 	/* Copy to the allocated buffer */
 	memcpy(state_buf, state, sizeof(istate_t));
-
-	_thread_op_end(t);
-
+	
+	_thread_op_end(thread);
+	
 	*buffer = (void *) state_buf;
 	return 0;
@@ -555,30 +534,32 @@
  * and a pointer to it is written into @a buffer.
  *
- * @param uspace_addr	Address from where to start reading.
- * @param n		Number of bytes to read.
- * @param buffer	For storing a pointer to the allocated buffer.
+ * @param uspace_addr Address from where to start reading.
+ * @param n           Number of bytes to read.
+ * @param buffer      For storing a pointer to the allocated buffer.
+ *
  */
 int udebug_mem_read(unative_t uspace_addr, size_t n, void **buffer)
 {
-	void *data_buffer;
-	int rc;
-
 	/* Verify task state */
 	mutex_lock(&TASK->udebug.lock);
-
+	
 	if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
 		mutex_unlock(&TASK->udebug.lock);
 		return EBUSY;
 	}
-
-	data_buffer = malloc(n, 0);
-
-	/* NOTE: this is not strictly from a syscall... but that shouldn't
-	 * be a problem */
-	rc = copy_from_uspace(data_buffer, (void *)uspace_addr, n);
-	mutex_unlock(&TASK->udebug.lock);
-
-	if (rc != 0) return rc;
-
+	
+	void *data_buffer = malloc(n, 0);
+	
+	/*
+	 * NOTE: this is not strictly from a syscall... but that shouldn't
+	 * be a problem
+	 *
+	 */
+	int rc = copy_from_uspace(data_buffer, (void *) uspace_addr, n);
+	mutex_unlock(&TASK->udebug.lock);
+	
+	if (rc != 0)
+		return rc;
+	
 	*buffer = data_buffer;
 	return 0;
