Index: uspace/lib/c/generic/assert.c
===================================================================
--- uspace/lib/c/generic/assert.c	(revision 1b3e8549153c45754eeae954067e77cd51aca026)
+++ uspace/lib/c/generic/assert.c	(revision 2bdf83130b54ce60b13639e8b922b22f02ed8cc7)
@@ -35,17 +35,42 @@
 #include <io/klog.h>
 #include <stdlib.h>
+#include <atomic.h>
 #include <stacktrace.h>
 
-void assert_abort(const char *cond, const char *file, unsigned int line)
+#define MSG_START	"Assertion failed ("
+#define MSG_FILE	") in file \""
+#define MSG_LINE	"\", line "
+#define MSG_END		".\n"
+
+static atomic_t failed_asserts;
+
+void assert_abort(const char *cond, const char *file, const char *line)
 {
-	printf("Assertion failed (%s) in file \"%s\", line %u.\n",
+	/*
+	 * Send the message safely to klog. Nested asserts should not occur.
+	 */
+	klog_write(MSG_START, str_size(MSG_START));
+	klog_write(cond, str_size(cond));
+	klog_write(MSG_FILE, str_size(MSG_FILE));
+	klog_write(file, str_size(file));
+	klog_write(MSG_LINE, str_size(MSG_LINE));
+	klog_write(line, str_size(line));
+	klog_write(MSG_END, str_size(MSG_END));
+
+	/*
+	 * Check if this is a nested or parallel assert.
+	 */
+	if (atomic_postinc(&failed_asserts))
+		abort();
+	
+	/*
+	 * Attempt to print the message to standard output and display
+	 * the stack trace. These operations can theoretically trigger nested
+	 * assertions.
+	 */
+	printf(MSG_START "%s" MSG_FILE "%s" MSG_LINE "%s" MSG_END,
 	    cond, file, line);
 	stacktrace_print();
-	abort();
-}
 
-void assert_static_abort(const char *msg)
-{
-	klog_write(msg, str_size(msg));
 	abort();
 }
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 1b3e8549153c45754eeae954067e77cd51aca026)
+++ uspace/lib/c/generic/malloc.c	(revision 2bdf83130b54ce60b13639e8b922b22f02ed8cc7)
@@ -188,4 +188,20 @@
 static futex_t malloc_futex = FUTEX_INITIALIZER;
 
+#ifndef NDEBUG
+
+#define malloc_assert(expr) \
+	do { \
+		if (!(expr)) {\
+			futex_up(&malloc_futex); \
+			assert_abort(#expr, __FILE__, STR2(__LINE__)); \
+		} \
+	} while (0)
+
+#else /* NDEBUG */
+
+#define malloc_assert(expr)
+
+#endif /* NDEBUG */
+
 /** Initialize a heap block
  *
@@ -228,10 +244,10 @@
 	heap_block_head_t *head = (heap_block_head_t *) addr;
 	
-	assert_static(head->magic == HEAP_BLOCK_HEAD_MAGIC);
+	malloc_assert(head->magic == HEAP_BLOCK_HEAD_MAGIC);
 	
 	heap_block_foot_t *foot = BLOCK_FOOT(head);
 	
-	assert_static(foot->magic == HEAP_BLOCK_FOOT_MAGIC);
-	assert_static(head->size == foot->size);
+	malloc_assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC);
+	malloc_assert(head->size == foot->size);
 }
 
@@ -247,9 +263,9 @@
 	heap_area_t *area = (heap_area_t *) addr;
 	
-	assert_static(area->magic == HEAP_AREA_MAGIC);
-	assert_static(addr == area->start);
-	assert_static(area->start < area->end);
-	assert_static(((uintptr_t) area->start % PAGE_SIZE) == 0);
-	assert_static(((uintptr_t) area->end % PAGE_SIZE) == 0);
+	malloc_assert(area->magic == HEAP_AREA_MAGIC);
+	malloc_assert(addr == area->start);
+	malloc_assert(area->start < area->end);
+	malloc_assert(((uintptr_t) area->start % PAGE_SIZE) == 0);
+	malloc_assert(((uintptr_t) area->end % PAGE_SIZE) == 0);
 }
 
@@ -382,5 +398,5 @@
 	
 	block_check((void *) last_head);
-	assert_static(last_head->area == area);
+	malloc_assert(last_head->area == area);
 	
 	if (last_head->free) {
@@ -395,5 +411,5 @@
 		
 		block_check((void *) first_head);
-		assert_static(first_head->area == area);
+		malloc_assert(first_head->area == area);
 		
 		size_t shrink_size = ALIGN_DOWN(last_head->size, PAGE_SIZE);
@@ -497,5 +513,5 @@
 static void split_mark(heap_block_head_t *cur, const size_t size)
 {
-	assert_static(cur->size >= size);
+	malloc_assert(cur->size >= size);
 	
 	/* See if we should split the block. */
@@ -533,6 +549,6 @@
 {
 	area_check((void *) area);
-	assert_static((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area));
-	assert_static((void *) first_block < area->end);
+	malloc_assert((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area));
+	malloc_assert((void *) first_block < area->end);
 	
 	for (heap_block_head_t *cur = first_block; (void *) cur < area->end;
@@ -661,5 +677,5 @@
 static void *malloc_internal(const size_t size, const size_t align)
 {
-	assert_static(first_heap_area != NULL);
+	malloc_assert(first_heap_area != NULL);
 	
 	if (align == 0)
@@ -786,11 +802,11 @@
 	
 	block_check(head);
-	assert_static(!head->free);
+	malloc_assert(!head->free);
 	
 	heap_area_t *area = head->area;
 	
 	area_check(area);
-	assert_static((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
-	assert_static((void *) head < area->end);
+	malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
+	malloc_assert((void *) head < area->end);
 	
 	void *ptr = NULL;
@@ -863,11 +879,11 @@
 	
 	block_check(head);
-	assert_static(!head->free);
+	malloc_assert(!head->free);
 	
 	heap_area_t *area = head->area;
 	
 	area_check(area);
-	assert_static((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
-	assert_static((void *) head < area->end);
+	malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
+	malloc_assert((void *) head < area->end);
 	
 	/* Mark the block itself as free. */
Index: uspace/lib/c/include/assert.h
===================================================================
--- uspace/lib/c/include/assert.h	(revision 1b3e8549153c45754eeae954067e77cd51aca026)
+++ uspace/lib/c/include/assert.h	(revision 2bdf83130b54ce60b13639e8b922b22f02ed8cc7)
@@ -47,4 +47,7 @@
  */
 
+#define STR(l)	#l
+#define STR2(l)	STR(l)
+
 #ifndef NDEBUG
 
@@ -52,12 +55,5 @@
 	do { \
 		if (!(expr)) \
-			assert_abort(#expr, __FILE__, __LINE__); \
-	} while (0)
-
-#define assert_static(expr) \
-	do { \
-		if (!(expr)) \
-			assert_static_abort("Assertion failed (" #expr \
-			    ") in file \"" __FILE__ "\".\n"); \
+			assert_abort(#expr, __FILE__, STR2(__LINE__)); \
 	} while (0)
 
@@ -65,11 +61,9 @@
 
 #define assert(expr)
-#define assert_static(expr)
 
 #endif /* NDEBUG */
 
-extern void assert_abort(const char *, const char *, unsigned int)
+extern void assert_abort(const char *, const char *, const char *)
     __attribute__((noreturn));
-extern void assert_static_abort(const char *);
 
 
