Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 4d6629f35433100ab954e68c6ed4fc9bf24accb1)
+++ kernel/generic/src/ipc/sysipc.c	(revision 6636fb199c2da579a541a22014f1a1e5321c2a68)
@@ -260,5 +260,5 @@
 /** Make a call over IPC and wait for reply.
  *
- * @param phone_cap    Phone capability for the call.
+ * @param handle       Phone capability handle for the call.
  * @param data[inout]  Structure with request/reply data.
  * @param priv         Value to be stored in call->priv.
@@ -268,8 +268,8 @@
  *
  */
-int ipc_req_internal(int phone_cap, ipc_data_t *data, sysarg_t priv)
-{
-	phone_t *phone = phone_get_current(phone_cap);
-	if (!phone)
+int ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
+{
+	kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
+	if (!kobj->phone)
 		return ENOENT;
 	
@@ -278,5 +278,5 @@
 	memcpy(call->data.args, data->args, sizeof(data->args));
 	
-	int rc = request_preprocess(call, phone);
+	int rc = request_preprocess(call, kobj->phone);
 	if (!rc) {
 #ifdef CONFIG_UDEBUG
@@ -285,5 +285,5 @@
 
 		ipc_call_hold(call);
-		rc = ipc_call_sync(phone, call);
+		rc = ipc_call_sync(kobj->phone, call);
 		spinlock_lock(&call->forget_lock);
 		bool forgotten = call->forget;
@@ -312,5 +312,6 @@
 				assert(rc == EINTR);
 			}
-			return rc;	
+			kobject_put(kobj);
+			return rc;
 		}
 
@@ -321,4 +322,5 @@
 	memcpy(data->args, call->data.args, sizeof(data->args));
 	ipc_call_free(call);
+	kobject_put(kobj);
 	
 	return EOK;
@@ -346,10 +348,10 @@
  * the generic function sys_ipc_call_async_slow().
  *
- * @param phone_cap  Phone capability for the call.
- * @param imethod    Interface and method of the call.
- * @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 handle   Phone capability handle for the call.
+ * @param imethod  Interface and method of the call.
+ * @param arg1     Service-defined payload argument.
+ * @param arg2     Service-defined payload argument.
+ * @param arg3     Service-defined payload argument.
+ * @param arg4     Service-defined payload argument.
  *
  * @return Call hash on success.
@@ -359,13 +361,15 @@
  *
  */
-sysarg_t sys_ipc_call_async_fast(sysarg_t phone_cap, sysarg_t imethod,
+sysarg_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
     sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
 {
-	phone_t *phone = phone_get_current(phone_cap);
-	if (!phone)
+	kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
+	if (!kobj)
 		return IPC_CALLRET_FATAL;
 	
-	if (check_call_limit(phone))
+	if (check_call_limit(kobj->phone)) {
+		kobject_put(kobj);
 		return IPC_CALLRET_TEMPORARY;
+	}
 	
 	call_t *call = ipc_call_alloc(0);
@@ -382,11 +386,12 @@
 	IPC_SET_ARG5(call->data, 0);
 	
-	int res = request_preprocess(call, phone);
+	int res = request_preprocess(call, kobj->phone);
 	
 	if (!res)
-		ipc_call(phone, call);
+		ipc_call(kobj->phone, call);
 	else
-		ipc_backsend_err(phone, call, res);
-	
+		ipc_backsend_err(kobj->phone, call, res);
+	
+	kobject_put(kobj);
 	return (sysarg_t) call;
 }
@@ -394,18 +399,20 @@
 /** Make an asynchronous IPC call allowing to transmit the entire payload.
  *
- * @param phone_cap  Phone capability for the call.
- * @param data       Userspace address of call data with the request.
+ * @param handle  Phone capability for the call.
+ * @param data    Userspace address of call data with the request.
  *
  * @return See sys_ipc_call_async_fast().
  *
  */
-sysarg_t sys_ipc_call_async_slow(sysarg_t phone_cap, ipc_data_t *data)
-{
-	phone_t *phone = phone_get_current(phone_cap);
-	if (!phone)
+sysarg_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data)
+{
+	kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
+	if (!kobj)
 		return IPC_CALLRET_FATAL;
 
-	if (check_call_limit(phone))
+	if (check_call_limit(kobj->phone)) {
+		kobject_put(kobj);
 		return IPC_CALLRET_TEMPORARY;
+	}
 
 	call_t *call = ipc_call_alloc(0);
@@ -414,14 +421,16 @@
 	if (rc != 0) {
 		ipc_call_free(call);
+		kobject_put(kobj);
 		return (sysarg_t) rc;
 	}
 	
-	int res = request_preprocess(call, phone);
+	int res = request_preprocess(call, kobj->phone);
 	
 	if (!res)
-		ipc_call(phone, call);
+		ipc_call(kobj->phone, call);
 	else
-		ipc_backsend_err(phone, call, res);
-	
+		ipc_backsend_err(kobj->phone, call, res);
+	
+	kobject_put(kobj);
 	return (sysarg_t) call;
 }
@@ -431,16 +440,16 @@
  * Common code for both the fast and the slow version.
  *
- * @param callid     Hash of the call to forward.
- * @param phone_cap  Phone capability to use for forwarding.
- * @param imethod    New interface and method to use 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 arg3       New value of the third argument for the forwarded call.
- * @param arg4       New value of the fourth argument for the forwarded call.
- * @param arg5       New value of the fifth argument for the forwarded call.
- * @param mode       Flags that specify mode of the forward operation.
- * @param slow       If true, arg3, arg4 and arg5 are considered. Otherwise
- *                   the function considers only the fast version arguments:
- *                   i.e. arg1 and arg2.
+ * @param callid   Hash of the call to forward.
+ * @param handle   Phone capability to use for forwarding.
+ * @param imethod  New interface and method to use 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 arg3     New value of the third argument for the forwarded call.
+ * @param arg4     New value of the fourth argument for the forwarded call.
+ * @param arg5     New value of the fifth argument for the forwarded call.
+ * @param mode     Flags that specify mode of the forward operation.
+ * @param slow     If true, arg3, arg4 and arg5 are considered. Otherwise
+ *                 the function considers only the fast version arguments:
+ *                 i.e. arg1 and arg2.
  *
  * @return 0 on succes, otherwise an error code.
@@ -449,5 +458,5 @@
  *
  */
-static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phone_cap,
+static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t handle,
     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
     sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
@@ -465,6 +474,6 @@
 	int rc;
 
-	phone_t *phone = phone_get_current(phone_cap);
-	if (!phone) {
+	kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
+	if (!kobj) {
 		rc = ENOENT;
 		goto error;
@@ -512,5 +521,5 @@
 	}
 	
-	rc = ipc_forward(call, phone, &TASK->answerbox, mode);
+	rc = ipc_forward(call, kobj->phone, &TASK->answerbox, mode);
 	if (rc != EOK) {
 		after_forward = true;
@@ -518,4 +527,5 @@
 	}
 
+	kobject_put(kobj);
 	return EOK;
 
@@ -528,4 +538,6 @@
 		ipc_answer(&TASK->answerbox, call);
 
+	if (kobj)
+		kobject_put(kobj);
 	return rc;
 }
@@ -540,18 +552,18 @@
  * arguments are not set and these values are ignored.
  *
- * @param callid  Hash of the call to forward.
- * @param phoneid Phone handle to use for forwarding.
- * @param imethod New interface and method to use 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 that specify mode of the forward operation.
+ * @param callid   Hash of the call to forward.
+ * @param handle   Phone handle to use for forwarding.
+ * @param imethod  New interface and method to use 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 that specify mode of the forward operation.
  *
  * @return 0 on succes, otherwise an error code.
  *
  */
-sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
+sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t handle,
     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
 {
-	return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
+	return sys_ipc_forward_common(callid, handle, imethod, arg1, arg2, 0, 0,
 	    0, mode, false); 
 }
@@ -567,5 +579,5 @@
  *
  * @param callid  Hash of the call to forward.
- * @param phoneid Phone handle to use for forwarding.
+ * @param handle  Phone handle to use for forwarding.
  * @param data    Userspace address of the new IPC data.
  * @param mode    Flags that specify mode of the forward operation.
@@ -574,5 +586,5 @@
  *
  */
-sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
+sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t handle,
     ipc_data_t *data, unsigned int mode)
 {
@@ -583,5 +595,5 @@
 		return (sysarg_t) rc;
 	
-	return sys_ipc_forward_common(callid, phoneid,
+	return sys_ipc_forward_common(callid, handle,
 	    IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
 	    IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
@@ -681,18 +693,21 @@
 /** Hang up a phone.
  *
- * @param phone_cap  Phone capability of the phone to be hung up.
+ * @param handle  Phone capability handle of the phone to be hung up.
  *
  * @return 0 on success or an error code.
  *
  */
-sysarg_t sys_ipc_hangup(sysarg_t phone_cap)
-{
-	phone_t *phone = phone_get_current(phone_cap);
-	if (!phone)
+sysarg_t sys_ipc_hangup(sysarg_t handle)
+{
+	kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
+	if (!kobj)
 		return ENOENT;
 	
-	if (ipc_phone_hangup(phone))
+	if (ipc_phone_hangup(kobj->phone)) {
+		kobject_put(kobj);
 		return -1;
-	
+	}
+	
+	kobject_put(kobj);
 	return 0;
 }
