Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision eeb2bde2cd490c6feb4ee861d340112bfcb495af)
+++ kernel/generic/src/mm/as.c	(revision 6e71a9d850aa09eec22b6f079fae6deae5f8cd51)
@@ -147,6 +147,10 @@
 	AS_KERNEL = as_create(FLAG_AS_KERNEL);
 	if (!AS_KERNEL)
-		panic("can't create kernel address space\n");
-	
+		panic("Cannot create kernel address space\n");
+	
+	/* Make sure the kernel address space
+	 * reference count never drops to zero.
+	 */
+	atomic_set(&AS_KERNEL->refcount, 1);
 }
 
@@ -177,5 +181,5 @@
 	page_table_create(flags);
 #endif
-
+	
 	return as;
 }
@@ -770,9 +774,10 @@
  * into private anonymous memory (unless it's already there).
  *
- * @param as		Address space.
- * @param flags		Flags of the area memory.
- * @param address	Address withing the area to be changed.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+ * @param as      Address space.
+ * @param flags   Flags of the area memory.
+ * @param address Address within the area to be changed.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
  */
 int as_area_change_flags(as_t *as, int flags, uintptr_t address)
@@ -786,5 +791,5 @@
 	index_t frame_idx;
 	count_t used_pages;
-
+	
 	/* Flags for the new memory mapping */
 	page_flags = area_flags_to_page_flags(flags);
@@ -800,5 +805,5 @@
 	}
 
-	if (area->sh_info || area->backend != &anon_backend) {
+	if ((area->sh_info) || (area->backend != &anon_backend)) {
 		/* Copying shared areas not supported yet */
 		/* Copying non-anonymous memory not supported yet */
@@ -871,4 +876,5 @@
 
 	tlb_invalidate_pages(as->asid, area->base, area->pages);
+	
 	/*
 	 * Invalidate potential software translation caches (e.g. TSB on
