Index: uspace/lib/c/generic/ipc.c
===================================================================
--- uspace/lib/c/generic/ipc.c	(revision 503ffceaab0f4c54907677d3399c3ed1363e507f)
+++ uspace/lib/c/generic/ipc.c	(revision 9940ce0abda70ea8d091bd0be88bbccc2059eceb)
@@ -59,5 +59,4 @@
 	struct {
 		ipc_call_t data;
-		int phoneid;
 	} msg;
 } async_call_t;
@@ -91,10 +90,8 @@
 /** Epilogue 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().
- */
-static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
-    async_call_t *call)
+ * @param rc       Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
+ * @param call     Structure returned by ipc_prepare_async().
+ */
+static inline void ipc_finish_async(int rc, async_call_t *call)
 {
 	if (!call) {
@@ -103,5 +100,5 @@
 	}
 	
-	if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
+	if (rc == IPC_CALLRET_FATAL) {
 		/* Call asynchronous handler with error code */
 		if (call->callback)
@@ -124,13 +121,13 @@
  * error code. If the call cannot be temporarily made, it is queued.
  *
- * @param phoneid     Phone handle for the call.
- * @param imethod     Requested interface and method.
- * @param arg1        Service-defined payload argument.
- * @param arg2        Service-defined payload argument.
- * @param arg3        Service-defined payload argument.
- * @param private     Argument to be passed to the answer/error callback.
- * @param callback    Answer or error callback.
- */
-void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
+ * @param phandle   Phone handle for the call.
+ * @param imethod   Requested interface and method.
+ * @param arg1      Service-defined payload argument.
+ * @param arg2      Service-defined payload argument.
+ * @param arg3      Service-defined payload argument.
+ * @param private   Argument to be passed to the answer/error callback.
+ * @param callback  Answer or error callback.
+ */
+void ipc_call_async_fast(cap_handle_t phandle, sysarg_t imethod, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, void *private, ipc_async_callback_t callback)
 {
@@ -139,8 +136,8 @@
 		return;
 	
-	ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
-	    imethod, arg1, arg2, arg3, (sysarg_t) call);
-	
-	ipc_finish_async(callid, phoneid, call);
+	int rc = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phandle, imethod, arg1,
+	    arg2, arg3, (sysarg_t) call);
+	
+	ipc_finish_async(rc, call);
 }
 
@@ -153,15 +150,15 @@
  * error code. If the call cannot be temporarily made, it is queued.
  *
- * @param phoneid     Phone handle for the call.
- * @param imethod     Requested interface and method.
- * @param arg1        Service-defined payload argument.
- * @param arg2        Service-defined payload argument.
- * @param arg3        Service-defined payload argument.
- * @param arg4        Service-defined payload argument.
- * @param arg5        Service-defined payload argument.
- * @param private     Argument to be passed to the answer/error callback.
- * @param callback    Answer or error callback.
- */
-void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
+ * @param phandle   Phone handle for the call.
+ * @param imethod   Requested interface and method.
+ * @param arg1      Service-defined payload argument.
+ * @param arg2      Service-defined payload argument.
+ * @param arg3      Service-defined payload argument.
+ * @param arg4      Service-defined payload argument.
+ * @param arg5      Service-defined payload argument.
+ * @param private   Argument to be passed to the answer/error callback.
+ * @param callback  Answer or error callback.
+ */
+void ipc_call_async_slow(int phandle, 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)
@@ -178,8 +175,8 @@
 	IPC_SET_ARG5(call->msg.data, arg5);
 	
-	ipc_callid_t callid = __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phoneid,
+	int rc = __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phandle,
 	    (sysarg_t) &call->msg.data, (sysarg_t) call);
 	
-	ipc_finish_async(callid, phoneid, call);
+	ipc_finish_async(rc, call);
 }
 
@@ -189,10 +186,10 @@
  * 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.
+ * @param chandle  Handle 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.
@@ -200,20 +197,20 @@
  *
  */
-sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+sysarg_t ipc_answer_fast(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
 {
-	return __SYSCALL6(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2, arg3,
-	    arg4);
+	return __SYSCALL6(SYS_IPC_ANSWER_FAST, chandle, retval, arg1, arg2,
+	    arg3, arg4);
 }
 
 /** 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.
+ * @param chandle  Handle 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.
@@ -221,5 +218,5 @@
  *
  */
-sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+sysarg_t ipc_answer_slow(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
 {
@@ -233,13 +230,12 @@
 	IPC_SET_ARG5(data, arg5);
 	
-	return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
+	return __SYSCALL2(SYS_IPC_ANSWER_SLOW, chandle, (sysarg_t) &data);
 }
 
 /** Handle received answer.
  *
- * @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)
+ * @param data  Call data of the answer.
+ */
+static void handle_answer(ipc_call_t *data)
 {
 	async_call_t *call = data->label;
@@ -255,112 +251,114 @@
 /** 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  Call handle.
+ * @return  Negative error code.
+ */
+cap_handle_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, unsigned int flags)
+{
+	cap_handle_t chandle =
+	    __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
+	
+	/* Handle received answers */
+	if ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED))
+		handle_answer(call);
+	
+	return chandle;
+}
+
+/** 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
- * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
- *
- * @return Hash of the call.
- */
-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 && (call->flags & IPC_CALLID_ANSWERED))
-		handle_answer(callid, call);
-	
-	return callid;
-}
-
-/** 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.
+ *
+ * @return  Call handle.
+ * @return  Negative error code.
+ *
+ */
+cap_handle_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
+{
+	cap_handle_t chandle;
+	
+	do {
+		chandle = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
+	} while ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED));
+	
+	return chandle;
+}
+
+/** Check if there is an IPC call waiting to be picked up.
  *
  * 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;
+ * @param call  Incoming call storage.
+ *
+ * @return  Call handle.
+ * @return  Negative error code.
+ *
+ */
+cap_handle_t ipc_trywait_for_call(ipc_call_t *call)
+{
+	cap_handle_t chandle;
 	
 	do {
-		callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
-	} while (callid && (call->flags & IPC_CALLID_ANSWERED));
-	
-	return callid;
-}
-
-/** Check if there is an IPC call waiting to be picked up.
- *
- * 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,
+		chandle = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
 		    SYNCH_FLAGS_NON_BLOCKING);
-	} while (callid && (call->flags & IPC_CALLID_ANSWERED));
-	
-	return callid;
+	} while ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED));
+	
+	return chandle;
 }
 
 /** Hang up a phone.
  *
- * @param phoneid Handle of the phone to be hung up.
- *
- * @return Zero on success or a negative error code.
- *
- */
-int ipc_hangup(int phoneid)
-{
-	return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
+ * @param phandle  Handle of the phone to be hung up.
+ *
+ * @return  Zero on success or a negative error code.
+ *
+ */
+int ipc_hangup(cap_handle_t phandle)
+{
+	return __SYSCALL1(SYS_IPC_HANGUP, phandle);
 }
 
 /** 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.
- * @param phoneid Phone handle to use for forwarding.
- * @param imethod New interface and method for the forwarded call.
- * @param arg1    New value of the first argument for the forwarded call.
- * @param arg2    New value of the second argument for the forwarded call.
- * @param mode    Flags specifying mode of the forward operation.
- *
- * @return Zero on success or an error code.
- *
- */
-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,
+ * 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 chandle  Handle of the call to forward.
+ * @param phandle  Phone handle to use for forwarding.
+ * @param imethod  New interface and method for the forwarded call.
+ * @param arg1     New value of the first argument for the forwarded call.
+ * @param arg2     New value of the second argument for the forwarded call.
+ * @param mode     Flags specifying mode of the forward operation.
+ *
+ * @return  Zero on success or an error code.
+ *
+ */
+int ipc_forward_fast(cap_handle_t chandle, cap_handle_t phandle,
+    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
+{
+	return __SYSCALL6(SYS_IPC_FORWARD_FAST, chandle, phandle, imethod, arg1,
 	    arg2, mode);
 }
 
-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,
-    unsigned int mode)
+int ipc_forward_slow(cap_handle_t chandle, cap_handle_t phandle,
+    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
+    sysarg_t arg4, sysarg_t arg5, unsigned int mode)
 {
 	ipc_call_t data;
@@ -373,6 +371,6 @@
 	IPC_SET_ARG5(data, arg5);
 	
-	return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
-	    mode);
+	return __SYSCALL4(SYS_IPC_FORWARD_SLOW, chandle, phandle,
+	    (sysarg_t) &data, mode);
 }
 
