Changeset 48bcf49 in mainline for kernel/generic/src/ipc/sysipc.c


Ignore:
Timestamp:
2017-09-28T22:08:15Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6636fb19
Parents:
dd20cbb
Message:

Introduce reference-counted kobjects

Capabilities are thus reduced to task-local names for references to kobjects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/sysipc.c

    rdd20cbb r48bcf49  
    260260/** Make a call over IPC and wait for reply.
    261261 *
    262  * @param phone_cap    Phone capability for the call.
     262 * @param handle       Phone capability handle for the call.
    263263 * @param data[inout]  Structure with request/reply data.
    264264 * @param priv         Value to be stored in call->priv.
     
    268268 *
    269269 */
    270 int ipc_req_internal(int phone_cap, ipc_data_t *data, sysarg_t priv)
    271 {
    272         phone_t *phone = phone_get_current(phone_cap);
    273         if (!phone)
     270int ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
     271{
     272        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     273        if (!kobj->phone)
    274274                return ENOENT;
    275275       
     
    278278        memcpy(call->data.args, data->args, sizeof(data->args));
    279279       
    280         int rc = request_preprocess(call, phone);
     280        int rc = request_preprocess(call, kobj->phone);
    281281        if (!rc) {
    282282#ifdef CONFIG_UDEBUG
     
    285285
    286286                ipc_call_hold(call);
    287                 rc = ipc_call_sync(phone, call);
     287                rc = ipc_call_sync(kobj->phone, call);
    288288                spinlock_lock(&call->forget_lock);
    289289                bool forgotten = call->forget;
     
    312312                                assert(rc == EINTR);
    313313                        }
    314                         return rc;     
     314                        kobject_put(kobj);
     315                        return rc;
    315316                }
    316317
     
    321322        memcpy(data->args, call->data.args, sizeof(data->args));
    322323        ipc_call_free(call);
     324        kobject_put(kobj);
    323325       
    324326        return EOK;
     
    346348 * the generic function sys_ipc_call_async_slow().
    347349 *
    348  * @param phone_cap  Phone capability for the call.
    349  * @param imethod    Interface and method of the call.
    350  * @param arg1       Service-defined payload argument.
    351  * @param arg2       Service-defined payload argument.
    352  * @param arg3       Service-defined payload argument.
    353  * @param arg4       Service-defined payload argument.
     350 * @param handle   Phone capability handle for the call.
     351 * @param imethod  Interface and method of the call.
     352 * @param arg1     Service-defined payload argument.
     353 * @param arg2     Service-defined payload argument.
     354 * @param arg3     Service-defined payload argument.
     355 * @param arg4     Service-defined payload argument.
    354356 *
    355357 * @return Call hash on success.
     
    359361 *
    360362 */
    361 sysarg_t sys_ipc_call_async_fast(sysarg_t phone_cap, sysarg_t imethod,
     363sysarg_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
    362364    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    363365{
    364         phone_t *phone = phone_get_current(phone_cap);
    365         if (!phone)
     366        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     367        if (!kobj)
    366368                return IPC_CALLRET_FATAL;
    367369       
    368         if (check_call_limit(phone))
     370        if (check_call_limit(kobj->phone)) {
     371                kobject_put(kobj);
    369372                return IPC_CALLRET_TEMPORARY;
     373        }
    370374       
    371375        call_t *call = ipc_call_alloc(0);
     
    382386        IPC_SET_ARG5(call->data, 0);
    383387       
    384         int res = request_preprocess(call, phone);
     388        int res = request_preprocess(call, kobj->phone);
    385389       
    386390        if (!res)
    387                 ipc_call(phone, call);
     391                ipc_call(kobj->phone, call);
    388392        else
    389                 ipc_backsend_err(phone, call, res);
    390        
     393                ipc_backsend_err(kobj->phone, call, res);
     394       
     395        kobject_put(kobj);
    391396        return (sysarg_t) call;
    392397}
     
    394399/** Make an asynchronous IPC call allowing to transmit the entire payload.
    395400 *
    396  * @param phone_cap  Phone capability for the call.
    397  * @param data       Userspace address of call data with the request.
     401 * @param handle  Phone capability for the call.
     402 * @param data    Userspace address of call data with the request.
    398403 *
    399404 * @return See sys_ipc_call_async_fast().
    400405 *
    401406 */
    402 sysarg_t sys_ipc_call_async_slow(sysarg_t phone_cap, ipc_data_t *data)
    403 {
    404         phone_t *phone = phone_get_current(phone_cap);
    405         if (!phone)
     407sysarg_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data)
     408{
     409        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     410        if (!kobj)
    406411                return IPC_CALLRET_FATAL;
    407412
    408         if (check_call_limit(phone))
     413        if (check_call_limit(kobj->phone)) {
     414                kobject_put(kobj);
    409415                return IPC_CALLRET_TEMPORARY;
     416        }
    410417
    411418        call_t *call = ipc_call_alloc(0);
     
    414421        if (rc != 0) {
    415422                ipc_call_free(call);
     423                kobject_put(kobj);
    416424                return (sysarg_t) rc;
    417425        }
    418426       
    419         int res = request_preprocess(call, phone);
     427        int res = request_preprocess(call, kobj->phone);
    420428       
    421429        if (!res)
    422                 ipc_call(phone, call);
     430                ipc_call(kobj->phone, call);
    423431        else
    424                 ipc_backsend_err(phone, call, res);
    425        
     432                ipc_backsend_err(kobj->phone, call, res);
     433       
     434        kobject_put(kobj);
    426435        return (sysarg_t) call;
    427436}
     
    431440 * Common code for both the fast and the slow version.
    432441 *
    433  * @param callid     Hash of the call to forward.
    434  * @param phone_cap  Phone capability to use for forwarding.
    435  * @param imethod    New interface and method to use for the forwarded call.
    436  * @param arg1       New value of the first argument for the forwarded call.
    437  * @param arg2       New value of the second argument for the forwarded call.
    438  * @param arg3       New value of the third argument for the forwarded call.
    439  * @param arg4       New value of the fourth argument for the forwarded call.
    440  * @param arg5       New value of the fifth argument for the forwarded call.
    441  * @param mode       Flags that specify mode of the forward operation.
    442  * @param slow       If true, arg3, arg4 and arg5 are considered. Otherwise
    443  *                   the function considers only the fast version arguments:
    444  *                   i.e. arg1 and arg2.
     442 * @param callid   Hash of the call to forward.
     443 * @param handle   Phone capability to use for forwarding.
     444 * @param imethod  New interface and method to use for the forwarded call.
     445 * @param arg1     New value of the first argument for the forwarded call.
     446 * @param arg2     New value of the second argument for the forwarded call.
     447 * @param arg3     New value of the third argument for the forwarded call.
     448 * @param arg4     New value of the fourth argument for the forwarded call.
     449 * @param arg5     New value of the fifth argument for the forwarded call.
     450 * @param mode     Flags that specify mode of the forward operation.
     451 * @param slow     If true, arg3, arg4 and arg5 are considered. Otherwise
     452 *                 the function considers only the fast version arguments:
     453 *                 i.e. arg1 and arg2.
    445454 *
    446455 * @return 0 on succes, otherwise an error code.
     
    449458 *
    450459 */
    451 static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phone_cap,
     460static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t handle,
    452461    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    453462    sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
     
    465474        int rc;
    466475
    467         phone_t *phone = phone_get_current(phone_cap);
    468         if (!phone) {
     476        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     477        if (!kobj) {
    469478                rc = ENOENT;
    470479                goto error;
     
    512521        }
    513522       
    514         rc = ipc_forward(call, phone, &TASK->answerbox, mode);
     523        rc = ipc_forward(call, kobj->phone, &TASK->answerbox, mode);
    515524        if (rc != EOK) {
    516525                after_forward = true;
     
    518527        }
    519528
     529        kobject_put(kobj);
    520530        return EOK;
    521531
     
    528538                ipc_answer(&TASK->answerbox, call);
    529539
     540        if (kobj)
     541                kobject_put(kobj);
    530542        return rc;
    531543}
     
    540552 * arguments are not set and these values are ignored.
    541553 *
    542  * @param callid  Hash of the call to forward.
    543  * @param phoneid Phone handle to use for forwarding.
    544  * @param imethod New interface and method to use for the forwarded call.
    545  * @param arg1    New value of the first argument for the forwarded call.
    546  * @param arg2    New value of the second argument for the forwarded call.
    547  * @param mode    Flags that specify mode of the forward operation.
     554 * @param callid   Hash of the call to forward.
     555 * @param handle  Phone handle to use for forwarding.
     556 * @param imethod  New interface and method to use for the forwarded call.
     557 * @param arg1     New value of the first argument for the forwarded call.
     558 * @param arg2     New value of the second argument for the forwarded call.
     559 * @param mode     Flags that specify mode of the forward operation.
    548560 *
    549561 * @return 0 on succes, otherwise an error code.
    550562 *
    551563 */
    552 sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
     564sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t handle,
    553565    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    554566{
    555         return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
     567        return sys_ipc_forward_common(callid, handle, imethod, arg1, arg2, 0, 0,
    556568            0, mode, false);
    557569}
     
    567579 *
    568580 * @param callid  Hash of the call to forward.
    569  * @param phoneid Phone handle to use for forwarding.
     581 * @param handle Phone handle to use for forwarding.
    570582 * @param data    Userspace address of the new IPC data.
    571583 * @param mode    Flags that specify mode of the forward operation.
     
    574586 *
    575587 */
    576 sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
     588sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t handle,
    577589    ipc_data_t *data, unsigned int mode)
    578590{
     
    583595                return (sysarg_t) rc;
    584596       
    585         return sys_ipc_forward_common(callid, phoneid,
     597        return sys_ipc_forward_common(callid, handle,
    586598            IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
    587599            IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
     
    681693/** Hang up a phone.
    682694 *
    683  * @param phone_cap  Phone capability of the phone to be hung up.
     695 * @param handle  Phone capability handle of the phone to be hung up.
    684696 *
    685697 * @return 0 on success or an error code.
    686698 *
    687699 */
    688 sysarg_t sys_ipc_hangup(sysarg_t phone_cap)
    689 {
    690         phone_t *phone = phone_get_current(phone_cap);
    691         if (!phone)
     700sysarg_t sys_ipc_hangup(sysarg_t handle)
     701{
     702        kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
     703        if (!kobj)
    692704                return ENOENT;
    693705       
    694         if (ipc_phone_hangup(phone))
     706        if (ipc_phone_hangup(kobj->phone)) {
     707                kobject_put(kobj);
    695708                return -1;
    696        
     709        }
     710       
     711        kobject_put(kobj);
    697712        return 0;
    698713}
Note: See TracChangeset for help on using the changeset viewer.