Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision 92778f2136ec900a873b76c69db8efbdb1998fea)
+++ kernel/generic/src/mm/as.c	(revision 134877d64bac047ca117c283bd304140ea31a7b0)
@@ -167,9 +167,4 @@
 	as->page_table = page_table_create(flags);
 
-#ifdef CONFIG_VIRT_IDX_DCACHE
-	as->dcache_flush_on_install = false;
-	as->dcache_flush_on_deinstall = false;
-#endif	/* CONFIG_VIRT_IDX_DCACHE */
-
 	return as;
 }
@@ -278,16 +273,4 @@
 	else
 		memsetb((uintptr_t) &a->backend_data, sizeof(a->backend_data), 0);
-
-#ifdef CONFIG_VIRT_IDX_DCACHE
-	/*
-	 * When the area is being created with the AS_AREA_ATTR_PARTIAL flag, the
-	 * orig_color is probably wrong until the flag is reset. In other words, it is
-	 * initialized with the color of the area being created and not with the color
-	 * of the original address space area at the beginning of the share chain. Of
-	 * course, the correct color is set by as_area_share() before the flag is
-	 * reset.
-	 */
-	a->orig_color = PAGE_COLOR(base);
-#endif /* CONFIG_VIRT_IDX_DCACHE */
 
 	btree_create(&a->used_space);
@@ -576,5 +559,6 @@
  * or ENOMEM if there was a problem in allocating destination address space
  * area. ENOTSUP is returned if the address space area backend does not support
- * sharing.
+ * sharing or if the kernel detects an attempt to create an illegal address
+ * alias.
  */
 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
@@ -584,5 +568,4 @@
 	int src_flags;
 	size_t src_size;
-	int src_orig_color;
 	as_area_t *src_area, *dst_area;
 	share_info_t *sh_info;
@@ -601,5 +584,4 @@
 		return ENOENT;
 	}
-	
 
 	if (!src_area->backend || !src_area->backend->share) {
@@ -618,5 +600,4 @@
 	src_backend = src_area->backend;
 	src_backend_data = src_area->backend_data;
-	src_orig_color = src_area->orig_color;
 
 	/* Share the cacheable flag from the original mapping */
@@ -630,4 +611,18 @@
 		return EPERM;
 	}
+
+#ifdef CONFIG_VIRT_IDX_DCACHE
+	if (!(dst_flags_mask & AS_AREA_EXEC)) {
+		if (PAGE_COLOR(src_area->base) != PAGE_COLOR(dst_base)) {
+			/*
+			 * Refuse to create an illegal address alias.
+			 */
+			mutex_unlock(&src_area->lock);
+			mutex_unlock(&src_as->lock);
+			interrupts_restore(ipl);
+			return ENOTSUP;
+		}
+	}
+#endif /* CONFIG_VIRT_IDX_DCACHE */
 
 	/*
@@ -683,24 +678,4 @@
 	dst_area->attributes &= ~AS_AREA_ATTR_PARTIAL;
 	dst_area->sh_info = sh_info;
-	dst_area->orig_color = src_orig_color;
-#ifdef CONFIG_VIRT_IDX_DCACHE
-	if (src_orig_color != PAGE_COLOR(dst_base)) {
-		/*
- 		 * We have just detected an attempt to create an invalid address
- 		 * alias. We allow this and set a special flag that tells the
- 		 * architecture specific code to flush the D-cache when the
- 		 * offending address space is installed and deinstalled
- 		 * (cleanup).
- 		 *
- 		 * In order for the flags to take effect immediately, we also
- 		 * perform a global D-cache shootdown.
- 		 */
-		dcache_shootdown_start();
-		dst_as->dcache_flush_on_install = true;
-		dst_as->dcache_flush_on_deinstall = true;
-		dcache_flush();
-		dcache_shootdown_finalize();
-	}
-#endif /* CONFIG_VIRT_IDX_DCACHE */
 	mutex_unlock(&dst_area->lock);
 	mutex_unlock(&dst_as->lock);	
