Index: uspace/lib/c/arch/abs32le/src/entry.c
===================================================================
--- uspace/lib/c/arch/abs32le/src/entry.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/abs32le/src/entry.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -37,5 +37,4 @@
 {
 	__main(NULL);
-	__exit();
 }
 
Index: uspace/lib/c/arch/abs32le/src/thread_entry.c
===================================================================
--- uspace/lib/c/arch/abs32le/src/thread_entry.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/abs32le/src/thread_entry.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -30,7 +30,4 @@
  */
 
-#include <unistd.h>
-#include <thread.h>
-
 void __thread_entry(void)
 {
Index: uspace/lib/c/arch/amd64/src/entry.s
===================================================================
--- uspace/lib/c/arch/amd64/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/amd64/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -47,4 +47,2 @@
 	# Pass PCB pointer to __main (no operation)
 	call __main
-
-	call __exit
Index: uspace/lib/c/arch/arm32/src/entry.s
===================================================================
--- uspace/lib/c/arch/arm32/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/arm32/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -42,5 +42,5 @@
 	ldr r0, =ras_page
 	str r2, [r0]
-
+	
 	#
 	# Create the first stack frame.
@@ -50,10 +50,8 @@
 	push {fp, ip, lr, pc}
 	sub fp, ip, #4
-
+	
 	# Pass pcb_ptr to __main as the first argument (in r0)
 	mov r0, r1
 	bl __main
-
-	bl __exit
 
 .data
@@ -62,3 +60,2 @@
 ras_page:
 	.long 0
-
Index: uspace/lib/c/arch/ia32/src/entry.s
===================================================================
--- uspace/lib/c/arch/ia32/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/ia32/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -46,5 +46,5 @@
 	mov %ax, %fs
 	# Do not set %gs, it contains descriptor that can see TLS
-
+	
 	# Detect the mechanism used for making syscalls
 	movl $(INTEL_CPUID_STANDARD), %eax
@@ -58,10 +58,8 @@
 	# Create the first stack frame.
 	#
-	pushl $0 
+	pushl $0
 	movl %esp, %ebp
-
+	
 	# Pass the PCB pointer to __main as the first argument
 	pushl %edi
 	call __main
-
-	call __exit
Index: uspace/lib/c/arch/ia64/src/entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/ia64/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -40,8 +40,6 @@
 	alloc loc0 = ar.pfs, 0, 1, 2, 0
 	movl gp = _gp
-
+	
 	# Pass PCB pointer as the first argument to __main
 	mov out0 = r2
 	br.call.sptk.many b0 = __main
-0:
-	br.call.sptk.many b0 = __exit
Index: uspace/lib/c/arch/mips32/src/entry.s
===================================================================
--- uspace/lib/c/arch/mips32/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/mips32/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -56,7 +56,4 @@
 	jal __main
 	nop
-	
-	jal __exit
-	nop
 .end
 
Index: uspace/lib/c/arch/ppc32/src/entry.s
===================================================================
--- uspace/lib/c/arch/ppc32/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/ppc32/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -44,9 +44,7 @@
 	stw %r3, 0(%r1)
 	stwu %r1, -16(%r1)
-
+	
 	# Pass the PCB pointer to __main() as the first argument.
 	# The first argument is passed in r3.
 	mr %r3, %r6
 	bl __main
-
-	bl __exit
Index: uspace/lib/c/arch/sparc64/src/entry.s
===================================================================
--- uspace/lib/c/arch/sparc64/src/entry.s	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/arch/sparc64/src/entry.s	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -45,5 +45,5 @@
 	flushw
 	add %g0, -0x7ff, %fp
-
+	
 	# Pass pcb_ptr as the first argument to __main()
 	mov %i1, %o0
@@ -51,5 +51,2 @@
 	call __main
 	or %l7, %lo(_gp), %l7
-
-	call __exit
-	nop
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/async.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -42,9 +42,4 @@
  * You should be able to write very simple multithreaded programs, the async
  * framework will automatically take care of most synchronization problems.
- *
- * Default semantics:
- * - async_send_*(): Send asynchronously. If the kernel refuses to send
- *                   more messages, [ try to get responses from kernel, if
- *                   nothing found, might try synchronous ]
  *
  * Example of use (pseudo C):
@@ -127,6 +122,6 @@
 
 /**
- * Structures of this type are used to group information about a call and a
- * message queue link.
+ * Structures of this type are used to group information about
+ * a call and about a message queue link.
  */
 typedef struct {
@@ -156,5 +151,5 @@
 	/** Link to the client tracking structure. */
 	client_t *client;
-
+	
 	/** Messages that should be delivered to this fibril. */
 	link_t msg_queue;
@@ -173,5 +168,5 @@
 
 /** Identifier of the incoming connection handled by the current fibril. */
-fibril_local connection_t *FIBRIL_connection;
+static fibril_local connection_t *FIBRIL_connection;
 
 static void *default_client_data_constructor(void)
@@ -202,10 +197,19 @@
 {
 	assert(FIBRIL_connection);
-
 	return FIBRIL_connection->client->data;
 }
 
-static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
-static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
+/** Default fibril function that gets called to handle new connection.
+ *
+ * This function is defined as a weak symbol - to be redefined in user code.
+ *
+ * @param callid Hash of the incoming call.
+ * @param call   Data of the incoming call.
+ *
+ */
+static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
+{
+	ipc_answer_0(callid, ENOENT);
+}
 
 /**
@@ -213,4 +217,16 @@
  */
 static async_client_conn_t client_connection = default_client_connection;
+
+/** Default fibril function that gets called to handle interrupt notifications.
+ *
+ * This function is defined as a weak symbol - to be redefined in user code.
+ *
+ * @param callid Hash of the incoming call.
+ * @param call   Data of the incoming call.
+ *
+ */
+static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
+{
+}
 
 /**
@@ -224,17 +240,17 @@
 static LIST_INITIALIZE(timeout_list);
 
-#define CLIENT_HASH_TABLE_BUCKETS	32
-#define CONN_HASH_TABLE_BUCKETS		32
-
-static hash_index_t client_hash(unsigned long *key)
+#define CLIENT_HASH_TABLE_BUCKETS  32
+#define CONN_HASH_TABLE_BUCKETS    32
+
+static hash_index_t client_hash(unsigned long key[])
 {
 	assert(key);
-	return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS); 
+	return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
 }
 
 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
 {
-	client_t *cl = hash_table_get_instance(item, client_t, link);
-	return (key[0] == cl->in_task_hash);
+	client_t *client = hash_table_get_instance(item, client_t, link);
+	return (key[0] == client->in_task_hash);
 }
 
@@ -257,8 +273,8 @@
  *
  */
-static hash_index_t conn_hash(unsigned long *key)
+static hash_index_t conn_hash(unsigned long key[])
 {
 	assert(key);
-	return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS);
+	return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
 }
 
@@ -274,6 +290,6 @@
 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
 {
-	connection_t *hs = hash_table_get_instance(item, connection_t, link);
-	return (key[0] == hs->in_phone_hash);
+	connection_t *conn = hash_table_get_instance(item, connection_t, link);
+	return (key[0] == conn->in_phone_hash);
 }
 
@@ -290,5 +306,4 @@
 	free(hash_table_get_instance(item, connection_t, link));
 }
-
 
 /** Operations for the connection hash table. */
@@ -311,9 +326,10 @@
 	link_t *tmp = timeout_list.next;
 	while (tmp != &timeout_list) {
-		awaiter_t *cur;
-		
-		cur = list_get_instance(tmp, awaiter_t, to_event.link);
+		awaiter_t *cur
+		    = list_get_instance(tmp, awaiter_t, to_event.link);
+		
 		if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
 			break;
+		
 		tmp = tmp->next;
 	}
@@ -332,5 +348,5 @@
  *
  * @return False if the call doesn't match any connection.
- *         True if the call was passed to the respective connection fibril.
+ * @return True if the call was passed to the respective connection fibril.
  *
  */
@@ -469,5 +485,5 @@
 			 * the first IPC_M_PHONE_HUNGUP call and continues to
 			 * call async_get_call_timeout(). Repeat
-			 * IPC_M_PHONE_HUNGUP until the caller notices. 
+			 * IPC_M_PHONE_HUNGUP until the caller notices.
 			 */
 			memset(call, 0, sizeof(ipc_call_t));
@@ -476,5 +492,5 @@
 			return conn->close_callid;
 		}
-
+		
 		if (usecs)
 			async_insert_timeout(&conn->wdata);
@@ -514,29 +530,4 @@
 }
 
-/** Default fibril function that gets called to handle new connection.
- *
- * This function is defined as a weak symbol - to be redefined in user code.
- *
- * @param callid Hash of the incoming call.
- * @param call   Data of the incoming call.
- *
- */
-static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
-{
-	ipc_answer_0(callid, ENOENT);
-}
-
-/** Default fibril function that gets called to handle interrupt notifications.
- *
- * This function is defined as a weak symbol - to be redefined in user code.
- *
- * @param callid Hash of the incoming call.
- * @param call   Data of the incoming call.
- *
- */
-static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
-{
-}
-
 /** Wrapper for client connection fibril.
  *
@@ -551,14 +542,11 @@
 static int connection_fibril(void *arg)
 {
-	unsigned long key;
-	client_t *cl;
-	link_t *lnk;
-	bool destroy = false;
-
 	/*
 	 * Setup fibril-local connection pointer.
 	 */
 	FIBRIL_connection = (connection_t *) arg;
-
+	
+	futex_down(&async_futex);
+	
 	/*
 	 * Add our reference for the current connection in the client task
@@ -566,28 +554,35 @@
 	 * hash in a new tracking structure.
 	 */
-	futex_down(&async_futex);
-	key = FIBRIL_connection->in_task_hash;
-	lnk = hash_table_find(&client_hash_table, &key);
+	
+	unsigned long key = FIBRIL_connection->in_task_hash;
+	link_t *lnk = hash_table_find(&client_hash_table, &key);
+	
+	client_t *client;
+	
 	if (lnk) {
-		cl = hash_table_get_instance(lnk, client_t, link);
-		cl->refcnt++;
+		client = hash_table_get_instance(lnk, client_t, link);
+		client->refcnt++;
 	} else {
-		cl = malloc(sizeof(client_t));
-		if (!cl) {
+		client = malloc(sizeof(client_t));
+		if (!client) {
 			ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
 			futex_up(&async_futex);
 			return 0;
 		}
-		cl->in_task_hash = FIBRIL_connection->in_task_hash;
+		
+		client->in_task_hash = FIBRIL_connection->in_task_hash;
+		
 		async_serialize_start();
-		cl->data = async_client_data_create();
+		client->data = async_client_data_create();
 		async_serialize_end();
-		cl->refcnt = 1;
-		hash_table_insert(&client_hash_table, &key, &cl->link);
-	}
+		
+		client->refcnt = 1;
+		hash_table_insert(&client_hash_table, &key, &client->link);
+	}
+	
 	futex_up(&async_futex);
-
-	FIBRIL_connection->client = cl;
-
+	
+	FIBRIL_connection->client = client;
+	
 	/*
 	 * Call the connection handler function.
@@ -599,17 +594,23 @@
 	 * Remove the reference for this client task connection.
 	 */
+	bool destroy;
+	
 	futex_down(&async_futex);
-	if (--cl->refcnt == 0) {
+	
+	if (--client->refcnt == 0) {
 		hash_table_remove(&client_hash_table, &key, 1);
 		destroy = true;
-	}
+	} else
+		destroy = false;
+	
 	futex_up(&async_futex);
-
+	
 	if (destroy) {
-		if (cl->data)
-			async_client_data_destroy(cl->data);
-		free(cl);
-	}
-
+		if (client->data)
+			async_client_data_destroy(client->data);
+		
+		free(client);
+	}
+	
 	/*
 	 * Remove myself from the connection hash table.
@@ -624,8 +625,8 @@
 	 */
 	while (!list_empty(&FIBRIL_connection->msg_queue)) {
-		msg_t *msg;
-		
-		msg = list_get_instance(FIBRIL_connection->msg_queue.next,
-		    msg_t, link);
+		msg_t *msg =
+		    list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
+		    link);
+		
 		list_remove(&msg->link);
 		ipc_answer_0(msg->callid, EHANGUP);
@@ -670,4 +671,5 @@
 		if (callid)
 			ipc_answer_0(callid, ENOMEM);
+		
 		return (uintptr_t) NULL;
 	}
@@ -717,8 +719,8 @@
 static void handle_call(ipc_callid_t callid, ipc_call_t *call)
 {
-	/* Unrouted call - do some default behaviour */
+	/* Unrouted call - take some default action */
 	if ((callid & IPC_CALLID_NOTIFICATION)) {
 		process_notification(callid, call);
-		goto out;
+		return;
 	}
 	
@@ -726,20 +728,16 @@
 	case IPC_M_CONNECT_ME:
 	case IPC_M_CONNECT_ME_TO:
-		/* Open new connection with fibril etc. */
+		/* Open new connection with fibril, etc. */
 		async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
 		    callid, call, client_connection);
-		goto out;
+		return;
 	}
 	
 	/* Try to route the call through the connection hash table */
 	if (route_call(callid, call))
-		goto out;
+		return;
 	
 	/* Unknown call from unknown phone - hang it up */
 	ipc_answer_0(callid, EHANGUP);
-	return;
-	
-out:
-	;
 }
 
@@ -754,12 +752,12 @@
 	link_t *cur = timeout_list.next;
 	while (cur != &timeout_list) {
-		awaiter_t *waiter;
-		
-		waiter = list_get_instance(cur, awaiter_t, to_event.link);
+		awaiter_t *waiter =
+		    list_get_instance(cur, awaiter_t, to_event.link);
+		
 		if (tv_gt(&waiter->to_event.expires, &tv))
 			break;
-
+		
 		cur = cur->next;
-
+		
 		list_remove(&waiter->to_event.link);
 		waiter->to_event.inlist = false;
@@ -788,5 +786,5 @@
 	while (true) {
 		if (fibril_switch(FIBRIL_FROM_MANAGER)) {
-			futex_up(&async_futex); 
+			futex_up(&async_futex);
 			/*
 			 * async_futex is always held when entering a manager
@@ -811,11 +809,10 @@
 				continue;
 			} else
-				timeout = tv_sub(&waiter->to_event.expires,
-				    &tv);
+				timeout = tv_sub(&waiter->to_event.expires, &tv);
 		} else
 			timeout = SYNCH_NO_TIMEOUT;
 		
 		futex_up(&async_futex);
-
+		
 		atomic_inc(&threads_in_ipc_wait);
 		
@@ -825,5 +822,5 @@
 		
 		atomic_dec(&threads_in_ipc_wait);
-
+		
 		if (!callid) {
 			handle_expired_timeouts();
@@ -875,17 +872,14 @@
 /** Initialize the async framework.
  *
- * @return Zero on success or an error code.
- */
-int __async_init(void)
+ */
+void __async_init(void)
 {
 	if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
-	    &client_hash_table_ops) || !hash_table_create(&conn_hash_table,
-	    CONN_HASH_TABLE_BUCKETS, 1, &conn_hash_table_ops)) {
-		return ENOMEM;
-	}
-
-	_async_sess_init();
-	
-	return 0;
+	    &client_hash_table_ops))
+		abort();
+	
+	if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1,
+	    &conn_hash_table_ops))
+		abort();
 }
 
@@ -900,4 +894,5 @@
  * @param retval Value returned in the answer.
  * @param data   Call data of the answer.
+ *
  */
 static void reply_received(void *arg, int retval, ipc_call_t *data)
@@ -947,5 +942,5 @@
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
 {
-	amsg_t *msg = malloc(sizeof(*msg));
+	amsg_t *msg = malloc(sizeof(amsg_t));
 	
 	if (!msg)
@@ -956,5 +951,9 @@
 	
 	msg->wdata.to_event.inlist = false;
-	/* We may sleep in the next method, but it will use its own mechanism */
+	
+	/*
+	 * We may sleep in the next method,
+	 * but it will use its own means
+	 */
 	msg->wdata.active = true;
 	
@@ -987,5 +986,5 @@
     ipc_call_t *dataptr)
 {
-	amsg_t *msg = malloc(sizeof(*msg));
+	amsg_t *msg = malloc(sizeof(amsg_t));
 	
 	if (!msg)
@@ -996,5 +995,9 @@
 	
 	msg->wdata.to_event.inlist = false;
-	/* We may sleep in next method, but it will use its own mechanism */
+	
+	/*
+	 * We may sleep in the next method,
+	 * but it will use its own means
+	 */
 	msg->wdata.active = true;
 	
@@ -1095,5 +1098,5 @@
 void async_usleep(suseconds_t timeout)
 {
-	amsg_t *msg = malloc(sizeof(*msg));
+	amsg_t *msg = malloc(sizeof(amsg_t));
 	
 	if (!msg)
@@ -1307,13 +1310,13 @@
 }
 
-int async_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
-    sysarg_t arg1, sysarg_t arg2, int mode)
+int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
+    sysarg_t arg1, sysarg_t arg2, unsigned int mode)
 {
 	return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
 }
 
-int async_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
+int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
-    int mode)
+    unsigned int mode)
 {
 	return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
@@ -1428,24 +1431,25 @@
 }
 
-/** Wrapper for making IPC_M_SHARE_IN calls using the async framework.
- *
- * @param phoneid	Phone that will be used to contact the receiving side.
- * @param dst		Destination address space area base.
- * @param size		Size of the destination address space area.
- * @param arg		User defined argument.
- * @param flags		Storage where the received flags will be stored. Can be
- *			NULL.
- *
- * @return		Zero on success or a negative error code from errno.h.
+/** Wrapper for IPC_M_SHARE_IN calls using the async framework.
+ *
+ * @param phoneid Phone that will be used to contact the receiving side.
+ * @param dst     Destination address space area base.
+ * @param size    Size of the destination address space area.
+ * @param arg     User defined argument.
+ * @param flags   Storage for the received flags. Can be NULL.
+ *
+ * @return Zero on success or a negative error code from errno.h.
+ *
  */
 int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
-    int *flags)
-{
-	int res;
+    unsigned int *flags)
+{
 	sysarg_t tmp_flags;
-	res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
+	int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
 	    (sysarg_t) size, arg, NULL, &tmp_flags);
+	
 	if (flags)
-		*flags = tmp_flags;
+		*flags = (unsigned int) tmp_flags;
+	
 	return res;
 }
@@ -1453,54 +1457,59 @@
 /** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
  *
- * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
+ * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
  *
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid	Storage where the hash of the IPC_M_SHARE_IN call will
- * 			be stored.
- * @param size		Destination address space area size.	
- *
- * @return		Non-zero on success, zero on failure.
- */
-int async_share_in_receive(ipc_callid_t *callid, size_t *size)
-{
-	ipc_call_t data;
-	
+ * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
+ * @param size   Destination address space area size.
+ *
+ * @return True on success, false on failure.
+ *
+ */
+bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
+{
 	assert(callid);
 	assert(size);
-
+	
+	ipc_call_t data;
 	*callid = async_get_call(&data);
+	
 	if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
-		return 0;
+		return false;
+	
 	*size = (size_t) IPC_GET_ARG2(data);
-	return 1;
+	return true;
 }
 
 /** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
  *
- * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
- *
- * @param callid	Hash of the IPC_M_DATA_READ call to answer.
- * @param src		Source address space base.
- * @param flags		Flags to be used for sharing. Bits can be only cleared.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
- */
-int async_share_in_finalize(ipc_callid_t callid, void *src, int flags)
+ * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
+ *
+ * @param callid Hash of the IPC_M_DATA_READ call to answer.
+ * @param src    Source address space base.
+ * @param flags  Flags to be used for sharing. Bits can be only cleared.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
+ */
+int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
 {
 	return ipc_share_in_finalize(callid, src, flags);
 }
 
-/** Wrapper for making IPC_M_SHARE_OUT calls using the async framework.
- *
- * @param phoneid	Phone that will be used to contact the receiving side.
- * @param src		Source address space area base address.
- * @param flags		Flags to be used for sharing. Bits can be only cleared.
- *
- * @return		Zero on success or a negative error code from errno.h.
- */
-int async_share_out_start(int phoneid, void *src, int flags)
+/** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
+ *
+ * @param phoneid Phone that will be used to contact the receiving side.
+ * @param src     Source address space area base address.
+ * @param flags   Flags to be used for sharing. Bits can be only cleared.
+ *
+ * @return Zero on success or a negative error code from errno.h.
+ *
+ */
+int async_share_out_start(int phoneid, void *src, unsigned int flags)
 {
 	return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
@@ -1510,42 +1519,45 @@
 /** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
  *
- * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
+ * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
  *
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid	Storage where the hash of the IPC_M_SHARE_OUT call will
- * 			be stored.
- * @param size		Storage where the source address space area size will be
- *			stored.
- * @param flags		Storage where the sharing flags will be stored.
- *
- * @return		Non-zero on success, zero on failure.
- */
-int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags)
-{
-	ipc_call_t data;
-	
+ * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
+ * @param size   Storage for the source address space area size.
+ * @param flags  Storage for the sharing flags.
+ *
+ * @return True on success, false on failure.
+ *
+ */
+bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
+{
 	assert(callid);
 	assert(size);
 	assert(flags);
-
+	
+	ipc_call_t data;
 	*callid = async_get_call(&data);
+	
 	if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
-		return 0;
+		return false;
+	
 	*size = (size_t) IPC_GET_ARG2(data);
-	*flags = (int) IPC_GET_ARG3(data);
-	return 1;
+	*flags = (unsigned int) IPC_GET_ARG3(data);
+	return true;
 }
 
 /** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
  *
- * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
- *
- * @param callid	Hash of the IPC_M_DATA_WRITE call to answer.
- * @param dst		Destination address space area base address.	
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+ * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
+ *
+ * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
+ * @param dst    Destination address space area base address.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
  */
 int async_share_out_finalize(ipc_callid_t callid, void *dst)
@@ -1554,12 +1566,12 @@
 }
 
-
-/** Wrapper for making IPC_M_DATA_READ calls using the async framework.
- *
- * @param phoneid	Phone that will be used to contact the receiving side.
- * @param dst		Address of the beginning of the destination buffer.
- * @param size		Size of the destination buffer.
- *
- * @return		Zero on success or a negative error code from errno.h.
+/** Wrapper for IPC_M_DATA_READ calls using the async framework.
+ *
+ * @param phoneid Phone that will be used to contact the receiving side.
+ * @param dst     Address of the beginning of the destination buffer.
+ * @param size    Size of the destination buffer.
+ *
+ * @return Zero on success or a negative error code from errno.h.
+ *
  */
 int async_data_read_start(int phoneid, void *dst, size_t size)
@@ -1571,41 +1583,45 @@
 /** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
  *
- * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
+ * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
  *
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid	Storage where the hash of the IPC_M_DATA_READ call will
- * 			be stored.
- * @param size		Storage where the maximum size will be stored. Can be
- *			NULL.
- *
- * @return		Non-zero on success, zero on failure.
- */
-int async_data_read_receive(ipc_callid_t *callid, size_t *size)
-{
+ * @param callid Storage for the hash of the IPC_M_DATA_READ.
+ * @param size   Storage for the maximum size. Can be NULL.
+ *
+ * @return True on success, false on failure.
+ *
+ */
+bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
+{
+	assert(callid);
+	
 	ipc_call_t data;
-	
-	assert(callid);
-
 	*callid = async_get_call(&data);
+	
 	if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
-		return 0;
+		return false;
+	
 	if (size)
 		*size = (size_t) IPC_GET_ARG2(data);
-	return 1;
+	
+	return true;
 }
 
 /** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
  *
- * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
- *
- * @param callid	Hash of the IPC_M_DATA_READ call to answer.
- * @param src		Source address for the IPC_M_DATA_READ call.
- * @param size		Size for the IPC_M_DATA_READ call. Can be smaller than
- *			the maximum size announced by the sender.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+ * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
+ *
+ * @param callid Hash of the IPC_M_DATA_READ call to answer.
+ * @param src    Source address for the IPC_M_DATA_READ call.
+ * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
+ *               the maximum size announced by the sender.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
  */
 int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
@@ -1647,5 +1663,5 @@
 }
 
-/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
+/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
  *
  * @param phoneid Phone that will be used to contact the receiving side.
@@ -1664,37 +1680,37 @@
 /** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
  *
- * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
+ * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
  *
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
- *               be stored.
- * @param size   Storage where the suggested size will be stored. May be
- *               NULL
- *
- * @return Non-zero on success, zero on failure.
- *
- */
-int async_data_write_receive(ipc_callid_t *callid, size_t *size)
-{
+ * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
+ * @param size   Storage for the suggested size. May be NULL.
+ *
+ * @return True on success, false on failure.
+ *
+ */
+bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
+{
+	assert(callid);
+	
 	ipc_call_t data;
-	
-	assert(callid);
-	
 	*callid = async_get_call(&data);
+	
 	if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
-		return 0;
+		return false;
 	
 	if (size)
 		*size = (size_t) IPC_GET_ARG2(data);
 	
-	return 1;
+	return true;
 }
 
 /** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
  *
- * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
- * so that the user doesn't have to remember the meaning of each IPC argument.
+ * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
+ * calls so that the user doesn't have to remember the meaning of each IPC
+ * argument.
  *
  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
@@ -1792,5 +1808,5 @@
  *
  */
-void async_data_write_void(const int retval)
+void async_data_write_void(sysarg_t retval)
 {
 	ipc_callid_t callid;
Index: uspace/lib/c/generic/async_sess.c
===================================================================
--- uspace/lib/c/generic/async_sess.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/async_sess.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -105,4 +105,5 @@
 #include <errno.h>
 #include <assert.h>
+#include "private/async_sess.h"
 
 /** An inactive open connection. */
@@ -137,6 +138,7 @@
  *
  * Needs to be called prior to any other interface in this file.
- */
-void _async_sess_init(void)
+ *
+ */
+void __async_sess_init(void)
 {
 	fibril_mutex_initialize(&async_sess_mutex);
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -105,5 +105,5 @@
 
 	if (fibril_get_sercount() != 0)
-		core();
+		abort();
 
 	futex_down(&async_futex);
@@ -198,5 +198,5 @@
 	
 	if (fibril_get_sercount() != 0)
-		core();
+		abort();
 
 	futex_down(&async_futex);
@@ -226,5 +226,5 @@
 	
 	if (fibril_get_sercount() != 0)
-		core();
+		abort();
 
 	futex_down(&async_futex);
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/io/io.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -46,4 +46,5 @@
 #include <ipc/devmap.h>
 #include <adt/list.h>
+#include "../private/io.h"
 
 static void _ffillbuf(FILE *stream);
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/libc.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -43,24 +43,29 @@
 #include <stdio.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <malloc.h>
 #include <tls.h>
-#include <thread.h>
 #include <fibril.h>
-#include <as.h>
+#include <task.h>
 #include <loader/pcb.h>
 #include "private/libc.h"
 #include "private/async.h"
+#include "private/async_sess.h"
+#include "private/malloc.h"
+#include "private/io.h"
 
-void _exit(int status)
-{
-	thread_exit(status);
-}
+static bool env_setup = false;
 
 void __main(void *pcb_ptr)
 {
 	/* Initialize user task run-time environment */
-	__heap_init();
+	__malloc_init();
 	__async_init();
+	__async_sess_init();
+	
 	fibril_t *fibril = fibril_setup();
+	if (fibril == NULL)
+		abort();
+	
 	__tcb_set(fibril->tcb);
 	
@@ -68,9 +73,14 @@
 	__pcb = (pcb_t *) pcb_ptr;
 	
+	/* The basic run-time environment is setup */
+	env_setup = true;
+	
 	int argc;
 	char **argv;
 	
-	/* Get command line arguments and initialize
-	   standard input and output */
+	/*
+	 * Get command line arguments and initialize
+	 * standard input and output
+	 */
 	if (__pcb == NULL) {
 		argc = 0;
@@ -84,14 +94,32 @@
 	}
 	
-	/* Run main() and set task return value
-	   according the result */
-	(void) task_retval(main(argc, argv));
+	/*
+	 * Run main() and set task return value
+	 * according the result
+	 */
+	int retval = main(argc, argv);
+	exit(retval);
 }
 
-void __exit(void)
+void exit(int status)
 {
-	__stdio_done();
-	fibril_teardown(__tcb_get()->fibril_data);
-	_exit(0);
+	if (env_setup) {
+		__stdio_done();
+		task_retval(status);
+		fibril_teardown(__tcb_get()->fibril_data);
+	}
+	
+	__SYSCALL1(SYS_TASK_EXIT, false);
+	
+	/* Unreachable */
+	while (1);
+}
+
+void abort(void)
+{
+	__SYSCALL1(SYS_TASK_EXIT, true);
+	
+	/* Unreachable */
+	while (1);
 }
 
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/malloc.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -45,4 +45,5 @@
 #include <futex.h>
 #include <adt/gcdlcm.h>
+#include "private/malloc.h"
 
 /* Magic used in heap headers. */
@@ -215,25 +216,22 @@
 /** Initialize the heap allocator
  *
- * Find how much physical memory we have and create
- * the heap management structures that mark the whole
- * physical memory as a single free block.
- *
- */
-void __heap_init(void)
-{
-	futex_down(&malloc_futex);
-	
-	if (as_area_create((void *) &_heap, PAGE_SIZE,
-	    AS_AREA_WRITE | AS_AREA_READ)) {
-		heap_pages = 1;
-		heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN);
-		heap_end =
-		    (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN);
-		
-		/* Make the entire area one large block. */
-		block_init(heap_start, heap_end - heap_start, true);
-	}
-	
-	futex_up(&malloc_futex);
+ * Create initial heap memory area. This routine is
+ * only called from libc initialization, thus we do not
+ * take any locks.
+ *
+ */
+void __malloc_init(void)
+{
+	if (!as_area_create((void *) &_heap, PAGE_SIZE,
+	    AS_AREA_WRITE | AS_AREA_READ))
+		abort();
+	
+	heap_pages = 1;
+	heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN);
+	heap_end =
+	    (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN);
+	
+	/* Make the entire area one large block. */
+	block_init(heap_start, heap_end - heap_start, true);
 }
 
Index: uspace/lib/c/generic/private/async.h
===================================================================
--- uspace/lib/c/generic/private/async.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/private/async.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -79,5 +79,5 @@
 } awaiter_t;
 
-extern int __async_init(void);
+extern void __async_init(void);
 extern void async_insert_timeout(awaiter_t *);
 
Index: uspace/lib/c/generic/private/async_sess.h
===================================================================
--- uspace/lib/c/generic/private/async_sess.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
+++ uspace/lib/c/generic/private/async_sess.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -0,0 +1,43 @@
+/*
+ * 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
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_PRIVATE_ASYNC_SESS_H_
+#define LIBC_PRIVATE_ASYNC_SESS_H_
+
+extern void __async_sess_init(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/generic/private/io.h
===================================================================
--- uspace/lib/c/generic/private/io.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
+++ uspace/lib/c/generic/private/io.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -0,0 +1,46 @@
+/*
+ * 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
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_PRIVATE_IO_H_
+#define LIBC_PRIVATE_IO_H_
+
+#include <ipc/vfs.h>
+
+extern void __stdio_init(int filc, fdi_node_t *filv[]);
+extern void __stdio_done(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/generic/private/libc.h
===================================================================
--- uspace/lib/c/generic/private/libc.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/private/libc.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -37,6 +37,5 @@
 
 extern int main(int, char *[]);
-extern void __main(void *);
-extern void __exit(void);
+extern void __main(void *) __attribute__((noreturn));
 
 #endif
Index: uspace/lib/c/generic/private/malloc.h
===================================================================
--- uspace/lib/c/generic/private/malloc.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
+++ uspace/lib/c/generic/private/malloc.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -0,0 +1,43 @@
+/*
+ * 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
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_PRIVATE_MALLOC_H_
+#define LIBC_PRIVATE_MALLOC_H_
+
+extern void __malloc_init(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/generic/private/thread.h
===================================================================
--- uspace/lib/c/generic/private/thread.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
+++ uspace/lib/c/generic/private/thread.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -0,0 +1,46 @@
+/*
+ * 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
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_PRIVATE_THREAD_H_
+#define LIBC_PRIVATE_THREAD_H_
+
+#include <kernel/proc/uarg.h>
+
+extern void __thread_entry(void);
+extern void __thread_main(uspace_arg_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/generic/thread.c
===================================================================
--- uspace/lib/c/generic/thread.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/generic/thread.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -31,5 +31,5 @@
  */
 /** @file
- */ 
+ */
 
 #include <thread.h>
@@ -41,4 +41,5 @@
 #include <str.h>
 #include <async.h>
+#include "private/thread.h"
 
 #ifndef THREAD_INITIAL_STACK_PAGES_NO
@@ -50,25 +51,27 @@
  * This function is called from __thread_entry() and is used
  * to call the thread's implementing function and perform cleanup
- * and exit when thread returns back. Do not call this function
- * directly.
+ * and exit when thread returns back.
  *
  * @param uarg Pointer to userspace argument structure.
+ *
  */
 void __thread_main(uspace_arg_t *uarg)
 {
-	fibril_t *f;
-
-	f = fibril_setup();
-	__tcb_set(f->tcb);
-
+	fibril_t *fibril = fibril_setup();
+	if (fibril == NULL)
+		thread_exit(0);
+	
+	__tcb_set(fibril->tcb);
+	
 	uarg->uspace_thread_function(uarg->uspace_thread_arg);
-	/* XXX: we cannot free the userspace stack while running on it */
-//	free(uarg->uspace_stack);
-//	free(uarg);
-
+	/* XXX: we cannot free the userspace stack while running on it
+		free(uarg->uspace_stack);
+		free(uarg);
+	*/
+	
 	/* If there is a manager, destroy it */
 	async_destroy_manager();
-	fibril_teardown(f);
-
+	fibril_teardown(fibril);
+	
 	thread_exit(0);
 }
@@ -127,10 +130,12 @@
  *
  * @param status Exit status. Currently not used.
+ *
  */
 void thread_exit(int status)
 {
 	__SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status);
-	for (;;)
-		;
+	
+	/* Unreachable */
+	while (1);
 }
 
Index: uspace/lib/c/include/async.h
===================================================================
--- uspace/lib/c/include/async.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/async.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -57,15 +57,11 @@
 extern atomic_t threads_in_ipc_wait;
 
+#define async_manager() \
+	fibril_switch(FIBRIL_TO_MANAGER)
+
+#define async_get_call(data) \
+	async_get_call_timeout(data, 0)
+
 extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t);
-
-static inline ipc_callid_t async_get_call(ipc_call_t *data)
-{
-	return async_get_call_timeout(data, 0);
-}
-
-static inline void async_manager(void)
-{
-	fibril_switch(FIBRIL_TO_MANAGER);
-}
 
 /*
@@ -142,7 +138,8 @@
  */
 
-extern int async_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t, int);
-extern int async_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,
-    sysarg_t, sysarg_t, sysarg_t, int);
+extern int async_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
+    unsigned int);
+extern int async_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
+    sysarg_t, sysarg_t, sysarg_t, unsigned int);
 
 /*
@@ -305,9 +302,10 @@
 	async_share_in_start((phoneid), (dst), (size), (arg), (flags))
 
-extern int async_share_in_start(int, void *, size_t, sysarg_t, int *);
-extern int async_share_in_receive(ipc_callid_t *, size_t *);
-extern int async_share_in_finalize(ipc_callid_t, void *, int );
-extern int async_share_out_start(int, void *, int);
-extern int async_share_out_receive(ipc_callid_t *, size_t *, int *);
+extern int async_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
+extern bool async_share_in_receive(ipc_callid_t *, size_t *);
+extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
+
+extern int async_share_out_start(int, void *, unsigned int);
+extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
 extern int async_share_out_finalize(ipc_callid_t, void *);
 
@@ -343,5 +341,5 @@
 
 extern int async_data_read_start(int, void *, size_t);
-extern int async_data_read_receive(ipc_callid_t *, size_t *);
+extern bool async_data_read_receive(ipc_callid_t *, size_t *);
 extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
 
@@ -382,10 +380,10 @@
 
 extern int async_data_write_start(int, const void *, size_t);
-extern int async_data_write_receive(ipc_callid_t *, size_t *);
+extern bool async_data_write_receive(ipc_callid_t *, size_t *);
 extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
 
 extern int async_data_write_accept(void **, const bool, const size_t,
     const size_t, const size_t, size_t *);
-extern void async_data_write_void(const int);
+extern void async_data_write_void(sysarg_t);
 
 extern int async_data_write_forward_fast(int, sysarg_t, sysarg_t, sysarg_t,
Index: uspace/lib/c/include/async_sess.h
===================================================================
--- uspace/lib/c/include/async_sess.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/async_sess.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -45,5 +45,4 @@
 } async_sess_t;
 
-extern void _async_sess_init(void);
 extern void async_session_create(async_sess_t *, int, sysarg_t);
 extern void async_session_destroy(async_sess_t *);
Index: uspace/lib/c/include/byteorder.h
===================================================================
--- uspace/lib/c/include/byteorder.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/byteorder.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -80,8 +80,8 @@
 #endif
 
-#define htons(n)	host2uint16_t_be((n))
-#define htonl(n)	host2uint32_t_be((n))
-#define ntohs(n)	uint16_t_be2host((n))
-#define ntohl(n)	uint32_t_be2host((n))
+#define htons(n)  host2uint16_t_be((n))
+#define htonl(n)  host2uint32_t_be((n))
+#define ntohs(n)  uint16_t_be2host((n))
+#define ntohl(n)  uint32_t_be2host((n))
 
 static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
Index: uspace/lib/c/include/err.h
===================================================================
--- uspace/lib/c/include/err.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/err.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -39,8 +39,8 @@
 
 #define errx(status, fmt, ...) \
-	{ \
+	do { \
 		printf((fmt), ##__VA_ARGS__); \
-		_exit(status); \
-	}
+		exit(status); \
+	} while (0)
 
 #endif
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/errno.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -39,7 +39,7 @@
 #include <fibril.h>
 
+#define errno _errno
+
 extern int _errno;
-
-#define errno _errno
 
 #define EMFILE        (-18)
@@ -57,36 +57,35 @@
 
 /** An API function is called while another blocking function is in progress. */
-#define EINPROGRESS	(-10036)
+#define EINPROGRESS  (-10036)
 
 /** The socket identifier is not valid. */
-#define ENOTSOCK	(-10038)
+#define ENOTSOCK  (-10038)
 
 /** The destination address required. */
-#define EDESTADDRREQ	(-10039)
+#define EDESTADDRREQ  (-10039)
 
 /** Protocol is not supported.  */
-#define EPROTONOSUPPORT	(-10043)
+#define EPROTONOSUPPORT  (-10043)
 
 /** Socket type is not supported. */
-#define ESOCKTNOSUPPORT	(-10044)
+#define ESOCKTNOSUPPORT  (-10044)
 
 /** Protocol family is not supported. */
-#define EPFNOSUPPORT	(-10046)
+#define EPFNOSUPPORT  (-10046)
 
 /** Address family is not supported. */
-#define EAFNOSUPPORT	(-10047)
+#define EAFNOSUPPORT  (-10047)
 
 /** Address is already in use. */
-#define EADDRINUSE	(-10048)
+#define EADDRINUSE  (-10048)
 
 /** The socket is not connected or bound. */
-#define ENOTCONN	(-10057)
+#define ENOTCONN  (-10057)
 
 /** The requested operation was not performed. Try again later. */
-#define EAGAIN		(-11002)
+#define EAGAIN  (-11002)
 
-/** No data.
- */
-#define NO_DATA		(-11004)
+/** No data. */
+#define NO_DATA (-11004)
 
 #endif
Index: uspace/lib/c/include/loader/pcb.h
===================================================================
--- uspace/lib/c/include/loader/pcb.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/loader/pcb.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -52,5 +52,5 @@
 	/** Program entry point. */
 	entry_point_t entry;
-
+	
 	/** Current working directory. */
 	char *cwd;
Index: uspace/lib/c/include/malloc.h
===================================================================
--- uspace/lib/c/include/malloc.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/malloc.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -38,5 +38,4 @@
 #include <sys/types.h>
 
-extern void __heap_init(void);
 extern uintptr_t get_max_heap_addr(void);
 
Index: uspace/lib/c/include/setjmp.h
===================================================================
--- uspace/lib/c/include/setjmp.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/setjmp.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -41,5 +41,5 @@
 
 extern int setjmp(jmp_buf env);
-extern void longjmp(jmp_buf env,int val) __attribute__((__noreturn__));
+extern void longjmp(jmp_buf env, int val) __attribute__((noreturn));
 
 #endif
Index: uspace/lib/c/include/stdlib.h
===================================================================
--- uspace/lib/c/include/stdlib.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/stdlib.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -40,29 +40,13 @@
 #include <stacktrace.h>
 
-#define abort() \
-	do { \
-		stacktrace_print(); \
-		_exit(1); \
-	} while (0)
+#define RAND_MAX  714025
 
-#define core() \
-	*((int *) 0) = 0xbadbad;
-
-#define exit(status)  _exit((status))
-
-#define RAND_MAX  714025
+#define rand()       random()
+#define srand(seed)  srandom(seed)
 
 extern long int random(void);
 extern void srandom(unsigned int seed);
 
-static inline int rand(void)
-{
-	return random();
-}
-
-static inline void srand(unsigned int seed)
-{
-	srandom(seed);
-}
+extern void abort(void) __attribute__((noreturn));
 
 #endif
Index: uspace/lib/c/include/syscall.h
===================================================================
--- uspace/lib/c/include/syscall.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/syscall.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -32,7 +32,7 @@
 /**
  * @file
- * @brief	Syscall function declaration for architectures that don't
- *		inline syscalls or architectures that handle syscalls
- *		according to the number of arguments.
+ * @brief Syscall function declaration for architectures that don't
+ *        inline syscalls or architectures that handle syscalls
+ *        according to the number of arguments.
  */
 
@@ -40,6 +40,6 @@
 #define LIBC_SYSCALL_H_
 
-#ifndef	LIBARCH_SYSCALL_GENERIC
-#error "You can't include this file directly."
+#ifndef LIBARCH_SYSCALL_GENERIC
+	#error You cannot include this file directly
 #endif
 
@@ -47,11 +47,11 @@
 #include <kernel/syscall/syscall.h>
 
-#define __syscall0	__syscall
-#define __syscall1	__syscall
-#define __syscall2	__syscall
-#define __syscall3	__syscall
-#define __syscall4	__syscall
-#define __syscall5	__syscall
-#define __syscall6	__syscall
+#define __syscall0  __syscall
+#define __syscall1  __syscall
+#define __syscall2  __syscall
+#define __syscall3  __syscall
+#define __syscall4  __syscall
+#define __syscall5  __syscall
+#define __syscall6  __syscall
 
 extern sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2,
Index: uspace/lib/c/include/thread.h
===================================================================
--- uspace/lib/c/include/thread.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/thread.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -36,5 +36,4 @@
 #define LIBC_THREAD_H_
 
-#include <kernel/proc/uarg.h>
 #include <libarch/thread.h>
 #include <sys/types.h>
@@ -42,9 +41,6 @@
 typedef uint64_t thread_id_t;
 
-extern void __thread_entry(void);
-extern void __thread_main(uspace_arg_t *);
-
 extern int thread_create(void (*)(void *), void *, const char *, thread_id_t *);
-extern void thread_exit(int) __attribute__ ((noreturn));
+extern void thread_exit(int) __attribute__((noreturn));
 extern void thread_detach(thread_id_t);
 extern int thread_join(thread_id_t);
Index: uspace/lib/c/include/tls.h
===================================================================
--- uspace/lib/c/include/tls.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/tls.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -57,4 +57,5 @@
 extern void tls_free_variant_1(tcb_t *, size_t);
 #endif
+
 #ifdef CONFIG_TLS_VARIANT_2
 extern tcb_t *tls_alloc_variant_2(void **, size_t);
Index: uspace/lib/c/include/unistd.h
===================================================================
--- uspace/lib/c/include/unistd.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/unistd.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -41,5 +41,5 @@
 
 #ifndef NULL
-	#define NULL	((void *) 0)
+	#define NULL  ((void *) 0)
 #endif
 
@@ -74,5 +74,5 @@
 extern int chdir(const char *);
 
-extern void _exit(int) __attribute__((noreturn));
+extern void exit(int) __attribute__((noreturn));
 extern int usleep(useconds_t);
 extern unsigned int sleep(unsigned int);
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/lib/c/include/vfs/vfs.h	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -57,7 +57,4 @@
 extern int unmount(const char *);
 
-extern void __stdio_init(int filc, fdi_node_t *filv[]);
-extern void __stdio_done(void);
-
 extern int open_node(fdi_node_t *, int);
 extern int fd_phone(int);
Index: uspace/srv/bd/ata_bd/ata_bd.c
===================================================================
--- uspace/srv/bd/ata_bd/ata_bd.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/srv/bd/ata_bd/ata_bd.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -265,5 +265,5 @@
 	sysarg_t method;
 	devmap_handle_t dh;
-	int flags;
+	unsigned int flags;
 	int retval;
 	uint64_t ba;
Index: uspace/srv/bd/file_bd/file_bd.c
===================================================================
--- uspace/srv/bd/file_bd/file_bd.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/srv/bd/file_bd/file_bd.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -177,5 +177,5 @@
 	sysarg_t method;
 	size_t comm_size;
-	int flags;
+	unsigned int flags;
 	int retval;
 	uint64_t ba;
Index: uspace/srv/bd/gxe_bd/gxe_bd.c
===================================================================
--- uspace/srv/bd/gxe_bd/gxe_bd.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/srv/bd/gxe_bd/gxe_bd.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -160,5 +160,5 @@
 	sysarg_t method;
 	devmap_handle_t dh;
-	int flags;
+	unsigned int flags;
 	int retval;
 	uint64_t ba;
Index: uspace/srv/bd/part/guid_part/guid_part.c
===================================================================
--- uspace/srv/bd/part/guid_part/guid_part.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/srv/bd/part/guid_part/guid_part.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -315,5 +315,5 @@
 	sysarg_t method;
 	devmap_handle_t dh;
-	int flags;
+	unsigned int flags;
 	int retval;
 	aoff64_t ba;
Index: uspace/srv/bd/part/mbr_part/mbr_part.c
===================================================================
--- uspace/srv/bd/part/mbr_part/mbr_part.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/srv/bd/part/mbr_part/mbr_part.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -393,5 +393,5 @@
 	sysarg_t method;
 	devmap_handle_t dh;
-	int flags;
+	unsigned int flags;
 	int retval;
 	uint64_t ba;
Index: uspace/srv/bd/rd/rd.c
===================================================================
--- uspace/srv/bd/rd/rd.c	(revision fd483ce19e0105317a6482ee61f57f1fe1405d88)
+++ uspace/srv/bd/rd/rd.c	(revision 47b70062180b321b58ca43746901c748ff7a6b2d)
@@ -102,5 +102,5 @@
 	 * Now we wait for the client to send us its communication as_area.
 	 */
-	int flags;
+	unsigned int flags;
 	if (async_share_out_receive(&callid, &comm_size, &flags)) {
 		fs_va = as_get_mappable_page(comm_size);
