Index: kernel/generic/src/udebug/udebug.c
===================================================================
--- kernel/generic/src/udebug/udebug.c	(revision a074b4f9d5cf65707ae3aaffaf4564453f710efd)
+++ kernel/generic/src/udebug/udebug.c	(revision aa8267cbfa3253527bca9386e27cbac1706afec8)
@@ -460,4 +460,29 @@
 }
 
+/** Wait for debugger to handle a fault in this thread.
+ *
+ * When a thread faults and someone is subscribed to the FAULT kernel event,
+ * this function is called to wait for a debugging session to give userspace
+ * 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);
+	while (!THREAD->udebug.active)
+		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);
+	while (THREAD->udebug.active)
+		condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock);
+	mutex_unlock(&THREAD->udebug.lock);
+
+	udebug_stoppable_end();
+}
 
 /** @}
