Index: boot/Makefile.build
===================================================================
--- boot/Makefile.build	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ boot/Makefile.build	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -111,5 +111,5 @@
 
 $(RAW): $(OBJECTS) $(COMPONENT_OBJECTS) $(LINK)
-	$(LD) -N $(LFLAGS) -T $(LINK) -M -Map $(MAP) -o $@ $(COMPONENT_OBJECTS) $(OBJECTS)
+	$(LD) -n $(LFLAGS) -T $(LINK) -M -Map $(MAP) -o $@ $(COMPONENT_OBJECTS) $(OBJECTS)
 
 $(LINK): $(LINK).comp $(DEPEND)
Index: boot/arch/ia64/_link.ld.in
===================================================================
--- boot/arch/ia64/_link.ld.in	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ boot/arch/ia64/_link.ld.in	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -11,6 +11,6 @@
 		*(.rodata);
 		*(.rodata.*);
-		*(.data);               /* initialized data */
-		_got = . ;
+		*(.data .data.*);       /* initialized data */
+		__gp = . ;
 		*(.got .got.*);
 		*(.bss);                /* uninitialized static variables */
@@ -20,6 +20,5 @@
 
 	/DISCARD/ : {
-		*(.comment);
-		*(.note*);
+		*(.*);
 	}
 }
Index: boot/arch/ia64/src/boot.S
===================================================================
--- boot/arch/ia64/src/boot.S	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ boot/arch/ia64/src/boot.S	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -34,5 +34,5 @@
 .global start
 start:
-	movl gp = LOADER_ADDRESS
+	movl gp = __gp
 
 	#
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/Makefile	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -134,5 +134,5 @@
 #
 AFLAGS =
-LFLAGS = -N -T $(LINK) -M
+LFLAGS = -n -T $(LINK) -M
 
 #
@@ -228,4 +228,5 @@
 	generic/src/syscall/syscall.c \
 	generic/src/syscall/copy.c \
+	generic/src/mm/reserve.c \
 	generic/src/mm/buddy.c \
 	generic/src/mm/frame.c \
Index: kernel/arch/abs32le/include/types.h
===================================================================
--- kernel/arch/abs32le/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/abs32le/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -40,4 +40,5 @@
 
 typedef uint32_t size_t;
+typedef int32_t ssize_t;
 
 typedef uint32_t uintptr_t;
Index: kernel/arch/amd64/include/types.h
===================================================================
--- kernel/arch/amd64/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/amd64/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,4 +37,5 @@
 
 typedef uint64_t size_t;
+typedef int64_t ssize_t;
 
 typedef uint64_t uintptr_t;
Index: kernel/arch/arm32/include/types.h
===================================================================
--- kernel/arch/arm32/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/arm32/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -44,4 +44,5 @@
 
 typedef uint32_t size_t;
+typedef int32_t ssize_t;
 
 typedef uint32_t uintptr_t;
Index: kernel/arch/ia32/include/types.h
===================================================================
--- kernel/arch/ia32/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/ia32/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,4 +37,5 @@
 
 typedef uint32_t size_t;
+typedef int32_t ssize_t;
 
 typedef uint32_t uintptr_t;
Index: kernel/arch/ia64/_link.ld.in
===================================================================
--- kernel/arch/ia64/_link.ld.in	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/ia64/_link.ld.in	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -30,4 +30,5 @@
 		hardcoded_kdata_size = .;
 		QUAD(kdata_end - kdata_start);
+		__gp = .;
 		*(.got .got.*)
 		*(.sdata)
Index: kernel/arch/ia64/include/types.h
===================================================================
--- kernel/arch/ia64/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/ia64/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,4 +37,5 @@
 
 typedef uint64_t size_t;
+typedef int64_t ssize_t;
 
 typedef uint64_t uintptr_t;
Index: kernel/arch/ia64/src/ivt.S
===================================================================
--- kernel/arch/ia64/src/ivt.S	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/ia64/src/ivt.S	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -391,5 +391,5 @@
 
     /* 10. call handler */
-    	movl r1 = kernel_image_start
+    	movl r1 = __gp
     
     	mov b1 = loc2
Index: kernel/arch/ia64/src/start.S
===================================================================
--- kernel/arch/ia64/src/start.S	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/ia64/src/start.S	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -174,7 +174,7 @@
 	
 	# Initialize gp (Global Pointer) register
-	movl gp = kernel_image_start
+	movl gp = __gp
 	
-	#	
+	#
 	# Initialize bootinfo on BSP.
 	#
Index: kernel/arch/mips32/include/types.h
===================================================================
--- kernel/arch/mips32/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/mips32/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,4 +37,5 @@
 
 typedef uint32_t size_t;
+typedef int32_t ssize_t;
 
 typedef uint32_t uintptr_t;
Index: kernel/arch/mips32/src/mm/frame.c
===================================================================
--- kernel/arch/mips32/src/mm/frame.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/mips32/src/mm/frame.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -88,5 +88,5 @@
 	/* gxemul devices */
 	if (overlaps(frame << ZERO_PAGE_WIDTH, ZERO_PAGE_SIZE,
-	    0x10000000, MB2SIZE(256)))
+	    0x10000000, MiB2SIZE(256)))
 		return false;
 #endif
Index: kernel/arch/ppc32/include/types.h
===================================================================
--- kernel/arch/ppc32/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/ppc32/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,4 +37,5 @@
 
 typedef uint32_t size_t;
+typedef int32_t ssize_t;
 
 typedef uint32_t uintptr_t;
Index: kernel/arch/sparc64/include/cpu.h
===================================================================
--- kernel/arch/sparc64/include/cpu.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/sparc64/include/cpu.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -59,9 +59,4 @@
 #include <arch/asm.h>
 
-#ifdef CONFIG_SMP
-#include <arch/mm/cache.h>
-#endif
-
-
 #if defined (SUN4U)
 #include <arch/sun4u/cpu.h>
Index: rnel/arch/sparc64/include/mm/cache.h
===================================================================
--- kernel/arch/sparc64/include/mm/cache.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup sparc64mm	
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_sparc64_CACHE_H_
-#define KERN_sparc64_CACHE_H_
-
-#include <mm/page.h>
-#include <mm/frame.h>
-
-#endif
-
-/** @}
- */
Index: kernel/arch/sparc64/include/sun4u/cpu.h
===================================================================
--- kernel/arch/sparc64/include/sun4u/cpu.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/sparc64/include/sun4u/cpu.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -60,8 +60,4 @@
 #include <trace.h>
 
-#ifdef CONFIG_SMP
-#include <arch/mm/cache.h>
-#endif
-
 typedef struct {
 	uint32_t mid;              /**< Processor ID as read from
Index: kernel/arch/sparc64/include/types.h
===================================================================
--- kernel/arch/sparc64/include/types.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/arch/sparc64/include/types.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,4 +37,5 @@
 
 typedef uint64_t size_t;
+typedef int64_t ssize_t;
 
 typedef uint64_t uintptr_t;
Index: kernel/generic/include/macros.h
===================================================================
--- kernel/generic/include/macros.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/include/macros.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -95,9 +95,6 @@
 	overlaps(KA2PA((x)), (szx), KA2PA((y)), (szy))
 
-#define SIZE2KB(size)  ((size) >> 10)
-#define SIZE2MB(size)  ((size) >> 20)
-
-#define KB2SIZE(kb)  ((kb) << 10)
-#define MB2SIZE(mb)  ((mb) << 20)
+#define KiB2SIZE(kb)  ((kb) << 10)
+#define MiB2SIZE(mb)  ((mb) << 20)
 
 #define STRING(arg)      STRING_ARG(arg)
Index: kernel/generic/include/mm/as.h
===================================================================
--- kernel/generic/include/mm/as.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/include/mm/as.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -238,7 +238,11 @@
 /** Address space area backend structure. */
 typedef struct mem_backend {
+	bool (* create)(as_area_t *);
+	bool (* resize)(as_area_t *, size_t);
+	void (* share)(as_area_t *);
+	void (* destroy)(as_area_t *);
+
 	int (* page_fault)(as_area_t *, uintptr_t, pf_access_t);
 	void (* frame_free)(as_area_t *, uintptr_t, uintptr_t);
-	void (* share)(as_area_t *);
 } mem_backend_t;
 
Index: kernel/generic/include/mm/frame.h
===================================================================
--- kernel/generic/include/mm/frame.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/include/mm/frame.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -62,16 +62,18 @@
 
 /** Convert the frame address to kernel VA. */
-#define FRAME_KA          0x01
+#define FRAME_KA          0x1
 /** Do not panic and do not sleep on failure. */
-#define FRAME_ATOMIC      0x02
+#define FRAME_ATOMIC      0x2
 /** Do not start reclaiming when no free memory. */
-#define FRAME_NO_RECLAIM  0x04
+#define FRAME_NO_RECLAIM  0x4
+/** Do not reserve / unreserve memory. */
+#define FRAME_NO_RESERVE  0x8
 
 typedef uint8_t zone_flags_t;
 
 /** Available zone (free for allocation) */
-#define ZONE_AVAILABLE  0x00
+#define ZONE_AVAILABLE  0x0
 /** Zone is reserved (not available for allocation) */
-#define ZONE_RESERVED   0x08
+#define ZONE_RESERVED   0x8
 /** Zone is used by firmware (not available for allocation) */
 #define ZONE_FIRMWARE   0x10
@@ -85,5 +87,5 @@
 	uint8_t buddy_order;  /**< Buddy system block order */
 	link_t buddy_link;    /**< Link to the next free block inside
-                               one order */
+                                   one order */
 	void *parent;         /**< If allocated by slab, this points there */
 } frame_t;
@@ -91,14 +93,14 @@
 typedef struct {
 	pfn_t base;                    /**< Frame_no of the first frame
-                                        in the frames array */
+                                            in the frames array */
 	size_t count;                  /**< Size of zone */
 	size_t free_count;             /**< Number of free frame_t
-                                        structures */
+                                            structures */
 	size_t busy_count;             /**< Number of busy frame_t
-                                        structures */
+                                            structures */
 	zone_flags_t flags;            /**< Type of the zone */
 	
 	frame_t *frames;               /**< Array of frame_t structures
-                                        in this zone */
+                                            in this zone */
 	buddy_system_t *buddy_system;  /**< Buddy system for the zone */
 } zone_t;
@@ -146,21 +148,22 @@
     ((~(((sysarg_t) -1) << (order)) & (index)) == 0)
 #define IS_BUDDY_LEFT_BLOCK(zone, frame) \
-    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 0)
+    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
 #define IS_BUDDY_RIGHT_BLOCK(zone, frame) \
-    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 1)
+    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \
-    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 0)
+    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \
-    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 1)
-
-#define frame_alloc(order, flags) \
-    frame_alloc_generic(order, flags, NULL)
+    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 
 extern void frame_init(void);
 extern void *frame_alloc_generic(uint8_t, frame_flags_t, size_t *);
+extern void *frame_alloc(uint8_t, frame_flags_t);
+extern void *frame_alloc_noreserve(uint8_t, frame_flags_t);
+extern void frame_free_generic(uintptr_t, frame_flags_t);
 extern void frame_free(uintptr_t);
+extern void frame_free_noreserve(uintptr_t);
 extern void frame_reference_add(pfn_t);
 
-extern size_t find_zone(pfn_t frame, size_t count, size_t hint);
+extern size_t find_zone(pfn_t, size_t, size_t);
 extern size_t zone_create(pfn_t, size_t, pfn_t, zone_flags_t);
 extern void *frame_get_parent(pfn_t, size_t);
Index: kernel/generic/include/mm/reserve.h
===================================================================
--- kernel/generic/include/mm/reserve.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
+++ kernel/generic/include/mm/reserve.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genericmm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_RESERVE_H_
+#define KERN_RESERVE_H_
+
+#include <typedefs.h>
+
+extern bool reserve_try_alloc(size_t);
+extern void reserve_force_alloc(size_t);
+extern void reserve_free(size_t);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/str.h
===================================================================
--- kernel/generic/include/str.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/include/str.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -99,5 +99,6 @@
 extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *);
 
-extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix);
+extern void order_suffix(const uint64_t, uint64_t *, char *);
+extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
 
 #endif
Index: kernel/generic/src/lib/str.c
===================================================================
--- kernel/generic/src/lib/str.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/lib/str.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -922,21 +922,21 @@
 void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
 {
-	if (val > 10000000000000000000ULL) {
-		*rv = val / 1000000000000000000ULL;
+	if (val > UINT64_C(10000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000000);
 		*suffix = 'Z';
-	} else if (val > 1000000000000000000ULL) {
-		*rv = val / 1000000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000);
 		*suffix = 'E';
-	} else if (val > 1000000000000000ULL) {
-		*rv = val / 1000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000)) {
+		*rv = val / UINT64_C(1000000000000);
 		*suffix = 'T';
-	} else if (val > 1000000000000ULL) {
-		*rv = val / 1000000000ULL;
+	} else if (val > UINT64_C(1000000000000)) {
+		*rv = val / UINT64_C(1000000000);
 		*suffix = 'G';
-	} else if (val > 1000000000ULL) {
-		*rv = val / 1000000ULL;
+	} else if (val > UINT64_C(1000000000)) {
+		*rv = val / UINT64_C(1000000);
 		*suffix = 'M';
-	} else if (val > 1000000ULL) {
-		*rv = val / 1000ULL;
+	} else if (val > UINT64_C(1000000)) {
+		*rv = val / UINT64_C(1000);
 		*suffix = 'k';
 	} else {
@@ -946,4 +946,31 @@
 }
 
+void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
+    bool fixed)
+{
+	if (val > UINT64_C(1152921504606846976)) {
+		*rv = val / UINT64_C(1125899906842624);
+		*suffix = "EiB";
+	} else if (val > UINT64_C(1125899906842624)) {
+		*rv = val / UINT64_C(1099511627776);
+		*suffix = "TiB";
+	} else if (val > UINT64_C(1099511627776)) {
+		*rv = val / UINT64_C(1073741824);
+		*suffix = "GiB";
+	} else if (val > UINT64_C(1073741824)) {
+		*rv = val / UINT64_C(1048576);
+		*suffix = "MiB";
+	} else if (val > UINT64_C(1048576)) {
+		*rv = val / UINT64_C(1024);
+		*suffix = "KiB";
+	} else {
+		*rv = val;
+		if (fixed)
+			*suffix = "B  ";
+		else
+			*suffix = "B";
+	}
+}
+
 /** @}
  */
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/main/main.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -223,6 +223,9 @@
 	slab_enable_cpucache();
 	
-	printf("Detected %u CPU(s), %" PRIu64 " MiB free memory\n",
-	    config.cpu_count, SIZE2MB(zones_total_size()));
+	uint64_t size;
+	const char *size_suffix;
+	bin_order_suffix(zones_total_size(), &size, &size_suffix, false);
+	printf("Detected %u CPU(s), %" PRIu64 " %s free memory\n",
+	    config.cpu_count, size, size_suffix);
 	
 	cpu_init();
Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/mm/as.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -80,8 +80,4 @@
 #include <arch/interrupt.h>
 
-#ifdef CONFIG_VIRT_IDX_DCACHE
-#include <arch/mm/cache.h>
-#endif /* CONFIG_VIRT_IDX_DCACHE */
-
 /**
  * Each architecture decides what functions will be used to carry out
@@ -447,4 +443,12 @@
 	else
 		memsetb(&area->backend_data, sizeof(area->backend_data), 0);
+	
+	if (area->backend && area->backend->create) {
+		if (!area->backend->create(area)) {
+			free(area);
+			mutex_unlock(&as->lock);
+			return NULL;
+		}
+	}
 	
 	btree_create(&area->used_space);
@@ -690,4 +694,12 @@
 	}
 	
+	if (area->backend && area->backend->resize) {
+		if (!area->backend->resize(area, pages)) {
+			mutex_unlock(&area->lock);
+			mutex_unlock(&as->lock);
+			return ENOMEM;
+		}
+	}
+	
 	area->pages = pages;
 	
@@ -756,4 +768,7 @@
 		return ENOENT;
 	}
+
+	if (area->backend && area->backend->destroy)
+		area->backend->destroy(area);
 	
 	uintptr_t base = area->base;
Index: kernel/generic/src/mm/backend_anon.c
===================================================================
--- kernel/generic/src/mm/backend_anon.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/mm/backend_anon.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -39,4 +39,5 @@
 #include <mm/as.h>
 #include <mm/page.h>
+#include <mm/reserve.h>
 #include <genarch/mm/page_pt.h>
 #include <genarch/mm/page_ht.h>
@@ -51,17 +52,95 @@
 #include <arch.h>
 
-#ifdef CONFIG_VIRT_IDX_DCACHE
-#include <arch/mm/cache.h>
-#endif
-
-static int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access);
-static void anon_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame);
-static void anon_share(as_area_t *area);
+static bool anon_create(as_area_t *);
+static bool anon_resize(as_area_t *, size_t);
+static void anon_share(as_area_t *);
+static void anon_destroy(as_area_t *);
+
+static int anon_page_fault(as_area_t *, uintptr_t, pf_access_t);
+static void anon_frame_free(as_area_t *, uintptr_t, uintptr_t);
 
 mem_backend_t anon_backend = {
+	.create = anon_create,
+	.resize = anon_resize,
+	.share = anon_share,
+	.destroy = anon_destroy,
+
 	.page_fault = anon_page_fault,
 	.frame_free = anon_frame_free,
-	.share = anon_share
 };
+
+bool anon_create(as_area_t *area)
+{
+	return reserve_try_alloc(area->pages);
+}
+
+bool anon_resize(as_area_t *area, size_t new_pages)
+{
+	if (new_pages > area->pages)
+		return reserve_try_alloc(new_pages - area->pages);
+	else if (new_pages < area->pages)
+		reserve_free(area->pages - new_pages);
+
+	return true;
+}
+
+/** Share the anonymous address space area.
+ *
+ * Sharing of anonymous area is done by duplicating its entire mapping
+ * to the pagemap. Page faults will primarily search for frames there.
+ *
+ * The address space and address space area must be already locked.
+ *
+ * @param area Address space area to be shared.
+ */
+void anon_share(as_area_t *area)
+{
+	link_t *cur;
+
+	ASSERT(mutex_locked(&area->as->lock));
+	ASSERT(mutex_locked(&area->lock));
+
+	/*
+	 * Copy used portions of the area to sh_info's page map.
+	 */
+	mutex_lock(&area->sh_info->lock);
+	for (cur = area->used_space.leaf_head.next;
+	    cur != &area->used_space.leaf_head; cur = cur->next) {
+		btree_node_t *node;
+		unsigned int i;
+		
+		node = list_get_instance(cur, btree_node_t, leaf_link);
+		for (i = 0; i < node->keys; i++) {
+			uintptr_t base = node->key[i];
+			size_t count = (size_t) node->value[i];
+			unsigned int j;
+			
+			for (j = 0; j < count; j++) {
+				pte_t *pte;
+			
+				page_table_lock(area->as, false);
+				pte = page_mapping_find(area->as,
+				    base + j * PAGE_SIZE);
+				ASSERT(pte && PTE_VALID(pte) &&
+				    PTE_PRESENT(pte));
+				btree_insert(&area->sh_info->pagemap,
+				    (base + j * PAGE_SIZE) - area->base,
+				    (void *) PTE_GET_FRAME(pte), NULL);
+				page_table_unlock(area->as, false);
+
+				pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte));
+				frame_reference_add(pfn);
+			}
+
+		}
+	}
+	mutex_unlock(&area->sh_info->lock);
+}
+
+void anon_destroy(as_area_t *area)
+{
+	reserve_free(area->pages);
+}
+
 
 /** Service a page fault in the anonymous memory address space area.
@@ -115,5 +194,6 @@
 			}
 			if (allocate) {
-				frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
+				frame = (uintptr_t) frame_alloc_noreserve(
+				    ONE_FRAME, 0);
 				memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
 				
@@ -145,5 +225,5 @@
 		 *   the different causes
 		 */
-		frame = (uintptr_t) frame_alloc(ONE_FRAME, 0);
+		frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);
 		memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
 	}
@@ -174,58 +254,5 @@
 	ASSERT(mutex_locked(&area->lock));
 
-	frame_free(frame);
-}
-
-/** Share the anonymous address space area.
- *
- * Sharing of anonymous area is done by duplicating its entire mapping
- * to the pagemap. Page faults will primarily search for frames there.
- *
- * The address space and address space area must be already locked.
- *
- * @param area Address space area to be shared.
- */
-void anon_share(as_area_t *area)
-{
-	link_t *cur;
-
-	ASSERT(mutex_locked(&area->as->lock));
-	ASSERT(mutex_locked(&area->lock));
-
-	/*
-	 * Copy used portions of the area to sh_info's page map.
-	 */
-	mutex_lock(&area->sh_info->lock);
-	for (cur = area->used_space.leaf_head.next;
-	    cur != &area->used_space.leaf_head; cur = cur->next) {
-		btree_node_t *node;
-		unsigned int i;
-		
-		node = list_get_instance(cur, btree_node_t, leaf_link);
-		for (i = 0; i < node->keys; i++) {
-			uintptr_t base = node->key[i];
-			size_t count = (size_t) node->value[i];
-			unsigned int j;
-			
-			for (j = 0; j < count; j++) {
-				pte_t *pte;
-			
-				page_table_lock(area->as, false);
-				pte = page_mapping_find(area->as,
-				    base + j * PAGE_SIZE);
-				ASSERT(pte && PTE_VALID(pte) &&
-				    PTE_PRESENT(pte));
-				btree_insert(&area->sh_info->pagemap,
-				    (base + j * PAGE_SIZE) - area->base,
-				    (void *) PTE_GET_FRAME(pte), NULL);
-				page_table_unlock(area->as, false);
-
-				pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte));
-				frame_reference_add(pfn);
-			}
-
-		}
-	}
-	mutex_unlock(&area->sh_info->lock);
+	frame_free_noreserve(frame);
 }
 
Index: kernel/generic/src/mm/backend_elf.c
===================================================================
--- kernel/generic/src/mm/backend_elf.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/mm/backend_elf.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -43,4 +43,5 @@
 #include <mm/slab.h>
 #include <mm/page.h>
+#include <mm/reserve.h>
 #include <genarch/mm/page_pt.h>
 #include <genarch/mm/page_ht.h>
@@ -51,219 +52,67 @@
 #include <arch/barrier.h>
 
-#ifdef CONFIG_VIRT_IDX_DCACHE
-#include <arch/mm/cache.h>
-#endif
-
-static int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access);
-static void elf_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame);
-static void elf_share(as_area_t *area);
+static bool elf_create(as_area_t *);
+static bool elf_resize(as_area_t *, size_t);
+static void elf_share(as_area_t *);
+static void elf_destroy(as_area_t *);
+
+static int elf_page_fault(as_area_t *, uintptr_t, pf_access_t);
+static void elf_frame_free(as_area_t *, uintptr_t, uintptr_t);
 
 mem_backend_t elf_backend = {
+	.create = elf_create,
+	.resize = elf_resize,
+	.share = elf_share,
+	.destroy = elf_destroy,
+
 	.page_fault = elf_page_fault,
 	.frame_free = elf_frame_free,
-	.share = elf_share
 };
 
-/** Service a page fault in the ELF backend address space area.
- *
- * The address space area and page tables must be already locked.
- *
- * @param area		Pointer to the address space area.
- * @param addr		Faulting virtual address.
- * @param access	Access mode that caused the fault (i.e.
- * 			read/write/exec).
- *
- * @return		AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK
- * 			on success (i.e. serviced).
- */
-int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
-{
-	elf_header_t *elf = area->backend_data.elf;
+static size_t elf_nonanon_pages_get(as_area_t *area)
+{
 	elf_segment_header_t *entry = area->backend_data.segment;
-	btree_node_t *leaf;
-	uintptr_t base, frame, page, start_anon;
-	size_t i;
-	bool dirty = false;
-
-	ASSERT(page_table_locked(AS));
-	ASSERT(mutex_locked(&area->lock));
-
-	if (!as_area_check_access(area, access))
-		return AS_PF_FAULT;
+	uintptr_t first = ALIGN_UP(entry->p_vaddr, PAGE_SIZE);
+	uintptr_t last = ALIGN_DOWN(entry->p_vaddr + entry->p_filesz,
+	    PAGE_SIZE);
+
+	if (entry->p_flags & PF_W)
+		return 0;
+
+	if (last < first)
+		return 0;
+
+	return last - first;
+}
+
+bool elf_create(as_area_t *area)
+{
+	size_t nonanon_pages = elf_nonanon_pages_get(area);
+
+	if (area->pages <= nonanon_pages)
+		return true;
 	
-	if (addr < ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE))
-		return AS_PF_FAULT;
+	return reserve_try_alloc(area->pages - nonanon_pages);
+}
+
+bool elf_resize(as_area_t *area, size_t new_pages)
+{
+	size_t nonanon_pages = elf_nonanon_pages_get(area);
+
+	if (new_pages > area->pages) {
+		/* The area is growing. */
+		if (area->pages >= nonanon_pages)
+			return reserve_try_alloc(new_pages - area->pages);
+		else if (new_pages > nonanon_pages)
+			return reserve_try_alloc(new_pages - nonanon_pages);
+	} else if (new_pages < area->pages) {
+		/* The area is shrinking. */
+		if (new_pages >= nonanon_pages)
+			reserve_free(area->pages - new_pages);
+		else if (area->pages > nonanon_pages)
+			reserve_free(nonanon_pages - new_pages);
+	}
 	
-	if (addr >= entry->p_vaddr + entry->p_memsz)
-		return AS_PF_FAULT;
-	
-	i = (addr - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH;
-	base = (uintptr_t)
-	    (((void *) elf) + ALIGN_DOWN(entry->p_offset, PAGE_SIZE));
-
-	/* Virtual address of faulting page*/
-	page = ALIGN_DOWN(addr, PAGE_SIZE);
-
-	/* Virtual address of the end of initialized part of segment */
-	start_anon = entry->p_vaddr + entry->p_filesz;
-
-	if (area->sh_info) {
-		bool found = false;
-
-		/*
-		 * The address space area is shared.
-		 */
-		
-		mutex_lock(&area->sh_info->lock);
-		frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
-		    page - area->base, &leaf);
-		if (!frame) {
-			unsigned int i;
-
-			/*
-			 * Workaround for valid NULL address.
-			 */
-
-			for (i = 0; i < leaf->keys; i++) {
-				if (leaf->key[i] == page - area->base) {
-					found = true;
-					break;
-				}
-			}
-		}
-		if (frame || found) {
-			frame_reference_add(ADDR2PFN(frame));
-			page_mapping_insert(AS, addr, frame,
-			    as_area_get_flags(area));
-			if (!used_space_insert(area, page, 1))
-				panic("Cannot insert used space.");
-			mutex_unlock(&area->sh_info->lock);
-			return AS_PF_OK;
-		}
-	}
-
-	/*
-	 * The area is either not shared or the pagemap does not contain the
-	 * mapping.
-	 */
-	if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) {
-		/*
-		 * Initialized portion of the segment. The memory is backed
-		 * directly by the content of the ELF image. Pages are
-		 * only copied if the segment is writable so that there
-		 * can be more instantions of the same memory ELF image
-		 * used at a time. Note that this could be later done
-		 * as COW.
-		 */
-		if (entry->p_flags & PF_W) {
-			frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
-			memcpy((void *) PA2KA(frame),
-			    (void *) (base + i * FRAME_SIZE), FRAME_SIZE);
-			if (entry->p_flags & PF_X) {
-				smc_coherence_block((void *) PA2KA(frame),
-				    FRAME_SIZE);
-			}
-			dirty = true;
-		} else {
-			frame = KA2PA(base + i * FRAME_SIZE);
-		}	
-	} else if (page >= start_anon) {
-		/*
-		 * This is the uninitialized portion of the segment.
-		 * It is not physically present in the ELF image.
-		 * To resolve the situation, a frame must be allocated
-		 * and cleared.
-		 */
-		frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
-		memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
-		dirty = true;
-	} else {
-		size_t pad_lo, pad_hi;
-		/*
-		 * The mixed case.
-		 *
-		 * The middle part is backed by the ELF image and
-		 * the lower and upper parts are anonymous memory.
-		 * (The segment can be and often is shorter than 1 page).
-		 */
-		if (page < entry->p_vaddr)
-			pad_lo = entry->p_vaddr - page;
-		else
-			pad_lo = 0;
-
-		if (start_anon < page + PAGE_SIZE)
-			pad_hi = page + PAGE_SIZE - start_anon;
-		else
-			pad_hi = 0;
-
-		frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
-		memcpy((void *) (PA2KA(frame) + pad_lo),
-		    (void *) (base + i * FRAME_SIZE + pad_lo),
-		    FRAME_SIZE - pad_lo - pad_hi);
-		if (entry->p_flags & PF_X) {
-			smc_coherence_block((void *) (PA2KA(frame) + pad_lo), 
-			    FRAME_SIZE - pad_lo - pad_hi);
-		}
-		memsetb((void *) PA2KA(frame), pad_lo, 0);
-		memsetb((void *) (PA2KA(frame) + FRAME_SIZE - pad_hi), pad_hi,
-		    0);
-		dirty = true;
-	}
-
-	if (dirty && area->sh_info) {
-		frame_reference_add(ADDR2PFN(frame));
-		btree_insert(&area->sh_info->pagemap, page - area->base,
-		    (void *) frame, leaf);
-	}
-
-	if (area->sh_info)
-		mutex_unlock(&area->sh_info->lock);
-
-	page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
-	if (!used_space_insert(area, page, 1))
-		panic("Cannot insert used space.");
-
-	return AS_PF_OK;
-}
-
-/** Free a frame that is backed by the ELF backend.
- *
- * The address space area and page tables must be already locked.
- *
- * @param area		Pointer to the address space area.
- * @param page		Page that is mapped to frame. Must be aligned to
- * 			PAGE_SIZE.
- * @param frame		Frame to be released.
- *
- */
-void elf_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
-{
-	elf_segment_header_t *entry = area->backend_data.segment;
-	uintptr_t start_anon;
-
-	ASSERT(page_table_locked(area->as));
-	ASSERT(mutex_locked(&area->lock));
-
-	ASSERT(page >= ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE));
-	ASSERT(page < entry->p_vaddr + entry->p_memsz);
-
-	start_anon = entry->p_vaddr + entry->p_filesz;
-
-	if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) {
-		if (entry->p_flags & PF_W) {
-			/*
-			 * Free the frame with the copy of writable segment
-			 * data.
-			 */
-			frame_free(frame);
-		}
-	} else {
-		/*
-		 * The frame is either anonymous memory or the mixed case (i.e.
-		 * lower part is backed by the ELF image and the upper is
-		 * anonymous). In any case, a frame needs to be freed.
-		 */
-		frame_free(frame);
-	}
+	return true;
 }
 
@@ -356,4 +205,215 @@
 }
 
+void elf_destroy(as_area_t *area)
+{
+	size_t nonanon_pages = elf_nonanon_pages_get(area);
+
+	if (area->pages > nonanon_pages)
+		reserve_free(area->pages - nonanon_pages);
+}
+
+/** Service a page fault in the ELF backend address space area.
+ *
+ * The address space area and page tables must be already locked.
+ *
+ * @param area		Pointer to the address space area.
+ * @param addr		Faulting virtual address.
+ * @param access	Access mode that caused the fault (i.e.
+ * 			read/write/exec).
+ *
+ * @return		AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK
+ * 			on success (i.e. serviced).
+ */
+int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
+{
+	elf_header_t *elf = area->backend_data.elf;
+	elf_segment_header_t *entry = area->backend_data.segment;
+	btree_node_t *leaf;
+	uintptr_t base, frame, page, start_anon;
+	size_t i;
+	bool dirty = false;
+
+	ASSERT(page_table_locked(AS));
+	ASSERT(mutex_locked(&area->lock));
+
+	if (!as_area_check_access(area, access))
+		return AS_PF_FAULT;
+	
+	if (addr < ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE))
+		return AS_PF_FAULT;
+	
+	if (addr >= entry->p_vaddr + entry->p_memsz)
+		return AS_PF_FAULT;
+	
+	i = (addr - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH;
+	base = (uintptr_t)
+	    (((void *) elf) + ALIGN_DOWN(entry->p_offset, PAGE_SIZE));
+
+	/* Virtual address of faulting page*/
+	page = ALIGN_DOWN(addr, PAGE_SIZE);
+
+	/* Virtual address of the end of initialized part of segment */
+	start_anon = entry->p_vaddr + entry->p_filesz;
+
+	if (area->sh_info) {
+		bool found = false;
+
+		/*
+		 * The address space area is shared.
+		 */
+		
+		mutex_lock(&area->sh_info->lock);
+		frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
+		    page - area->base, &leaf);
+		if (!frame) {
+			unsigned int i;
+
+			/*
+			 * Workaround for valid NULL address.
+			 */
+
+			for (i = 0; i < leaf->keys; i++) {
+				if (leaf->key[i] == page - area->base) {
+					found = true;
+					break;
+				}
+			}
+		}
+		if (frame || found) {
+			frame_reference_add(ADDR2PFN(frame));
+			page_mapping_insert(AS, addr, frame,
+			    as_area_get_flags(area));
+			if (!used_space_insert(area, page, 1))
+				panic("Cannot insert used space.");
+			mutex_unlock(&area->sh_info->lock);
+			return AS_PF_OK;
+		}
+	}
+
+	/*
+	 * The area is either not shared or the pagemap does not contain the
+	 * mapping.
+	 */
+	if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) {
+		/*
+		 * Initialized portion of the segment. The memory is backed
+		 * directly by the content of the ELF image. Pages are
+		 * only copied if the segment is writable so that there
+		 * can be more instantions of the same memory ELF image
+		 * used at a time. Note that this could be later done
+		 * as COW.
+		 */
+		if (entry->p_flags & PF_W) {
+			frame = (uintptr_t)frame_alloc_noreserve(ONE_FRAME, 0);
+			memcpy((void *) PA2KA(frame),
+			    (void *) (base + i * FRAME_SIZE), FRAME_SIZE);
+			if (entry->p_flags & PF_X) {
+				smc_coherence_block((void *) PA2KA(frame),
+				    FRAME_SIZE);
+			}
+			dirty = true;
+		} else {
+			frame = KA2PA(base + i * FRAME_SIZE);
+		}	
+	} else if (page >= start_anon) {
+		/*
+		 * This is the uninitialized portion of the segment.
+		 * It is not physically present in the ELF image.
+		 * To resolve the situation, a frame must be allocated
+		 * and cleared.
+		 */
+		frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);
+		memsetb((void *) PA2KA(frame), FRAME_SIZE, 0);
+		dirty = true;
+	} else {
+		size_t pad_lo, pad_hi;
+		/*
+		 * The mixed case.
+		 *
+		 * The middle part is backed by the ELF image and
+		 * the lower and upper parts are anonymous memory.
+		 * (The segment can be and often is shorter than 1 page).
+		 */
+		if (page < entry->p_vaddr)
+			pad_lo = entry->p_vaddr - page;
+		else
+			pad_lo = 0;
+
+		if (start_anon < page + PAGE_SIZE)
+			pad_hi = page + PAGE_SIZE - start_anon;
+		else
+			pad_hi = 0;
+
+		frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);
+		memcpy((void *) (PA2KA(frame) + pad_lo),
+		    (void *) (base + i * FRAME_SIZE + pad_lo),
+		    FRAME_SIZE - pad_lo - pad_hi);
+		if (entry->p_flags & PF_X) {
+			smc_coherence_block((void *) (PA2KA(frame) + pad_lo), 
+			    FRAME_SIZE - pad_lo - pad_hi);
+		}
+		memsetb((void *) PA2KA(frame), pad_lo, 0);
+		memsetb((void *) (PA2KA(frame) + FRAME_SIZE - pad_hi), pad_hi,
+		    0);
+		dirty = true;
+	}
+
+	if (dirty && area->sh_info) {
+		frame_reference_add(ADDR2PFN(frame));
+		btree_insert(&area->sh_info->pagemap, page - area->base,
+		    (void *) frame, leaf);
+	}
+
+	if (area->sh_info)
+		mutex_unlock(&area->sh_info->lock);
+
+	page_mapping_insert(AS, addr, frame, as_area_get_flags(area));
+	if (!used_space_insert(area, page, 1))
+		panic("Cannot insert used space.");
+
+	return AS_PF_OK;
+}
+
+/** Free a frame that is backed by the ELF backend.
+ *
+ * The address space area and page tables must be already locked.
+ *
+ * @param area		Pointer to the address space area.
+ * @param page		Page that is mapped to frame. Must be aligned to
+ * 			PAGE_SIZE.
+ * @param frame		Frame to be released.
+ *
+ */
+void elf_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
+{
+	elf_segment_header_t *entry = area->backend_data.segment;
+	uintptr_t start_anon;
+
+	ASSERT(page_table_locked(area->as));
+	ASSERT(mutex_locked(&area->lock));
+
+	ASSERT(page >= ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE));
+	ASSERT(page < entry->p_vaddr + entry->p_memsz);
+
+	start_anon = entry->p_vaddr + entry->p_filesz;
+
+	if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) {
+		if (entry->p_flags & PF_W) {
+			/*
+			 * Free the frame with the copy of writable segment
+			 * data.
+			 */
+			frame_free_noreserve(frame);
+		}
+	} else {
+		/*
+		 * The frame is either anonymous memory or the mixed case (i.e.
+		 * lower part is backed by the ELF image and the upper is
+		 * anonymous). In any case, a frame needs to be freed.
+		 */
+		frame_free_noreserve(frame);
+	}
+}
+
 /** @}
  */
Index: kernel/generic/src/mm/backend_phys.c
===================================================================
--- kernel/generic/src/mm/backend_phys.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/mm/backend_phys.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -48,12 +48,43 @@
 #include <align.h>
 
-static int phys_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access);
-static void phys_share(as_area_t *area);
+static bool phys_create(as_area_t *);
+static void phys_share(as_area_t *);
+static void phys_destroy(as_area_t *);
+
+static int phys_page_fault(as_area_t *, uintptr_t, pf_access_t);
 
 mem_backend_t phys_backend = {
+	.create = phys_create,
+	.resize = NULL,
+	.share = phys_share,
+	.destroy = phys_destroy,
+
 	.page_fault = phys_page_fault,
 	.frame_free = NULL,
-	.share = phys_share
 };
+
+bool phys_create(as_area_t *area)
+{
+	return true;
+}
+
+/** Share address space area backed by physical memory.
+ *
+ * Do actually nothing as sharing of address space areas
+ * that are backed up by physical memory is very easy.
+ * Note that the function must be defined so that
+ * as_area_share() will succeed.
+ */
+void phys_share(as_area_t *area)
+{
+	ASSERT(mutex_locked(&area->as->lock));
+	ASSERT(mutex_locked(&area->lock));
+}
+
+
+void phys_destroy(as_area_t *area)
+{
+	/* Nothing to do. */
+}
 
 /** Service a page fault in the address space area backed by physical memory.
@@ -88,17 +119,4 @@
 }
 
-/** Share address space area backed by physical memory.
- *
- * Do actually nothing as sharing of address space areas
- * that are backed up by physical memory is very easy.
- * Note that the function must be defined so that
- * as_area_share() will succeed.
- */
-void phys_share(as_area_t *area)
-{
-	ASSERT(mutex_locked(&area->as->lock));
-	ASSERT(mutex_locked(&area->lock));
-}
-
 /** @}
  */
Index: kernel/generic/src/mm/frame.c
===================================================================
--- kernel/generic/src/mm/frame.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/mm/frame.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -45,4 +45,5 @@
 #include <typedefs.h>
 #include <mm/frame.h>
+#include <mm/reserve.h>
 #include <mm/as.h>
 #include <panic.h>
@@ -59,4 +60,5 @@
 #include <macros.h>
 #include <config.h>
+#include <str.h>
 
 zones_t zones;
@@ -472,23 +474,25 @@
  * @param frame_idx Frame index relative to zone.
  *
- */
-NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx)
+ * @return          Number of freed frames.
+ *
+ */
+NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx)
 {
 	ASSERT(zone_flags_available(zone->flags));
 	
 	frame_t *frame = &zone->frames[frame_idx];
-	
-	/* Remember frame order */
-	uint8_t order = frame->buddy_order;
+	size_t size = 0;
 	
 	ASSERT(frame->refcount);
 	
 	if (!--frame->refcount) {
-		buddy_system_free(zone->buddy_system, &frame->buddy_link);
-		
+		size = 1 << frame->buddy_order;
+		buddy_system_free(zone->buddy_system, &frame->buddy_link);		
 		/* Update zone information. */
-		zone->free_count += (1 << order);
-		zone->busy_count -= (1 << order);
-	}
+		zone->free_count += size;
+		zone->busy_count -= size;
+	}
+	
+	return size;
 }
 
@@ -516,4 +520,5 @@
 	ASSERT(link);
 	zone->free_count--;
+	reserve_force_alloc(1);
 }
 
@@ -645,5 +650,5 @@
 	for (i = 0; i < cframes; i++) {
 		zones.info[znum].busy_count++;
-		zone_frame_free(&zones.info[znum],
+		(void) zone_frame_free(&zones.info[znum],
 		    pfn - zones.info[znum].base + i);
 	}
@@ -683,5 +688,5 @@
 	/* Free unneeded frames */
 	for (i = count; i < (size_t) (1 << order); i++)
-		zone_frame_free(&zones.info[znum], i + frame_idx);
+		(void) zone_frame_free(&zones.info[znum], i + frame_idx);
 }
 
@@ -695,6 +700,4 @@
  * not to be 2^order size. Once the allocator is running it is no longer
  * possible, merged configuration data occupies more space :-/
- *
- * The function uses
  *
  */
@@ -837,4 +840,7 @@
 			buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link);
 		}
+
+		/* "Unreserve" new frames. */
+		reserve_free(count);
 	} else
 		zone->frames = NULL;
@@ -999,4 +1005,10 @@
 	size_t hint = pzone ? (*pzone) : 0;
 	
+	/*
+	 * If not told otherwise, we must first reserve the memory.
+	 */
+	if (!(flags & FRAME_NO_RESERVE)) 
+		reserve_force_alloc(size);
+
 loop:
 	irq_spinlock_lock(&zones.lock, true);
@@ -1033,4 +1045,6 @@
 		if (flags & FRAME_ATOMIC) {
 			irq_spinlock_unlock(&zones.lock, true);
+			if (!(flags & FRAME_NO_RESERVE))
+				reserve_free(size);
 			return NULL;
 		}
@@ -1088,4 +1102,14 @@
 }
 
+void *frame_alloc(uint8_t order, frame_flags_t flags)
+{
+	return frame_alloc_generic(order, flags, NULL);
+}
+
+void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags)
+{
+	return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL);
+}
+
 /** Free a frame.
  *
@@ -1095,8 +1119,11 @@
  *
  * @param frame Physical Address of of the frame to be freed.
- *
- */
-void frame_free(uintptr_t frame)
-{
+ * @param flags Flags to control memory reservation.
+ *
+ */
+void frame_free_generic(uintptr_t frame, frame_flags_t flags)
+{
+	size_t size;
+	
 	irq_spinlock_lock(&zones.lock, true);
 	
@@ -1106,8 +1133,9 @@
 	pfn_t pfn = ADDR2PFN(frame);
 	size_t znum = find_zone(pfn, 1, 0);
+
 	
 	ASSERT(znum != (size_t) -1);
 	
-	zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
+	size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
 	
 	irq_spinlock_unlock(&zones.lock, true);
@@ -1118,5 +1146,5 @@
 	mutex_lock(&mem_avail_mtx);
 	if (mem_avail_req > 0)
-		mem_avail_req--;
+		mem_avail_req -= min(mem_avail_req, size);
 	
 	if (mem_avail_req == 0) {
@@ -1125,4 +1153,17 @@
 	}
 	mutex_unlock(&mem_avail_mtx);
+	
+	if (!(flags & FRAME_NO_RESERVE))
+		reserve_free(size);
+}
+
+void frame_free(uintptr_t frame)
+{
+	frame_free_generic(frame, 0);
+}
+
+void frame_free_noreserve(uintptr_t frame)
+{
+	frame_free_generic(frame, FRAME_NO_RESERVE);
 }
 
@@ -1355,8 +1396,12 @@
 	bool available = zone_flags_available(flags);
 	
+	uint64_t size;
+	const char *size_suffix;
+	bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);
+	
 	printf("Zone number:       %zu\n", znum);
 	printf("Zone base address: %p\n", (void *) base);
-	printf("Zone size:         %zu frames (%zu KiB)\n", count,
-	    SIZE2KB(FRAMES2SIZE(count)));
+	printf("Zone size:         %zu frames (%" PRIu64 " %s)\n", count,
+	    size, size_suffix);
 	printf("Zone flags:        %c%c%c\n",
 	    available ? 'A' : ' ',
@@ -1365,8 +1410,12 @@
 	
 	if (available) {
-		printf("Allocated space:   %zu frames (%zu KiB)\n",
-		    busy_count, SIZE2KB(FRAMES2SIZE(busy_count)));
-		printf("Available space:   %zu frames (%zu KiB)\n",
-		    free_count, SIZE2KB(FRAMES2SIZE(free_count)));
+		bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix,
+		    false);
+		printf("Allocated space:   %zu frames (%" PRIu64 " %s)\n",
+		    busy_count, size, size_suffix);
+		bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix,
+		    false);
+		printf("Available space:   %zu frames (%" PRIu64 " %s)\n",
+		    free_count, size, size_suffix);
 	}
 }
Index: kernel/generic/src/mm/reserve.c
===================================================================
--- kernel/generic/src/mm/reserve.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
+++ kernel/generic/src/mm/reserve.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2011 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genericmm
+ * @{
+ */
+
+/**
+ * @file
+ * @brief Memory reservations.
+ */
+
+#include <mm/reserve.h>
+#include <mm/frame.h>
+#include <mm/slab.h>
+#include <synch/spinlock.h>
+#include <typedefs.h>
+#include <arch/types.h>
+
+IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(reserve_lock, "reserve_lock");
+static ssize_t reserve = 0;
+
+/** Try to reserve memory.
+ *
+ * This function may not be called from contexts that do not allow memory
+ * reclaiming, such as some invocations of frame_alloc_generic().
+ *
+ * @param size		Number of frames to reserve.
+ * @return		True on success or false otherwise.
+ */
+bool reserve_try_alloc(size_t size)
+{
+	bool reserved = false;
+
+	irq_spinlock_lock(&reserve_lock, true);
+	if (reserve >= 0 && (size_t) reserve >= size) {
+		reserve -= size;
+		reserved = true;
+	} else {
+		/*
+		 * Some reservable frames may be cached by the slab allocator.
+		 * Try to reclaim some reservable memory. Try to be gentle for
+		 * the first time. If it does not help, try to reclaim
+		 * everything.
+		 */
+		irq_spinlock_unlock(&reserve_lock, true);
+		slab_reclaim(0);
+		irq_spinlock_lock(&reserve_lock, true);
+		if (reserve >= 0 && (size_t) reserve >= size) {
+			reserve -= size;
+			reserved = true;
+		} else {
+			irq_spinlock_unlock(&reserve_lock, true);
+			slab_reclaim(SLAB_RECLAIM_ALL);
+			irq_spinlock_lock(&reserve_lock, true);
+			if (reserve >= 0 && (size_t) reserve >= size) {
+				reserve -= size;
+				reserved = true;
+			}
+		}
+	}
+	irq_spinlock_unlock(&reserve_lock, true);
+
+	return reserved;
+}
+
+/** Reserve memory.
+ *
+ * This function simply marks the respective amount of memory frames reserved.
+ * It does not implement any sort of blocking for the case there is not enough
+ * reservable memory. It will simply take the reserve into negative numbers and
+ * leave the blocking up to the allocation phase.
+ *
+ * @param size		Number of frames to reserve.
+ */
+void reserve_force_alloc(size_t size)
+{
+	irq_spinlock_lock(&reserve_lock, true);
+	reserve -= size;
+	irq_spinlock_unlock(&reserve_lock, true);
+}
+
+/** Unreserve memory.
+ *
+ * @param size		Number of frames to unreserve.
+ */
+void reserve_free(size_t size)
+{
+	irq_spinlock_lock(&reserve_lock, true);
+	reserve += size;
+	irq_spinlock_unlock(&reserve_lock, true);
+}
+
+/** @}
+ */
Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ kernel/generic/src/proc/scheduler.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -354,5 +354,5 @@
 	
 	/*
-	 * Through the 'THE' structure, we keep track of THREAD, TASK, CPU, VM
+	 * Through the 'THE' structure, we keep track of THREAD, TASK, CPU, AS
 	 * and preemption counter. At this point THE could be coming either
 	 * from THREAD's or CPU's stack.
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/Makefile.common	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -187,5 +187,5 @@
 
 $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
-	$(LD) -N $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
+	$(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
 ifeq ($(CONFIG_STRIP_BINARIES),y)
 	$(STRIP) $(BINARY)
Index: uspace/app/klog/klog.c
===================================================================
--- uspace/app/klog/klog.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/app/klog/klog.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -118,9 +118,5 @@
 	}
 	
-	/*
-	 * Mode "a" would be definitively much better here, but it is
-	 * not well supported by the FAT driver.
-	 */
-	log = fopen(LOG_FNAME, "w");
+	log = fopen(LOG_FNAME, "a");
 	if (log == NULL)
 		printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
Index: uspace/app/stats/stats.c
===================================================================
--- uspace/app/stats/stats.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/app/stats/stats.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -69,13 +69,19 @@
 	size_t i;
 	for (i = 0; i < count; i++) {
-		uint64_t resmem, virtmem, ucycles, kcycles;
-		char resmem_suffix, virtmem_suffix, usuffix, ksuffix;
-		
-		order_suffix(stats_tasks[i].resmem, &resmem, &resmem_suffix);
-		order_suffix(stats_tasks[i].virtmem, &virtmem, &virtmem_suffix);
+		uint64_t resmem;
+		uint64_t virtmem;
+		uint64_t ucycles;
+		uint64_t kcycles;
+		const char *resmem_suffix;
+		const char *virtmem_suffix;
+		char usuffix;
+		char ksuffix;
+		
+		bin_order_suffix(stats_tasks[i].resmem, &resmem, &resmem_suffix, true);
+		bin_order_suffix(stats_tasks[i].virtmem, &virtmem, &virtmem_suffix, true);
 		order_suffix(stats_tasks[i].ucycles, &ucycles, &usuffix);
 		order_suffix(stats_tasks[i].kcycles, &kcycles, &ksuffix);
 		
-		printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c %8" PRIu64 "%c"
+		printf("%-8" PRIu64 " %7zu %7" PRIu64 "%s %6" PRIu64 "%s"
 		    " %8" PRIu64 "%c %8" PRIu64 "%c %s\n",
 		    stats_tasks[i].task_id, stats_tasks[i].threads,
Index: uspace/app/tester/Makefile
===================================================================
--- uspace/app/tester/Makefile	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/app/tester/Makefile	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -49,4 +49,5 @@
 	loop/loop1.c \
 	mm/malloc1.c \
+	mm/malloc2.c \
 	devs/devman1.c \
 	hw/misc/virtchar1.c \
Index: uspace/app/tester/mm/malloc2.c
===================================================================
--- uspace/app/tester/mm/malloc2.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
+++ uspace/app/tester/mm/malloc2.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011 Jakub Jermar 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include "../tester.h"
+
+const char *test_malloc2(void)
+{
+	int cnt = 0;
+	char *p;
+
+	TPRINTF("Provoking the kernel into overcommitting memory to us...\n");
+	while ((p = malloc(1024 * 1024))) {
+		TPRINTF("%dM ", ++cnt);
+		*p = 'A';
+	}
+	TPRINTF("\nWas refused more memory as expected.\n");
+
+	return NULL;
+}
Index: uspace/app/tester/mm/malloc2.def
===================================================================
--- uspace/app/tester/mm/malloc2.def	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
+++ uspace/app/tester/mm/malloc2.def	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -0,0 +1,6 @@
+{
+	"malloc2",
+	"Memory reservation feature test",
+	&test_malloc2,
+	false	
+},
Index: uspace/app/tester/tester.c
===================================================================
--- uspace/app/tester/tester.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/app/tester/tester.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -62,4 +62,5 @@
 #include "loop/loop1.def"
 #include "mm/malloc1.def"
+#include "mm/malloc2.def"
 #include "hw/serial/serial1.def"
 #include "hw/misc/virtchar1.def"
Index: uspace/app/tester/tester.h
===================================================================
--- uspace/app/tester/tester.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/app/tester/tester.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -78,4 +78,5 @@
 extern const char *test_loop1(void);
 extern const char *test_malloc1(void);
+extern const char *test_malloc2(void);
 extern const char *test_serial1(void);
 extern const char *test_virtchar1(void);
Index: uspace/app/top/screen.c
===================================================================
--- uspace/app/top/screen.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/app/top/screen.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -254,16 +254,16 @@
 	uint64_t used;
 	uint64_t free;
-	char total_suffix;
-	char unavail_suffix;
-	char used_suffix;
-	char free_suffix;
-	
-	order_suffix(data->physmem->total, &total, &total_suffix);
-	order_suffix(data->physmem->unavail, &unavail, &unavail_suffix);
-	order_suffix(data->physmem->used, &used, &used_suffix);
-	order_suffix(data->physmem->free, &free, &free_suffix);
-	
-	printf("memory: %" PRIu64 "%c total, %" PRIu64 "%c unavail, %"
-	    PRIu64 "%c used, %" PRIu64 "%c free", total, total_suffix,
+	const char *total_suffix;
+	const char *unavail_suffix;
+	const char *used_suffix;
+	const char *free_suffix;
+	
+	bin_order_suffix(data->physmem->total, &total, &total_suffix, false);
+	bin_order_suffix(data->physmem->unavail, &unavail, &unavail_suffix, false);
+	bin_order_suffix(data->physmem->used, &used, &used_suffix, false);
+	bin_order_suffix(data->physmem->free, &free, &free_suffix, false);
+	
+	printf("memory: %" PRIu64 "%s total, %" PRIu64 "%s unavail, %"
+	    PRIu64 "%s used, %" PRIu64 "%s free", total, total_suffix,
 	    unavail, unavail_suffix, used, used_suffix, free, free_suffix);
 	screen_newline();
@@ -295,15 +295,15 @@
 		
 		uint64_t resmem;
-		char resmem_suffix;
-		order_suffix(task->resmem, &resmem, &resmem_suffix);
+		const char *resmem_suffix;
+		bin_order_suffix(task->resmem, &resmem, &resmem_suffix, true);
 		
 		uint64_t virtmem;
-		char virtmem_suffix;
-		order_suffix(task->virtmem, &virtmem, &virtmem_suffix);
-		
-		printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c ",
+		const char *virtmem_suffix;
+		bin_order_suffix(task->virtmem, &virtmem, &virtmem_suffix, true);
+		
+		printf("%-8" PRIu64 " %7zu %7" PRIu64 "%s ",
 		    task->task_id, task->threads, resmem, resmem_suffix);
 		print_percent(perc->resmem, 2);
-		printf(" %8" PRIu64 "%c ", virtmem, virtmem_suffix);
+		printf(" %6" PRIu64 "%s ", virtmem, virtmem_suffix);
 		print_percent(perc->virtmem, 2);
 		puts(" ");
Index: uspace/lib/block/libblock.c
===================================================================
--- uspace/lib/block/libblock.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/block/libblock.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -51,4 +51,6 @@
 #include <macros.h>
 #include <mem.h>
+#include <malloc.h>
+#include <stdio.h>
 #include <sys/typefmt.h>
 #include <stacktrace.h>
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/Makefile	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -113,5 +113,6 @@
 	generic/arg_parse.c \
 	generic/sort.c \
-	generic/stats.c
+	generic/stats.c \
+	generic/assert.c \
 
 SOURCES = \
Index: uspace/lib/c/arch/ia32/include/config.h
===================================================================
--- uspace/lib/c/arch/ia32/include/config.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia32/include/config.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -36,6 +36,9 @@
 #define LIBC_ia32_CONFIG_H_
 
-#define PAGE_WIDTH	12
-#define PAGE_SIZE	(1 << PAGE_WIDTH)
+#define PAGE_WIDTH  12
+#define PAGE_SIZE   (1 << PAGE_WIDTH)
+
+#define USER_ADDRESS_SPACE_START_ARCH  UINT32_C(0x00000000)
+#define USER_ADDRESS_SPACE_END_ARCH    UINT32_C(0x7fffffff)
 
 #endif
Index: uspace/lib/c/arch/ia32/include/ddi.h
===================================================================
--- uspace/lib/c/arch/ia32/include/ddi.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia32/include/ddi.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,5 +37,5 @@
 #include <libarch/types.h>
 
-#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
+#define IO_SPACE_BOUNDARY  ((void *) (64 * 1024))
 
 static inline uint8_t pio_read_8(ioport8_t *port)
Index: uspace/lib/c/arch/ia32/include/faddr.h
===================================================================
--- uspace/lib/c/arch/ia32/include/faddr.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia32/include/faddr.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -38,5 +38,5 @@
 #include <libarch/types.h>
 
-#define FADDR(fptr)		((uintptr_t) (fptr))
+#define FADDR(fptr)  ((uintptr_t) (fptr))
 
 #endif
Index: uspace/lib/c/arch/ia32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia32/include/fibril.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia32/include/fibril.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -42,5 +42,5 @@
  * panic sooner or later
  */
-#define SP_DELTA     (12)
+#define SP_DELTA  12
 
 #define context_set(c, _pc, stack, size, ptls) \
@@ -51,6 +51,7 @@
 		(c)->ebp = 0; \
 	} while (0)
-	
-/* We include only registers that must be preserved
+
+/*
+ * We include only registers that must be preserved
  * during function call
  */
Index: uspace/lib/c/arch/ia32/src/stacktrace.c
===================================================================
--- uspace/lib/c/arch/ia32/src/stacktrace.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia32/src/stacktrace.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -35,16 +35,16 @@
  */
 
+#include <libarch/config.h>
 #include <sys/types.h>
 #include <bool.h>
-
 #include <stacktrace.h>
 
-#define FRAME_OFFSET_FP_PREV	0
-#define FRAME_OFFSET_RA		4
+#define FRAME_OFFSET_FP_PREV  0
+#define FRAME_OFFSET_RA       4
 
 bool stacktrace_fp_valid(stacktrace_t *st, uintptr_t fp)
 {
 	(void) st;
-	return fp != 0;
+	return (fp != 0) && (fp <= USER_ADDRESS_SPACE_END_ARCH);
 }
 
Index: uspace/lib/c/arch/ia64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia64/_link.ld.in	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia64/_link.ld.in	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -22,5 +22,6 @@
 	
 	.got : {
-		_gp = .;
+		/* Tell the linker where we expect GP to point. */
+		__gp = .;
 		*(.got .got.*);
 	} :data
Index: uspace/lib/c/arch/ia64/src/entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/entry.s	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia64/src/entry.s	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -39,5 +39,5 @@
 __entry:
 	alloc loc0 = ar.pfs, 0, 1, 2, 0
-	movl gp = _gp
+	movl gp = __gp
 	
 	# Pass PCB pointer as the first argument to __main
Index: uspace/lib/c/arch/ia64/src/thread_entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/thread_entry.s	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/arch/ia64/src/thread_entry.s	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -37,5 +37,5 @@
 	alloc loc0 = ar.pfs, 0, 1, 1, 0
 
-	movl gp = _gp
+	movl gp = __gp
 	
 	#
Index: uspace/lib/c/generic/assert.c
===================================================================
--- uspace/lib/c/generic/assert.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
+++ uspace/lib/c/generic/assert.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stacktrace.h>
+
+void assert_abort(const char *cond, const char *file, unsigned int line)
+{
+	printf("Assertion failed (%s) in file \"%s\", line %u.\n",
+	    cond, file, line);
+	stacktrace_print();
+	abort();
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/async.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -102,4 +102,6 @@
 #include <arch/barrier.h>
 #include <bool.h>
+#include <stdlib.h>
+#include <malloc.h>
 #include "private/async.h"
 
Index: uspace/lib/c/generic/async_sess.c
===================================================================
--- uspace/lib/c/generic/async_sess.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/async_sess.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -105,4 +105,5 @@
 #include <errno.h>
 #include <assert.h>
+#include <async.h>
 #include "private/async_sess.h"
 
Index: uspace/lib/c/generic/errno.c
===================================================================
--- uspace/lib/c/generic/errno.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/errno.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -36,5 +36,10 @@
 #include <fibril.h>
 
-int _errno;
+static fibril_local int fibril_errno;
+
+int *__errno(void)
+{
+	return &fibril_errno;
+}
 
 /** @}
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -43,4 +43,5 @@
 #include <stacktrace.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include "private/async.h"
 
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/io/io.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -173,4 +173,5 @@
 		}
 		*flags = (O_APPEND | O_CREAT) | (plus ? O_RDWR : O_WRONLY);
+		break;
 	default:
 		errno = EINVAL;
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/malloc.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -44,4 +44,5 @@
 #include <mem.h>
 #include <futex.h>
+#include <stdlib.h>
 #include <adt/gcdlcm.h>
 #include "private/malloc.h"
Index: uspace/lib/c/generic/stacktrace.c
===================================================================
--- uspace/lib/c/generic/stacktrace.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/stacktrace.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -61,9 +61,11 @@
 	stacktrace_prepare();
 	stacktrace_print_fp_pc(stacktrace_fp_get(), stacktrace_pc_get());
+	
 	/*
 	 * Prevent the tail call optimization of the previous call by
 	 * making it a non-tail call.
 	 */
-	(void) stacktrace_fp_get();
+	
+	printf("-- end of stack trace --\n");
 }
 
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/generic/str.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -1215,21 +1215,21 @@
 void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
 {
-	if (val > 10000000000000000000ULL) {
-		*rv = val / 1000000000000000000ULL;
+	if (val > UINT64_C(10000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000000);
 		*suffix = 'Z';
-	} else if (val > 1000000000000000000ULL) {
-		*rv = val / 1000000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000);
 		*suffix = 'E';
-	} else if (val > 1000000000000000ULL) {
-		*rv = val / 1000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000)) {
+		*rv = val / UINT64_C(1000000000000);
 		*suffix = 'T';
-	} else if (val > 1000000000000ULL) {
-		*rv = val / 1000000000ULL;
+	} else if (val > UINT64_C(1000000000000)) {
+		*rv = val / UINT64_C(1000000000);
 		*suffix = 'G';
-	} else if (val > 1000000000ULL) {
-		*rv = val / 1000000ULL;
+	} else if (val > UINT64_C(1000000000)) {
+		*rv = val / UINT64_C(1000000);
 		*suffix = 'M';
-	} else if (val > 1000000ULL) {
-		*rv = val / 1000ULL;
+	} else if (val > UINT64_C(1000000)) {
+		*rv = val / UINT64_C(1000);
 		*suffix = 'k';
 	} else {
@@ -1239,4 +1239,31 @@
 }
 
+void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
+    bool fixed)
+{
+	if (val > UINT64_C(1152921504606846976)) {
+		*rv = val / UINT64_C(1125899906842624);
+		*suffix = "EiB";
+	} else if (val > UINT64_C(1125899906842624)) {
+		*rv = val / UINT64_C(1099511627776);
+		*suffix = "TiB";
+	} else if (val > UINT64_C(1099511627776)) {
+		*rv = val / UINT64_C(1073741824);
+		*suffix = "GiB";
+	} else if (val > UINT64_C(1073741824)) {
+		*rv = val / UINT64_C(1048576);
+		*suffix = "MiB";
+	} else if (val > UINT64_C(1048576)) {
+		*rv = val / UINT64_C(1024);
+		*suffix = "KiB";
+	} else {
+		*rv = val;
+		if (fixed)
+			*suffix = "B  ";
+		else
+			*suffix = "B";
+	}
+}
+
 /** @}
  */
Index: uspace/lib/c/include/assert.h
===================================================================
--- uspace/lib/c/include/assert.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/include/assert.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -40,5 +40,5 @@
  *
  * If NDEBUG is not set, the assert() macro
- * evaluates expr and if it is false prints 
+ * evaluates expr and if it is false prints
  * error message and terminate program.
  *
@@ -47,16 +47,10 @@
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #ifndef NDEBUG
 
 #define assert(expr) \
 	do { \
-		if (!(expr)) { \
-			printf("Assertion failed (%s) at file '%s', " \
-			    "line %d.\n", #expr, __FILE__, __LINE__); \
-			abort(); \
-		} \
+		if (!(expr)) \
+			assert_abort(#expr, __FILE__, __LINE__); \
 	} while (0)
 
@@ -67,4 +61,7 @@
 #endif /* NDEBUG */
 
+extern void assert_abort(const char *, const char *, unsigned int)
+    __attribute__((noreturn));
+
 #endif
 
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/include/errno.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -39,7 +39,7 @@
 #include <fibril.h>
 
-#define errno _errno
+#define errno  (*(__errno()))
 
-extern int _errno;
+extern int *__errno(void) __attribute__((const));
 
 #define EMFILE        (-18)
Index: uspace/lib/c/include/fibril_synch.h
===================================================================
--- uspace/lib/c/include/fibril_synch.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/include/fibril_synch.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -36,12 +36,12 @@
 #define LIBC_FIBRIL_SYNCH_H_
 
-#include <async.h>
 #include <fibril.h>
 #include <adt/list.h>
 #include <libarch/tls.h>
 #include <sys/time.h>
+#include <bool.h>
 
 typedef struct {
-	fibril_owner_info_t oi;		/* Keep this the first thing. */
+	fibril_owner_info_t oi;  /**< Keep this the first thing. */
 	int counter;
 	link_t waiters;
@@ -64,5 +64,5 @@
 
 typedef struct {
-	fibril_owner_info_t oi;	/* Keep this the first thing. */
+	fibril_owner_info_t oi;  /**< Keep this the first thing. */
 	unsigned writers;
 	unsigned readers;
Index: uspace/lib/c/include/macros.h
===================================================================
--- uspace/lib/c/include/macros.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/include/macros.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -39,9 +39,6 @@
 #define max(a, b)  ((a) > (b) ? (a) : (b))
 
-#define SIZE2KB(size)  ((size) >> 10)
-#define SIZE2MB(size)  ((size) >> 20)
-
-#define KB2SIZE(kb)  ((kb) << 10)
-#define MB2SIZE(mb)  ((mb) << 20)
+#define KiB2SIZE(kb)  ((kb) << 10)
+#define MiB2SIZE(mb)  ((mb) << 20)
 
 #define STRING(arg)      STRING_ARG(arg)
Index: uspace/lib/c/include/str.h
===================================================================
--- uspace/lib/c/include/str.h	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/lib/c/include/str.h	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -89,5 +89,6 @@
 extern int str_size_t(const char *, char **, unsigned int, bool, size_t *);
 
-extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix);
+extern void order_suffix(const uint64_t, uint64_t *, char *);
+extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
 
 /*
Index: uspace/srv/devman/devman.c
===================================================================
--- uspace/srv/devman/devman.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/devman/devman.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -39,4 +39,5 @@
 #include <devmap.h>
 #include <str_error.h>
+#include <stdio.h>
 
 #include "devman.h"
Index: uspace/srv/fs/fat/fat_fat.c
===================================================================
--- uspace/srv/fs/fat/fat_fat.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/fs/fat/fat_fat.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -47,4 +47,5 @@
 #include <assert.h>
 #include <fibril_synch.h>
+#include <malloc.h>
 #include <mem.h>
 
Index: uspace/srv/fs/fat/fat_idx.c
===================================================================
--- uspace/srv/fs/fat/fat_idx.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/fs/fat/fat_idx.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -44,4 +44,5 @@
 #include <assert.h>
 #include <fibril_synch.h>
+#include <malloc.h>
 
 /** Each instance of this type describes one interval of freed VFS indices. */
Index: uspace/srv/fs/fat/fat_ops.c
===================================================================
--- uspace/srv/fs/fat/fat_ops.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/fs/fat/fat_ops.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -55,4 +55,5 @@
 #include <sys/mman.h>
 #include <align.h>
+#include <malloc.h>
 
 #define FAT_NODE(node)	((node) ? (fat_node_t *) (node)->data : NULL)
Index: uspace/srv/hw/netif/ne2000/dp8390.c
===================================================================
--- uspace/srv/hw/netif/ne2000/dp8390.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/hw/netif/ne2000/dp8390.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -53,4 +53,5 @@
 #include <byteorder.h>
 #include <errno.h>
+#include <stdio.h>
 #include <libarch/ddi.h>
 #include <net/packet.h>
Index: uspace/srv/loader/arch/ia64/_link.ld.in
===================================================================
--- uspace/srv/loader/arch/ia64/_link.ld.in	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/loader/arch/ia64/_link.ld.in	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -28,5 +28,6 @@
 	
 	.got : {
-		_gp = .;
+		/* Tell the linker where we expect GP to point. */
+		__gp = .;
 		*(.got .got.*);
 	} :data
Index: uspace/srv/ns/clonable.c
===================================================================
--- uspace/srv/ns/clonable.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/ns/clonable.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -78,5 +78,5 @@
 	if (list_empty(&cs_req)) {
 		/* There was no pending connection request. */
-		printf(NAME ": Unexpected clonable server.\n");
+		printf("%s: Unexpected clonable server.\n", NAME);
 		ipc_answer_0(callid, EBUSY);
 		return;
Index: uspace/srv/ns/service.c
===================================================================
--- uspace/srv/ns/service.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/ns/service.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -35,4 +35,6 @@
 #include <assert.h>
 #include <errno.h>
+#include <stdio.h>
+#include <malloc.h>
 #include "service.h"
 #include "ns.h"
Index: uspace/srv/ns/task.c
===================================================================
--- uspace/srv/ns/task.c	(revision 6b40ea7dd1a7cdce929c1950e81a47e4b91a89b7)
+++ uspace/srv/ns/task.c	(revision 30c400582d588fe7571fc86db6dacfdffd30486a)
@@ -39,4 +39,5 @@
 #include <stdio.h>
 #include <macros.h>
+#include <malloc.h>
 #include "task.h"
 #include "ns.h"
