Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision eef1b0317f3802b67fa2a31033fa2973fbaab4e7)
+++ kernel/generic/src/mm/as.c	(revision 55b77d9e6e4dab7c54e9826ca79d2d6a0ddb6d87)
@@ -94,5 +94,5 @@
  *
  * This lock protects:
- * - inactive_as_with_asid_head list
+ * - inactive_as_with_asid_list
  * - as->asid for each as of the as_t type
  * - asids_allocated counter
@@ -105,5 +105,5 @@
  * that have valid ASID.
  */
-LIST_INITIALIZE(inactive_as_with_asid_head);
+LIST_INITIALIZE(inactive_as_with_asid_list);
 
 /** Kernel address space. */
@@ -235,8 +235,8 @@
 	bool cond = true;
 	while (cond) {
-		ASSERT(!list_empty(&as->as_area_btree.leaf_head));
+		ASSERT(!list_empty(&as->as_area_btree.leaf_list));
 		
 		btree_node_t *node =
-		    list_get_instance(as->as_area_btree.leaf_head.next,
+		    list_get_instance(list_first(&as->as_area_btree.leaf_list),
 		    btree_node_t, leaf_link);
 		
@@ -602,8 +602,8 @@
 		bool cond = true;
 		while (cond) {
-			ASSERT(!list_empty(&area->used_space.leaf_head));
+			ASSERT(!list_empty(&area->used_space.leaf_list));
 			
 			btree_node_t *node =
-			    list_get_instance(area->used_space.leaf_head.prev,
+			    list_get_instance(list_last(&area->used_space.leaf_list),
 			    btree_node_t, leaf_link);
 			
@@ -727,5 +727,4 @@
 	if (--sh_info->refcount == 0) {
 		dealloc = true;
-		link_t *cur;
 		
 		/*
@@ -733,6 +732,5 @@
 		 * reference from all frames found there.
 		 */
-		for (cur = sh_info->pagemap.leaf_head.next;
-		    cur != &sh_info->pagemap.leaf_head; cur = cur->next) {
+		list_foreach(sh_info->pagemap.leaf_list, cur) {
 			btree_node_t *node
 			    = list_get_instance(cur, btree_node_t, leaf_link);
@@ -786,7 +784,5 @@
 	 * Visit only the pages mapped by used_space B+tree.
 	 */
-	link_t *cur;
-	for (cur = area->used_space.leaf_head.next;
-	    cur != &area->used_space.leaf_head; cur = cur->next) {
+	list_foreach(area->used_space.leaf_list, cur) {
 		btree_node_t *node;
 		btree_key_t i;
@@ -1065,8 +1061,6 @@
 	 */
 	size_t used_pages = 0;
-	link_t *cur;
-	
-	for (cur = area->used_space.leaf_head.next;
-	    cur != &area->used_space.leaf_head; cur = cur->next) {
+	
+	list_foreach(area->used_space.leaf_list, cur) {
 		btree_node_t *node
 		    = list_get_instance(cur, btree_node_t, leaf_link);
@@ -1094,6 +1088,5 @@
 	size_t frame_idx = 0;
 	
-	for (cur = area->used_space.leaf_head.next;
-	    cur != &area->used_space.leaf_head; cur = cur->next) {
+	list_foreach(area->used_space.leaf_list, cur) {
 		btree_node_t *node = list_get_instance(cur, btree_node_t,
 		    leaf_link);
@@ -1147,6 +1140,5 @@
 	frame_idx = 0;
 	
-	for (cur = area->used_space.leaf_head.next;
-	    cur != &area->used_space.leaf_head; cur = cur->next) {
+	list_foreach(area->used_space.leaf_list, cur) {
 		btree_node_t *node
 		    = list_get_instance(cur, btree_node_t, leaf_link);
@@ -1334,5 +1326,5 @@
 			
 			list_append(&old_as->inactive_as_with_asid_link,
-			    &inactive_as_with_asid_head);
+			    &inactive_as_with_asid_list);
 		}
 		
@@ -2027,8 +2019,8 @@
 	
 	/* Eventually check the addresses behind each area */
-	link_t *cur;
-	for (cur = AS->as_area_btree.leaf_head.next;
-	    (ret == 0) && (cur != &AS->as_area_btree.leaf_head);
-	    cur = cur->next) {
+	list_foreach(AS->as_area_btree.leaf_list, cur) {
+		if (ret != 0)
+			break;
+
 		btree_node_t *node =
 		    list_get_instance(cur, btree_node_t, leaf_link);
@@ -2072,8 +2064,6 @@
 	
 	size_t area_cnt = 0;
-	link_t *cur;
-	
-	for (cur = as->as_area_btree.leaf_head.next;
-	    cur != &as->as_area_btree.leaf_head; cur = cur->next) {
+	
+	list_foreach(as->as_area_btree.leaf_list, cur) {
 		btree_node_t *node =
 		    list_get_instance(cur, btree_node_t, leaf_link);
@@ -2088,6 +2078,5 @@
 	size_t area_idx = 0;
 	
-	for (cur = as->as_area_btree.leaf_head.next;
-	    cur != &as->as_area_btree.leaf_head; cur = cur->next) {
+	list_foreach(as->as_area_btree.leaf_list, cur) {
 		btree_node_t *node =
 		    list_get_instance(cur, btree_node_t, leaf_link);
@@ -2125,7 +2114,5 @@
 	
 	/* Print out info about address space areas */
-	link_t *cur;
-	for (cur = as->as_area_btree.leaf_head.next;
-	    cur != &as->as_area_btree.leaf_head; cur = cur->next) {
+	list_foreach(as->as_area_btree.leaf_list, cur) {
 		btree_node_t *node
 		    = list_get_instance(cur, btree_node_t, leaf_link);
