Index: uspace/lib/c/generic/ipc.c
===================================================================
--- uspace/lib/c/generic/ipc.c	(revision 6119f247f3183c16bdfe692a5c235f69d6c726ff)
+++ uspace/lib/c/generic/ipc.c	(revision 104776019e8c3fcfc0545665cd8f58eea101d0ca)
@@ -49,12 +49,13 @@
 
 /**
- * Structures of this type are used for keeping track of sent asynchronous calls
- * and queing unsent calls.
+ * Structures of this type are used for keeping track
+ * of sent asynchronous calls and queing unsent calls.
  */
 typedef struct {
 	link_t list;
-
+	
 	ipc_async_callback_t callback;
 	void *private;
+	
 	union {
 		ipc_callid_t callid;
@@ -64,5 +65,7 @@
 		} msg;
 	} u;
-	fid_t fid;	/**< Fibril waiting for sending this call. */
+	
+	/** Fibril waiting for sending this call. */
+	fid_t fid;
 } async_call_t;
 
@@ -71,6 +74,7 @@
 /** List of asynchronous calls that were not accepted by kernel.
  *
- * It is protected by async_futex, because if the call cannot be sent into the
- * kernel, the async framework is used automatically.
+ * Protected by async_futex, because if the call is not accepted
+ * by the kernel, the async framework is used automatically.
+ *
  */
 LIST_INITIALIZE(queued_calls);
@@ -78,36 +82,35 @@
 static atomic_t ipc_futex = FUTEX_INITIALIZER;
 
-/** Make a fast synchronous call.
- *
- * Only three payload arguments can be passed using this function. However, this
- * function is faster than the generic ipc_call_sync_slow() because the payload
- * is passed directly in registers.
- *
- * @param phoneid	Phone handle for the call.
- * @param method	Requested method.
- * @param arg1		Service-defined payload argument.
- * @param arg2		Service-defined payload argument.
- * @param arg3		Service-defined payload argument.
- * @param result1	If non-NULL, the return ARG1 will be stored there.
- * @param result2	If non-NULL, the return ARG2 will be stored there.
- * @param result3	If non-NULL, the return ARG3 will be stored there.
- * @param result4	If non-NULL, the return ARG4 will be stored there.
- * @param result5	If non-NULL, the return ARG5 will be stored there.
- *
- * @return		Negative values represent errors returned by IPC.
- *			Otherwise the RETVAL of the answer is returned.
- */
-int
-ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1, sysarg_t arg2,
-    sysarg_t arg3, sysarg_t *result1, sysarg_t *result2, sysarg_t *result3,
-    sysarg_t *result4, sysarg_t *result5)
+/** Fast synchronous call.
+ *
+ * Only three payload arguments can be passed using this function. However,
+ * this function is faster than the generic ipc_call_sync_slow() because
+ * the payload is passed directly in registers.
+ *
+ * @param phoneid Phone handle for the call.
+ * @param method  Requested method.
+ * @param arg1    Service-defined payload argument.
+ * @param arg2    Service-defined payload argument.
+ * @param arg3    Service-defined payload argument.
+ * @param result1 If non-NULL, the return ARG1 will be stored there.
+ * @param result2 If non-NULL, the return ARG2 will be stored there.
+ * @param result3 If non-NULL, the return ARG3 will be stored there.
+ * @param result4 If non-NULL, the return ARG4 will be stored there.
+ * @param result5 If non-NULL, the return ARG5 will be stored there.
+ *
+ * @return Negative values representing IPC errors.
+ * @return Otherwise the RETVAL of the answer.
+ *
+ */
+int ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1,
+    sysarg_t arg2, sysarg_t arg3, sysarg_t *result1, sysarg_t *result2,
+    sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
 {
 	ipc_call_t resdata;
-	int callres;
-	
-	callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
+	int callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
 	    arg2, arg3, (sysarg_t) &resdata);
 	if (callres)
 		return callres;
+	
 	if (result1)
 		*result1 = IPC_GET_ARG1(resdata);
@@ -120,9 +123,9 @@
 	if (result5)
 		*result5 = IPC_GET_ARG5(resdata);
-
+	
 	return IPC_GET_RETVAL(resdata);
 }
 
-/** Make a synchronous call transmitting 5 arguments of payload.
+/** Synchronous call transmitting 5 arguments of payload.
  *
  * @param phoneid Phone handle for the call.
@@ -139,12 +142,12 @@
  * @param result5 If non-NULL, storage for the fifth return argument.
  *
- * @return Negative value means IPC error.
- *         Otherwise the RETVAL of the answer.
- *
- */
-int
-ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
-    sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *result1,
-    sysarg_t *result2, sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
+ * @return Negative values representing IPC errors.
+ * @return Otherwise the RETVAL of the answer.
+ *
+ */
+int ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
+    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
+    sysarg_t *result1, sysarg_t *result2, sysarg_t *result3, sysarg_t *result4,
+    sysarg_t *result5)
 {
 	ipc_call_t data;
@@ -176,5 +179,5 @@
 }
 
-/** Syscall to send asynchronous message.
+/** Send asynchronous message via syscall.
  *
  * @param phoneid Phone handle for the call.
@@ -184,66 +187,72 @@
  *
  */
-static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
+static ipc_callid_t ipc_call_async_internal(int phoneid, ipc_call_t *data)
 {
 	return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
 }
 
-/** Prolog to ipc_call_async_*() functions.
- *
- * @param private	Argument for the answer/error callback.
- * @param callback	Answer/error callback.
- *
- * @return		New, partially initialized async_call structure or NULL.
+/** Prolog for ipc_call_async_*() functions.
+ *
+ * @param private  Argument for the answer/error callback.
+ * @param callback Answer/error callback.
+ *
+ * @return New, partially initialized async_call structure or NULL.
+ *
  */
 static inline async_call_t *ipc_prepare_async(void *private,
     ipc_async_callback_t callback)
 {
-	async_call_t *call;
-
-	call = malloc(sizeof(*call));
+	async_call_t *call =
+	    (async_call_t *) malloc(sizeof(async_call_t));
 	if (!call) {
 		if (callback)
 			callback(private, ENOMEM, NULL);
+		
 		return NULL;
 	}
+	
 	call->callback = callback;
 	call->private = private;
-
+	
 	return call;
 }
 
-/** Epilogue of ipc_call_async_*() functions.
- *
- * @param callid	Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
- * @param phoneid	Phone handle through which the call was made.
- * @param call		async_call structure returned by ipc_prepare_async().
- * @param can_preempt	If non-zero, the current fibril can be preempted in this
- *			call.
+/** Epilog for ipc_call_async_*() functions.
+ *
+ * @param callid      Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
+ * @param phoneid     Phone handle through which the call was made.
+ * @param call        Structure returned by ipc_prepare_async().
+ * @param can_preempt If true, the current fibril can be preempted
+ *                    in this call.
+ *
  */
 static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
-    async_call_t *call, int can_preempt)
-{
-	if (!call) { /* Nothing to do regardless if failed or not */
+    async_call_t *call, bool can_preempt)
+{
+	if (!call) {
+		/* Nothing to do regardless if failed or not */
 		futex_up(&ipc_futex);
 		return;
 	}
-
+	
 	if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
 		futex_up(&ipc_futex);
+		
 		/* Call asynchronous handler with error code */
 		if (call->callback)
 			call->callback(call->private, ENOENT, NULL);
+		
 		free(call);
 		return;
 	}
-
+	
 	if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
 		futex_up(&ipc_futex);
-
+		
 		call->u.msg.phoneid = phoneid;
 		
 		futex_down(&async_futex);
 		list_append(&call->list, &queued_calls);
-
+		
 		if (can_preempt) {
 			call->fid = fibril_get_id();
@@ -254,14 +263,16 @@
 			futex_up(&async_futex);
 		}
+		
 		return;
 	}
+	
 	call->u.callid = callid;
+	
 	/* Add call to the list of dispatched calls */
 	list_append(&call->list, &dispatched_calls);
 	futex_up(&ipc_futex);
-	
-}
-
-/** Make a fast asynchronous call.
+}
+
+/** Fast asynchronous call.
  *
  * This function can only handle four arguments of payload. It is, however,
@@ -269,7 +280,8 @@
  *
  * Note that this function is a void function.
- * During normal opertation, answering this call will trigger the callback.
- * In case of fatal error, call the callback handler with the proper error code.
- * If the call cannot be temporarily made, queue it.
+ *
+ * During normal operation, answering this call will trigger the callback.
+ * In case of fatal error, the callback handler is called with the proper
+ * error code. If the call cannot be temporarily made, it is queued.
  *
  * @param phoneid     Phone handle for the call.
@@ -281,5 +293,5 @@
  * @param private     Argument to be passed to the answer/error callback.
  * @param callback    Answer or error callback.
- * @param can_preempt If non-zero, the current fibril will be preempted in
+ * @param can_preempt If true, the current fibril will be preempted in
  *                    case the kernel temporarily refuses to accept more
  *                    asynchronous calls.
@@ -288,5 +300,5 @@
 void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private,
-    ipc_async_callback_t callback, int can_preempt)
+    ipc_async_callback_t callback, bool can_preempt)
 {
 	async_call_t *call = NULL;
@@ -299,7 +311,8 @@
 	
 	/*
-	 * We need to make sure that we get callid before another thread
-	 * accesses the queue again.
+	 * We need to make sure that we get callid
+	 * before another thread accesses the queue again.
 	 */
+	
 	futex_down(&ipc_futex);
 	ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
@@ -312,4 +325,5 @@
 				return;
 		}
+		
 		IPC_SET_IMETHOD(call->u.msg.data, imethod);
 		IPC_SET_ARG1(call->u.msg.data, arg1);
@@ -317,19 +331,23 @@
 		IPC_SET_ARG3(call->u.msg.data, arg3);
 		IPC_SET_ARG4(call->u.msg.data, arg4);
+		
 		/*
 		 * To achieve deterministic behavior, we always zero out the
 		 * arguments that are beyond the limits of the fast version.
 		 */
+		
 		IPC_SET_ARG5(call->u.msg.data, 0);
 	}
+	
 	ipc_finish_async(callid, phoneid, call, can_preempt);
 }
 
-/** Make an asynchronous call transmitting the entire payload.
+/** Asynchronous call transmitting the entire payload.
  *
  * Note that this function is a void function.
- * During normal opertation, answering this call will trigger the callback.
- * In case of fatal error, call the callback handler with the proper error code.
- * If the call cannot be temporarily made, queue it.
+ *
+ * During normal operation, answering this call will trigger the callback.
+ * In case of fatal error, the callback handler is called with the proper
+ * error code. If the call cannot be temporarily made, it is queued.
  *
  * @param phoneid     Phone handle for the call.
@@ -342,5 +360,5 @@
  * @param private     Argument to be passed to the answer/error callback.
  * @param callback    Answer or error callback.
- * @param can_preempt If non-zero, the current fibril will be preempted in
+ * @param can_preempt If true, the current fibril will be preempted in
  *                    case the kernel temporarily refuses to accept more
  *                    asynchronous calls.
@@ -349,13 +367,10 @@
 void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
-    ipc_async_callback_t callback, int can_preempt)
-{
-	async_call_t *call;
-	ipc_callid_t callid;
-
-	call = ipc_prepare_async(private, callback);
+    ipc_async_callback_t callback, bool can_preempt)
+{
+	async_call_t *call = ipc_prepare_async(private, callback);
 	if (!call)
 		return;
-
+	
 	IPC_SET_IMETHOD(call->u.msg.data, imethod);
 	IPC_SET_ARG1(call->u.msg.data, arg1);
@@ -364,28 +379,32 @@
 	IPC_SET_ARG4(call->u.msg.data, arg4);
 	IPC_SET_ARG5(call->u.msg.data, arg5);
+	
 	/*
-	 * We need to make sure that we get callid before another thread
-	 * accesses the queue again.
+	 * We need to make sure that we get callid
+	 * before another threadaccesses the queue again.
 	 */
+	
 	futex_down(&ipc_futex);
-	callid = _ipc_call_async(phoneid, &call->u.msg.data);
-
+	ipc_callid_t callid =
+	    ipc_call_async_internal(phoneid, &call->u.msg.data);
+	
 	ipc_finish_async(callid, phoneid, call, can_preempt);
 }
 
-
-/** Answer a received call - fast version.
+/** Answer received call (fast version).
  *
  * The fast answer makes use of passing retval and first four arguments in
  * registers. If you need to return more, use the ipc_answer_slow() instead.
  *
- * @param callid	Hash of the call being answered.
- * @param retval	Return value.
- * @param arg1		First return argument.
- * @param arg2		Second return argument.
- * @param arg3		Third return argument.
- * @param arg4		Fourth return argument.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+ * @param callid Hash of the call being answered.
+ * @param retval Return value.
+ * @param arg1   First return argument.
+ * @param arg2   Second return argument.
+ * @param arg3   Third return argument.
+ * @param arg4   Fourth return argument.
+ *
+ * @return Zero on success.
+ * @return Value from @ref errno.h on failure.
+ *
  */
 sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
@@ -396,15 +415,17 @@
 }
 
-/** Answer a received call - slow full version.
- *
- * @param callid	Hash of the call being answered.
- * @param retval	Return value.
- * @param arg1		First return argument.
- * @param arg2		Second return argument.
- * @param arg3		Third return argument.
- * @param arg4		Fourth return argument.
- * @param arg5		Fifth return argument.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+/** Answer received call (entire payload).
+ *
+ * @param callid Hash of the call being answered.
+ * @param retval Return value.
+ * @param arg1   First return argument.
+ * @param arg2   Second return argument.
+ * @param arg3   Third return argument.
+ * @param arg4   Fourth return argument.
+ * @param arg5   Fifth return argument.
+ *
+ * @return Zero on success.
+ * @return Value from @ref errno.h on failure.
+ *
  */
 sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
@@ -412,5 +433,5 @@
 {
 	ipc_call_t data;
-
+	
 	IPC_SET_RETVAL(data, retval);
 	IPC_SET_ARG1(data, arg1);
@@ -419,30 +440,33 @@
 	IPC_SET_ARG4(data, arg4);
 	IPC_SET_ARG5(data, arg5);
-
+	
 	return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
 }
 
-
-/** Try to dispatch queued calls from the async queue. */
-static void try_dispatch_queued_calls(void)
-{
-	async_call_t *call;
-	ipc_callid_t callid;
-
+/** Try to dispatch queued calls from the async queue.
+ *
+ */
+static void dispatch_queued_calls(void)
+{
 	/** @todo
-	 * Integrate intelligently ipc_futex, so that it is locked during
-	 * ipc_call_async_*(), until it is added to dispatched_calls.
+	 * Integrate intelligently ipc_futex so that it is locked during
+	 * ipc_call_async_*() until it is added to dispatched_calls.
 	 */
+	
 	futex_down(&async_futex);
+	
 	while (!list_empty(&queued_calls)) {
-		call = list_get_instance(queued_calls.next, async_call_t, list);
-		callid = _ipc_call_async(call->u.msg.phoneid,
-		    &call->u.msg.data);
-		if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
+		async_call_t *call =
+		    list_get_instance(queued_calls.next, async_call_t, list);
+		ipc_callid_t callid =
+		    ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
+		
+		if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY)
 			break;
-		}
+		
 		list_remove(&call->list);
-
+		
 		futex_up(&async_futex);
+		
 		if (call->fid)
 			fibril_add_ready(call->fid);
@@ -451,94 +475,114 @@
 			if (call->callback)
 				call->callback(call->private, ENOENT, NULL);
+			
 			free(call);
 		} else {
 			call->u.callid = callid;
+			
 			futex_down(&ipc_futex);
 			list_append(&call->list, &dispatched_calls);
 			futex_up(&ipc_futex);
 		}
+		
 		futex_down(&async_futex);
 	}
+	
 	futex_up(&async_futex);
 }
 
-/** Handle a received answer.
+/** Handle received answer.
  *
  * Find the hash of the answer and call the answer callback.
  *
- * @todo Make it use hash table.
- *
- * @param callid	Hash of the received answer.
- *			The answer has the same hash as the request OR'ed with
- *			the IPC_CALLID_ANSWERED bit.
- * @param data		Call data of the answer.
+ * The answer has the same hash as the request OR'ed with
+ * the IPC_CALLID_ANSWERED bit.
+ *
+ * @todo Use hash table.
+ *
+ * @param callid Hash of the received answer.
+ * @param data   Call data of the answer.
+ *
  */
 static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
 {
+	callid &= ~IPC_CALLID_ANSWERED;
+	
+	futex_down(&ipc_futex);
+	
 	link_t *item;
-	async_call_t *call;
-
-	callid &= ~IPC_CALLID_ANSWERED;
-	
-	futex_down(&ipc_futex);
 	for (item = dispatched_calls.next; item != &dispatched_calls;
 	    item = item->next) {
-		call = list_get_instance(item, async_call_t, list);
+		async_call_t *call =
+		    list_get_instance(item, async_call_t, list);
+		
 		if (call->u.callid == callid) {
 			list_remove(&call->list);
+			
 			futex_up(&ipc_futex);
+			
 			if (call->callback)
-				call->callback(call->private, 
+				call->callback(call->private,
 				    IPC_GET_RETVAL(*data), data);
+			
 			free(call);
 			return;
 		}
 	}
+	
 	futex_up(&ipc_futex);
 }
 
-
-/** Wait for a first call to come.
- *
- * @param call		Storage where the incoming call data will be stored.
- * @param usec		Timeout in microseconds
- * @param flags		Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
- *
- * @return		Hash of the call. Note that certain bits have special
- *			meaning. IPC_CALLID_ANSWERED will be set in an answer
- *			and IPC_CALLID_NOTIFICATION is used for notifications.
- *			
- */
-ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
-{
-	ipc_callid_t callid;
-
-	callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
+/** Wait for first IPC call to come.
+ *
+ * @param call  Incoming call storage.
+ * @param usec  Timeout in microseconds
+ * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
+ *
+ * @return Hash of the call. Note that certain bits have special
+ *         meaning: IPC_CALLID_ANSWERED is set in an answer
+ *         and IPC_CALLID_NOTIFICATION is used for notifications.
+ *
+ */
+ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec,
+    unsigned int flags)
+{
+	ipc_callid_t callid =
+	    __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
+	
 	/* Handle received answers */
 	if (callid & IPC_CALLID_ANSWERED) {
 		handle_answer(callid, call);
-		try_dispatch_queued_calls();
+		dispatch_queued_calls();
 	}
-
+	
 	return callid;
 }
 
-/** Wait some time for an IPC call.
- *
- * The call will return after an answer is received.
- *
- * @param call		Storage where the incoming call data will be stored.
- * @param usec		Timeout in microseconds.
- *
- * @return		Hash of the answer.
- */
-ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
+/** Interrupt one thread of this task from waiting for IPC.
+ *
+ */
+void ipc_poke(void)
+{
+	__SYSCALL0(SYS_IPC_POKE);
+}
+
+/** Wait for first IPC call to come.
+ *
+ * Only requests are returned, answers are processed internally.
+ *
+ * @param call Incoming call storage.
+ * @param usec Timeout in microseconds
+ *
+ * @return Hash of the call.
+ *
+ */
+ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
 {
 	ipc_callid_t callid;
-
+	
 	do {
 		callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
 	} while (callid & IPC_CALLID_ANSWERED);
-
+	
 	return callid;
 }
@@ -546,41 +590,40 @@
 /** Check if there is an IPC call waiting to be picked up.
  *
- * @param call		Storage where the incoming call will be stored.
- * @return		Hash of the answer.
+ * Only requests are returned, answers are processed internally.
+ *
+ * @param call Incoming call storage.
+ *
+ * @return Hash of the call.
+ *
  */
 ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
 {
 	ipc_callid_t callid;
-
+	
 	do {
 		callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
 		    SYNCH_FLAGS_NON_BLOCKING);
 	} while (callid & IPC_CALLID_ANSWERED);
-
+	
 	return callid;
 }
 
-/** Interrupt one thread of this task from waiting for IPC. */
-void ipc_poke(void)
-{
-	__SYSCALL0(SYS_IPC_POKE);
-}
-
-/** Ask destination to do a callback connection.
- *
- * @param phoneid	Phone handle used for contacting the other side.
- * @param arg1		Service-defined argument.
- * @param arg2		Service-defined argument.
- * @param arg3		Service-defined argument.
- * @param taskhash	Storage where the kernel will store an opaque
- *			identifier of the client task.
- * @param phonehash	Storage where the kernel will store an opaque
- *			identifier of the phone that will be used for incoming
- *			calls. This identifier can be used for connection
- *			tracking.
- *
- * @return		Zero on success or a negative error code.
- */
-int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3, 
+/** Request callback connection.
+ *
+ * The @a taskhash and @a phonehash identifiers returned
+ * by the kernel can be used for connection tracking.
+ *
+ * @param phoneid   Phone handle used for contacting the other side.
+ * @param arg1      User defined argument.
+ * @param arg2      User defined argument.
+ * @param arg3      User defined argument.
+ * @param taskhash  Opaque identifier of the client task.
+ * @param phonehash Opaque identifier of the phone that will
+ *                  be used for incoming calls.
+ *
+ * @return Zero on success or a negative error code.
+ *
+ */
+int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
     sysarg_t *taskhash, sysarg_t *phonehash)
 {
@@ -589,46 +632,48 @@
 }
 
-/** Ask through phone for a new connection to some service.
- *
- * @param phoneid	Phone handle used for contacting the other side.
- * @param arg1		User defined argument.
- * @param arg2		User defined argument.
- * @param arg3		User defined argument.
- *
- * @return		New phone handle on success or a negative error code.
- */
-int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3)
+/** Request new connection.
+ *
+ * @param phoneid Phone handle used for contacting the other side.
+ * @param arg1    User defined argument.
+ * @param arg2    User defined argument.
+ * @param arg3    User defined argument.
+ *
+ * @return New phone handle on success or a negative error code.
+ *
+ */
+int ipc_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
 {
 	sysarg_t newphid;
-	int res;
-
-	res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
+	int res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
 	    NULL, NULL, NULL, NULL, &newphid);
 	if (res)
 		return res;
+	
 	return newphid;
 }
 
-/** Ask through phone for a new connection to some service.
+/** Request new connection (blocking)
  *
  * If the connection is not available at the moment, the
- * call will block.
- *
- * @param phoneid	Phone handle used for contacting the other side.
- * @param arg1		User defined argument.
- * @param arg2		User defined argument.
- * @param arg3		User defined argument.
- *
- * @return		New phone handle on success or a negative error code.
- */
-int ipc_connect_me_to_blocking(int phoneid, int arg1, int arg2, int arg3)
+ * call should block. This has to be, however, implemented
+ * on the server side.
+ *
+ * @param phoneid Phone handle used for contacting the other side.
+ * @param arg1    User defined argument.
+ * @param arg2    User defined argument.
+ * @param arg3    User defined argument.
+ *
+ * @return New phone handle on success or a negative error code.
+ *
+ */
+int ipc_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
+    sysarg_t arg3)
 {
 	sysarg_t newphid;
-	int res;
-
-	res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
+	int res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
 	    IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
 	if (res)
 		return res;
+	
 	return newphid;
 }
@@ -636,7 +681,8 @@
 /** Hang up a phone.
  *
- * @param phoneid	Handle of the phone to be hung up.
- *
- * @return		Zero on success or a negative error code.
+ * @param phoneid Handle of the phone to be hung up.
+ *
+ * @return Zero on success or a negative error code.
+ *
  */
 int ipc_hangup(int phoneid)
@@ -646,4 +692,9 @@
 
 /** Forward a received call to another destination.
+ *
+ * For non-system methods, the old method, arg1 and arg2 are rewritten
+ * by the new values. For system methods, the new method, arg1 and arg2
+ * are written to the old arg1, arg2 and arg3, respectivelly. Calls with
+ * immutable methods are forwarded verbatim.
  *
  * @param callid  Hash of the call to forward.
@@ -656,11 +707,7 @@
  * @return Zero on success or an error code.
  *
- * For non-system methods, the old method, arg1 and arg2 are rewritten by the
- * new values. For system methods, the new method, arg1 and arg2 are written 
- * to the old arg1, arg2 and arg3, respectivelly. Calls with immutable 
- * methods are forwarded verbatim.
- */
-int ipc_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
-    sysarg_t arg1, sysarg_t arg2, int mode)
+ */
+int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
+    sysarg_t arg1, sysarg_t arg2, unsigned int mode)
 {
 	return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
@@ -668,8 +715,7 @@
 }
 
-
-int ipc_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
+int ipc_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)
 {
 	ipc_call_t data;
@@ -682,20 +728,21 @@
 	IPC_SET_ARG5(data, arg5);
 	
-	return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data, mode);
-}
-
-/** Wrapper for making IPC_M_SHARE_IN calls.
- *
- * @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.
+	return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
+	    mode);
+}
+
+/** Wrapper for IPC_M_SHARE_IN calls.
+ *
+ * @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 received flags. Can be NULL.
+ *
+ * @return Zero on success or a negative error code from errno.h.
+ *
  */
 int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
-    int *flags)
+    unsigned int *flags)
 {
 	sysarg_t tmp_flags = 0;
@@ -704,5 +751,5 @@
 	
 	if (flags)
-		*flags = tmp_flags;
+		*flags = (unsigned int) tmp_flags;
 	
 	return res;
@@ -711,27 +758,30 @@
 /** Wrapper for answering the IPC_M_SHARE_IN calls.
  *
- * 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 ipc_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 ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
 {
 	return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
 }
 
-/** Wrapper for making IPC_M_SHARE_OUT calls.
- *
- * @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 ipc_share_out_start(int phoneid, void *src, int flags)
+/** Wrapper for IPC_M_SHARE_OUT calls.
+ *
+ * @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 ipc_share_out_start(int phoneid, void *src, unsigned int flags)
 {
 	return ipc_call_sync_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
@@ -741,11 +791,13 @@
 /** Wrapper for answering the IPC_M_SHARE_OUT calls.
  *
- * 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 ipc_share_out_finalize(ipc_callid_t callid, void *dst)
@@ -754,12 +806,12 @@
 }
 
-
-/** Wrapper for making IPC_M_DATA_READ calls.
- *
- * @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.
+ *
+ * @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 ipc_data_read_start(int phoneid, void *dst, size_t size)
@@ -771,13 +823,15 @@
 /** Wrapper for answering the IPC_M_DATA_READ calls.
  *
- * 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 ipc_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
@@ -786,11 +840,12 @@
 }
 
-/** Wrapper for making IPC_M_DATA_WRITE calls.
- *
- * @param phoneid	Phone that will be used to contact the receiving side.
- * @param src		Address of the beginning of the source buffer.
- * @param size		Size of the source buffer.
- *
- * @return		Zero on success or a negative error code from errno.h.
+/** Wrapper for IPC_M_DATA_WRITE calls.
+ *
+ * @param phoneid Phone that will be used to contact the receiving side.
+ * @param src     Address of the beginning of the source buffer.
+ * @param size    Size of the source buffer.
+ *
+ * @return Zero on success or a negative error code from errno.h.
+ *
  */
 int ipc_data_write_start(int phoneid, const void *src, size_t size)
@@ -802,12 +857,14 @@
 /** Wrapper for answering the IPC_M_DATA_WRITE calls.
  *
- * 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.
- * @param dst		Final destination address for the IPC_M_DATA_WRITE call.
- * @param size		Final size for the IPC_M_DATA_WRITE call.
- *
- * @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_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.
+ * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
+ * @param size   Final size for the IPC_M_DATA_WRITE call.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
  */
 int ipc_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
Index: uspace/lib/c/include/ipc/ipc.h
===================================================================
--- uspace/lib/c/include/ipc/ipc.h	(revision 6119f247f3183c16bdfe692a5c235f69d6c726ff)
+++ uspace/lib/c/include/ipc/ipc.h	(revision 104776019e8c3fcfc0545665cd8f58eea101d0ca)
@@ -53,4 +53,5 @@
  * possible, the fast version is used.
  */
+
 #define ipc_call_sync_0_0(phoneid, method) \
 	ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0)
@@ -182,13 +183,11 @@
     sysarg_t *);
 
-extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, uint32_t, int);
-extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, uint32_t);
+extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
 extern void ipc_poke(void);
 
-static inline ipc_callid_t ipc_wait_for_call(ipc_call_t *data)
-{
-	return ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
-}
-
+#define ipc_wait_for_call(data) \
+	ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
+
+extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
 extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
 
@@ -199,4 +198,5 @@
  * to m.
  */
+
 #define ipc_answer_0(callid, retval) \
 	ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
@@ -223,4 +223,5 @@
  * to m.
  */
+
 #define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \
 	ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
@@ -248,19 +249,24 @@
 
 extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
-    sysarg_t, void *, ipc_async_callback_t, int);
+    sysarg_t, void *, ipc_async_callback_t, bool);
 extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
-    sysarg_t, sysarg_t, void *, ipc_async_callback_t, int);
-
-extern int ipc_connect_to_me(int, int, int, int, sysarg_t *, sysarg_t *);
-extern int ipc_connect_me_to(int, int, int, int);
-extern int ipc_connect_me_to_blocking(int, int, int, int);
+    sysarg_t, sysarg_t, void *, ipc_async_callback_t, bool);
+
+extern int ipc_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t *,
+    sysarg_t *);
+extern int ipc_connect_me_to(int, sysarg_t, sysarg_t, sysarg_t);
+extern int ipc_connect_me_to_blocking(int, sysarg_t, sysarg_t, sysarg_t);
+
 extern int ipc_hangup(int);
-extern int ipc_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t, int);
-extern int ipc_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,
-    sysarg_t, sysarg_t, sysarg_t, int);
+
+extern int ipc_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
+    unsigned int);
+extern int ipc_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
+    sysarg_t, sysarg_t, sysarg_t, unsigned int);
 
 /*
  * User-friendly wrappers for ipc_share_in_start().
  */
+
 #define ipc_share_in_start_0_0(phoneid, dst, size) \
 	ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
@@ -272,7 +278,7 @@
 	ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
 
-extern int ipc_share_in_start(int, void *, size_t, sysarg_t, int *);
-extern int ipc_share_in_finalize(ipc_callid_t, void *, int );
-extern int ipc_share_out_start(int, void *, int);
+extern int ipc_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
+extern int ipc_share_in_finalize(ipc_callid_t, void *, unsigned int);
+extern int ipc_share_out_start(int, void *, unsigned int);
 extern int ipc_share_out_finalize(ipc_callid_t, void *);
 extern int ipc_data_read_start(int, void *, size_t);
