Changeset 984a9ba in mainline for uspace/srv/devman/drv_conn.c


Ignore:
Timestamp:
2018-07-05T09:34:09Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63d46341
Parents:
76f566d
Message:

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/drv_conn.c

    r76f566d r984a9ba  
    6464
    6565/** Register running driver. */
    66 static driver_t *devman_driver_register(cap_call_handle_t chandle, ipc_call_t *call)
     66static driver_t *devman_driver_register(ipc_call_t *call)
    6767{
    6868        driver_t *driver = NULL;
     
    7474        errno_t rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0);
    7575        if (rc != EOK) {
    76                 async_answer_0(chandle, rc);
     76                async_answer_0(call, rc);
    7777                return NULL;
    7878        }
     
    8787                free(drv_name);
    8888                drv_name = NULL;
    89                 async_answer_0(chandle, ENOENT);
     89                async_answer_0(call, ENOENT);
    9090                return NULL;
    9191        }
     
    101101                    driver->name);
    102102                fibril_mutex_unlock(&driver->driver_mutex);
    103                 async_answer_0(chandle, EEXIST);
     103                async_answer_0(call, EEXIST);
    104104                return NULL;
    105105        }
     
    126126        if (!driver->sess) {
    127127                fibril_mutex_unlock(&driver->driver_mutex);
    128                 async_answer_0(chandle, ENOTSUP);
     128                async_answer_0(call, ENOTSUP);
    129129                return NULL;
    130130        }
     
    146146                    "for driver `%s'.", driver->name);
    147147                fibril_mutex_unlock(&driver->driver_mutex);
    148                 async_answer_0(chandle, ENOMEM);
     148                async_answer_0(call, ENOMEM);
    149149                return NULL;
    150150        }
     
    153153        fibril_mutex_unlock(&driver->driver_mutex);
    154154
    155         async_answer_0(chandle, EOK);
     155        async_answer_0(call, EOK);
    156156        return driver;
    157157}
     
    166166{
    167167        match_id_t *match_id = create_match_id();
    168         cap_call_handle_t chandle;
    169168        ipc_call_t call;
    170169        errno_t rc = 0;
    171170
    172         chandle = async_get_call(&call);
     171        async_get_call(&call);
    173172        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    174173                log_msg(LOG_DEFAULT, LVL_ERROR,
    175174                    "Invalid protocol when trying to receive match id.");
    176                 async_answer_0(chandle, EINVAL);
     175                async_answer_0(&call, EINVAL);
    177176                delete_match_id(match_id);
    178177                return EINVAL;
     
    181180        if (match_id == NULL) {
    182181                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate match id.");
    183                 async_answer_0(chandle, ENOMEM);
     182                async_answer_0(&call, ENOMEM);
    184183                return ENOMEM;
    185184        }
    186185
    187         async_answer_0(chandle, EOK);
     186        async_answer_0(&call, EOK);
    188187
    189188        match_id->score = IPC_GET_ARG1(call);
     
    230229 * Child devices are registered by their parent's device driver.
    231230 */
    232 static void devman_add_function(cap_call_handle_t chandle, ipc_call_t *call)
     231static void devman_add_function(ipc_call_t *call)
    233232{
    234233        fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call);
     
    239238        dev_node_t *pdev = find_dev_node(&device_tree, dev_handle);
    240239        if (pdev == NULL) {
    241                 async_answer_0(chandle, ENOENT);
     240                async_answer_0(call, ENOENT);
    242241                return;
    243242        }
     
    250249
    251250                dev_del_ref(pdev);
    252                 async_answer_0(chandle, EINVAL);
     251                async_answer_0(call, EINVAL);
    253252                return;
    254253        }
    255254
    256255        char *fun_name = NULL;
    257         errno_t rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0);
     256        errno_t rc = async_data_write_accept((void **) &fun_name, true, 0, 0, 0, 0);
    258257        if (rc != EOK) {
    259258                dev_del_ref(pdev);
    260                 async_answer_0(chandle, rc);
     259                async_answer_0(call, rc);
    261260                return;
    262261        }
     
    268267                fibril_rwlock_write_unlock(&tree->rwlock);
    269268                dev_del_ref(pdev);
    270                 async_answer_0(chandle, ENOENT);
     269                async_answer_0(call, ENOENT);
    271270                return;
    272271        }
     
    278277                fibril_rwlock_write_unlock(&tree->rwlock);
    279278                dev_del_ref(pdev);
    280                 async_answer_0(chandle, EEXIST);
     279                async_answer_0(call, EEXIST);
    281280                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
    282281                    fun_name);
     
    303302                fun_del_ref(fun);
    304303                delete_fun_node(fun);
    305                 async_answer_0(chandle, ENOMEM);
     304                async_answer_0(call, ENOMEM);
    306305                return;
    307306        }
     
    317316                fun_busy_unlock(fun);
    318317                fun_del_ref(fun);
    319                 async_answer_0(chandle, rc);
     318                async_answer_0(call, rc);
    320319                return;
    321320        }
     
    325324
    326325        /* Return device handle to parent's driver. */
    327         async_answer_1(chandle, EOK, fun->handle);
    328 }
    329 
    330 static void devman_add_function_to_cat(cap_call_handle_t chandle, ipc_call_t *call)
     326        async_answer_1(call, EOK, fun->handle);
     327}
     328
     329static void devman_add_function_to_cat(ipc_call_t *call)
    331330{
    332331        devman_handle_t handle = IPC_GET_ARG1(*call);
     
    339338            0, 0, 0, 0);
    340339        if (rc != EOK) {
    341                 async_answer_0(chandle, rc);
     340                async_answer_0(call, rc);
    342341                return;
    343342        }
     
    345344        fun_node_t *fun = find_fun_node(&device_tree, handle);
    346345        if (fun == NULL) {
    347                 async_answer_0(chandle, ENOENT);
     346                async_answer_0(call, ENOENT);
    348347                return;
    349348        }
     
    354353        if (fun->state == FUN_REMOVED) {
    355354                fibril_rwlock_read_unlock(&device_tree.rwlock);
    356                 async_answer_0(chandle, ENOENT);
     355                async_answer_0(call, ENOENT);
    357356                return;
    358357        }
     
    371370        fun_del_ref(fun);
    372371
    373         async_answer_0(chandle, rc);
     372        async_answer_0(call, rc);
    374373}
    375374
     
    377376 *
    378377 */
    379 static void devman_drv_fun_online(cap_call_handle_t icall_handle, ipc_call_t *icall,
    380     driver_t *drv)
     378static void devman_drv_fun_online(ipc_call_t *icall, driver_t *drv)
    381379{
    382380        fun_node_t *fun;
     
    387385        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
    388386        if (fun == NULL) {
    389                 async_answer_0(icall_handle, ENOENT);
     387                async_answer_0(icall, ENOENT);
    390388                return;
    391389        }
     
    398396                fun_busy_unlock(fun);
    399397                fun_del_ref(fun);
    400                 async_answer_0(icall_handle, ENOENT);
     398                async_answer_0(icall, ENOENT);
    401399                return;
    402400        }
     
    407405                fun_busy_unlock(fun);
    408406                fun_del_ref(fun);
    409                 async_answer_0(icall_handle, rc);
     407                async_answer_0(icall, rc);
    410408                return;
    411409        }
     
    414412        fun_del_ref(fun);
    415413
    416         async_answer_0(icall_handle, EOK);
     414        async_answer_0(icall, EOK);
    417415}
    418416
     
    421419 *
    422420 */
    423 static void devman_drv_fun_offline(cap_call_handle_t icall_handle, ipc_call_t *icall,
    424     driver_t *drv)
     421static void devman_drv_fun_offline(ipc_call_t *icall, driver_t *drv)
    425422{
    426423        fun_node_t *fun;
     
    429426        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
    430427        if (fun == NULL) {
    431                 async_answer_0(icall_handle, ENOENT);
     428                async_answer_0(icall, ENOENT);
    432429                return;
    433430        }
     
    439436                fun_busy_unlock(fun);
    440437                fun_del_ref(fun);
    441                 async_answer_0(icall_handle, ENOENT);
     438                async_answer_0(icall, ENOENT);
    442439                return;
    443440        }
     
    448445                fun_busy_unlock(fun);
    449446                fun_del_ref(fun);
    450                 async_answer_0(icall_handle, rc);
     447                async_answer_0(icall, rc);
    451448                return;
    452449        }
     
    454451        fun_busy_unlock(fun);
    455452        fun_del_ref(fun);
    456         async_answer_0(icall_handle, EOK);
     453        async_answer_0(icall, EOK);
    457454}
    458455
    459456/** Remove function. */
    460 static void devman_remove_function(cap_call_handle_t chandle, ipc_call_t *call)
     457static void devman_remove_function(ipc_call_t *call)
    461458{
    462459        devman_handle_t fun_handle = IPC_GET_ARG1(*call);
     
    466463        fun_node_t *fun = find_fun_node(&device_tree, fun_handle);
    467464        if (fun == NULL) {
    468                 async_answer_0(chandle, ENOENT);
     465                async_answer_0(call, ENOENT);
    469466                return;
    470467        }
     
    481478                fun_busy_unlock(fun);
    482479                fun_del_ref(fun);
    483                 async_answer_0(chandle, ENOENT);
     480                async_answer_0(call, ENOENT);
    484481                return;
    485482        }
     
    523520                                fun_busy_unlock(fun);
    524521                                fun_del_ref(fun);
    525                                 async_answer_0(chandle, gone_rc);
     522                                async_answer_0(call, gone_rc);
    526523                                return;
    527524                        }
     
    551548                                fun_busy_unlock(fun);
    552549                                fun_del_ref(fun);
    553                                 async_answer_0(chandle, EIO);
     550                                async_answer_0(call, EIO);
    554551                                return;
    555552                        }
     
    567564
    568565        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded.");
    569         async_answer_0(chandle, EOK);
     566        async_answer_0(call, EOK);
    570567}
    571568
     
    586583
    587584/** Function for handling connections from a driver to the device manager. */
    588 void devman_connection_driver(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
     585void devman_connection_driver(ipc_call_t *icall, void *arg)
    589586{
    590587        client_t *client;
     
    592589
    593590        /* Accept the connection. */
    594         async_answer_0(icall_handle, EOK);
     591        async_answer_0(icall, EOK);
    595592
    596593        client = async_get_client_data();
     
    602599        while (true) {
    603600                ipc_call_t call;
    604                 cap_call_handle_t chandle = async_get_call(&call);
     601                async_get_call(&call);
    605602
    606603                if (!IPC_GET_IMETHOD(call))
     
    613610                        if (driver == NULL) {
    614611                                /* First call must be to DEVMAN_DRIVER_REGISTER */
    615                                 async_answer_0(chandle, ENOTSUP);
     612                                async_answer_0(&call, ENOTSUP);
    616613                                continue;
    617614                        }
     
    623620                        if (client->driver != NULL) {
    624621                                fibril_mutex_unlock(&client->mutex);
    625                                 async_answer_0(chandle, EINVAL);
     622                                async_answer_0(&call, EINVAL);
    626623                                continue;
    627624                        }
    628                         client->driver = devman_driver_register(chandle, &call);
     625                        client->driver = devman_driver_register(&call);
    629626                        fibril_mutex_unlock(&client->mutex);
    630627                        break;
    631628                case DEVMAN_ADD_FUNCTION:
    632                         devman_add_function(chandle, &call);
     629                        devman_add_function(&call);
    633630                        break;
    634631                case DEVMAN_ADD_DEVICE_TO_CATEGORY:
    635                         devman_add_function_to_cat(chandle, &call);
     632                        devman_add_function_to_cat(&call);
    636633                        break;
    637634                case DEVMAN_DRV_FUN_ONLINE:
    638                         devman_drv_fun_online(chandle, &call, driver);
     635                        devman_drv_fun_online(&call, driver);
    639636                        break;
    640637                case DEVMAN_DRV_FUN_OFFLINE:
    641                         devman_drv_fun_offline(chandle, &call, driver);
     638                        devman_drv_fun_offline(&call, driver);
    642639                        break;
    643640                case DEVMAN_REMOVE_FUNCTION:
    644                         devman_remove_function(chandle, &call);
     641                        devman_remove_function(&call);
    645642                        break;
    646643                default:
    647                         async_answer_0(chandle, EINVAL);
     644                        async_answer_0(&call, EINVAL);
    648645                        break;
    649646                }
Note: See TracChangeset for help on using the changeset viewer.