Index: generic/include/errno.h
===================================================================
--- generic/include/errno.h	(revision cfffb000c1b414a3b483fb3d1b0ef9d245d2fa89)
+++ generic/include/errno.h	(revision 7242a78e33a2551d6e465ea31b274f0f66292505)
@@ -32,15 +32,17 @@
 /* 1-255 are kernel error codes, 256-512 are user error codes */
 
-#define ENOENT     -1  /* No such entry */
-#define ENOMEM     -2  /* Not enough memory */
-#define ELIMIT     -3  /* Limit exceeded */
-#define EREFUSED   -4  /* Connection refused */
-#define EFORWARD   -5  /* Forward error */
-#define EPERM      -6  /* Permission denied */
-#define EHANGUP    -7  /* Answerbox closed connection, call sys_ipc_hangup
-			* to close the connection. Used by answerbox
-			* to close the connection.  */
-#define EEXISTS    -8  /* Entry already exists */
-#define EBADMEM    -9  /* Bad memory pointer */
+#define ENOENT		-1	/* No such entry */
+#define ENOMEM		-2	/* Not enough memory */
+#define ELIMIT		-3	/* Limit exceeded */
+#define EREFUSED	-4	/* Connection refused */
+#define EFORWARD	-5	/* Forward error */
+#define EPERM		-6	/* Permission denied */
+#define EHANGUP		-7	/* Answerbox closed connection, call sys_ipc_hangup
+				 * to close the connection. Used by answerbox
+				 * to close the connection.  */
+#define EEXISTS		-8	/* Entry already exists */
+#define EBADMEM		-9	/* Bad memory pointer */
+#define ENOTSUP		-10	/* Not supported */
+#define EADDRNOTAVAIL	-11	/* Address not available. */
 
 #endif
Index: generic/include/mm/as.h
===================================================================
--- generic/include/mm/as.h	(revision cfffb000c1b414a3b483fb3d1b0ef9d245d2fa89)
+++ generic/include/mm/as.h	(revision 7242a78e33a2551d6e465ea31b274f0f66292505)
@@ -123,5 +123,6 @@
 extern as_t *as_create(int flags);
 extern as_area_t *as_area_create(as_t *as, int flags, size_t size, __address base, int attrs);
-extern __address as_area_resize(as_t *as, __address address, size_t size, int flags);
+extern int as_area_resize(as_t *as, __address address, size_t size, int flags);
+extern int as_area_destroy(as_t *as, __address address);
 int as_area_send(task_id_t dst_id, __address base);
 extern void as_set_mapping(as_t *as, __address page, __address frame);
@@ -138,4 +139,5 @@
 extern __native sys_as_area_create(__address address, size_t size, int flags);
 extern __native sys_as_area_resize(__address address, size_t size, int flags);
+extern __native sys_as_area_destroy(__address address);
 extern __native sys_as_area_accept(as_area_acptsnd_arg_t *uspace_accept_arg);
 extern __native sys_as_area_send(as_area_acptsnd_arg_t *uspace_send_arg);
Index: generic/include/syscall/syscall.h
===================================================================
--- generic/include/syscall/syscall.h	(revision cfffb000c1b414a3b483fb3d1b0ef9d245d2fa89)
+++ generic/include/syscall/syscall.h	(revision 7242a78e33a2551d6e465ea31b274f0f66292505)
@@ -40,4 +40,5 @@
 	SYS_AS_AREA_CREATE,
 	SYS_AS_AREA_RESIZE,
+	SYS_AS_AREA_DESTROY,
 	SYS_AS_AREA_ACCEPT,
 	SYS_AS_AREA_SEND,
Index: generic/src/mm/as.c
===================================================================
--- generic/src/mm/as.c	(revision cfffb000c1b414a3b483fb3d1b0ef9d245d2fa89)
+++ generic/src/mm/as.c	(revision 7242a78e33a2551d6e465ea31b274f0f66292505)
@@ -195,9 +195,9 @@
  * @param flags Flags influencing the remap operation. Currently unused.
  *
- * @return address on success, (__address) -1 otherwise.
+ * @return Zero on success or a value from @ref errno.h otherwise.
  */ 
-__address as_area_resize(as_t *as, __address address, size_t size, int flags)
-{
-	as_area_t *area = NULL;
+int as_area_resize(as_t *as, __address address, size_t size, int flags)
+{
+	as_area_t *area;
 	ipl_t ipl;
 	size_t pages;
@@ -213,5 +213,5 @@
 		spinlock_unlock(&as->lock);
 		interrupts_restore(ipl);
-		return (__address) -1;
+		return ENOENT;
 	}
 
@@ -224,5 +224,5 @@
 		spinlock_unlock(&as->lock);
 		interrupts_restore(ipl);
-		return (__address) -1;
+		return ENOTSUP;
 	}
 
@@ -235,5 +235,5 @@
 		spinlock_unlock(&as->lock);
 		interrupts_restore(ipl);
-		return (__address) -1;
+		return EPERM;
 	}
 	
@@ -282,5 +282,5 @@
 			spinlock_unlock(&as->lock);		
 			interrupts_restore(ipl);
-			return (__address) -1;
+			return EADDRNOTAVAIL;
 		}
 	} 
@@ -292,5 +292,72 @@
 	interrupts_restore(ipl);
 
-	return address;
+	return 0;
+}
+
+/** Destroy address space area.
+ *
+ * @param as Address space.
+ * @param address Address withing the area to be deleted.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure. 
+ */
+int as_area_destroy(as_t *as, __address address)
+{
+	as_area_t *area;
+	__address base;
+	ipl_t ipl;
+	int i;
+
+	ipl = interrupts_disable();
+	spinlock_lock(&as->lock);
+
+	area = find_area_and_lock(as, address);
+	if (!area) {
+		spinlock_unlock(&as->lock);
+		interrupts_restore(ipl);
+		return ENOENT;
+	}
+
+	base = area->base;	
+	for (i = 0; i < area->pages; i++) {
+		pte_t *pte;
+
+		/*
+		 * Releasing physical memory.
+		 * Areas mapping memory-mapped devices are treated differently than
+		 * areas backing frame_alloc()'ed memory.
+		 */
+		page_table_lock(as, false);
+		pte = page_mapping_find(as, area->base + i*PAGE_SIZE);
+		if (pte && PTE_VALID(pte)) {
+			ASSERT(PTE_PRESENT(pte));
+			page_mapping_remove(as, area->base + i*PAGE_SIZE);
+			if (area->flags & AS_AREA_DEVICE) {
+				__address frame;
+				frame = PTE_GET_FRAME(pte);
+				frame_free(ADDR2PFN(frame));
+			}
+			page_table_unlock(as, false);
+		} else {
+			page_table_unlock(as, false);
+		}
+	}
+	/*
+	 * Invalidate TLB's.
+	 */
+	tlb_shootdown_start(TLB_INVL_PAGES, AS->asid, area->base, area->pages);
+	tlb_invalidate_pages(AS->asid, area->base, area->pages);
+	tlb_shootdown_finalize();
+
+	spinlock_unlock(&area->lock);
+
+	/*
+	 * Remove the empty area from address space.
+	 */
+	btree_remove(&AS->as_area_btree, base, NULL);
+	
+	spinlock_unlock(&AS->lock);
+	interrupts_restore(ipl);
+	return 0;
 }
 
@@ -308,5 +375,5 @@
  * @param src_base Base address of the source address space area.
  *
- * @return 0 on success or ENOENT if there is no such task or
+ * @return Zero on success or ENOENT if there is no such task or
  *	   if there is no such address space area,
  *	   EPERM if there was a problem in accepting the area or
@@ -892,5 +959,11 @@
 __native sys_as_area_resize(__address address, size_t size, int flags)
 {
-	return as_area_resize(AS, address, size, 0);
+	return (__native) as_area_resize(AS, address, size, 0);
+}
+
+/** Wrapper for as_area_destroy. */
+__native sys_as_area_destroy(__address address)
+{
+	return (__native) as_area_destroy(AS, address);
 }
 
Index: generic/src/syscall/syscall.c
===================================================================
--- generic/src/syscall/syscall.c	(revision cfffb000c1b414a3b483fb3d1b0ef9d245d2fa89)
+++ generic/src/syscall/syscall.c	(revision 7242a78e33a2551d6e465ea31b274f0f66292505)
@@ -85,4 +85,5 @@
 	sys_as_area_create,
 	sys_as_area_resize,
+	sys_as_area_destroy,
 	sys_as_area_accept,
 	sys_as_area_send,
