Index: kernel/generic/src/interrupt/interrupt.c
===================================================================
--- kernel/generic/src/interrupt/interrupt.c	(revision cf39b2e03efcad323862967fb61a984f98b229a6)
+++ kernel/generic/src/interrupt/interrupt.c	(revision 89d3946f2bd69be149361dc978ecd1d251f48c76)
@@ -54,4 +54,5 @@
 #include <proc/thread.h>
 #include <arch/cycle.h>
+#include <arch/stack.h>
 #include <str.h>
 #include <trace.h>
@@ -222,8 +223,7 @@
 	/*
 	 * The istate structure should be right at the bottom of the kernel
-	 * stack.
+	 * memory stack.
 	 */
-	return (istate_t *) ((uint8_t *)
-	    thread->kstack + STACK_SIZE - sizeof(istate_t));
+	return (istate_t *) &thread->kstack[MEM_STACK_SIZE - sizeof(istate_t)];
 }
 
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision cf39b2e03efcad323862967fb61a984f98b229a6)
+++ kernel/generic/src/main/kinit.c	(revision 89d3946f2bd69be149361dc978ecd1d251f48c76)
@@ -250,6 +250,14 @@
 				    CAP_IO_MANAGER | CAP_IRQ_REG);
 				
-				if (!ipc_phone_0)
+				if (!ipc_phone_0) {
 					ipc_phone_0 = &programs[i].task->answerbox;
+					/*
+					 * Hold the first task so that the
+					 * ipc_phone_0 remains a valid pointer
+					 * even if the first task exits for
+					 * whatever reason.
+					 */
+					task_hold(programs[i].task);
+				}
 			}
 			
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision cf39b2e03efcad323862967fb61a984f98b229a6)
+++ kernel/generic/src/proc/task.c	(revision 89d3946f2bd69be149361dc978ecd1d251f48c76)
@@ -125,4 +125,14 @@
 {
 	size_t tasks_left;
+
+	if (ipc_phone_0) {
+		task_t *task_0 = ipc_phone_0->task;
+		ipc_phone_0 = NULL;
+		/*
+		 * The first task is held by kinit(), we need to release it or
+		 * it will never finish cleanup.
+		 */
+		task_release(task_0);
+	}
 	
 	/* Repeat until there are any tasks except TASK */
