Changeset 984a9ba in mainline for uspace/lib/drv/generic/driver.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/lib/drv/generic/driver.c

    r76f566d r984a9ba  
    118118}
    119119
    120 static void driver_dev_add(cap_call_handle_t icall_handle, ipc_call_t *icall)
     120static void driver_dev_add(ipc_call_t *icall)
    121121{
    122122        devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
     
    126126        errno_t rc = async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
    127127        if (rc != EOK) {
    128                 async_answer_0(icall_handle, rc);
     128                async_answer_0(icall, rc);
    129129                return;
    130130        }
     
    134134        if (stopping) {
    135135                fibril_rwlock_read_unlock(&stopping_lock);
    136                 async_answer_0(icall_handle, EIO);
     136                async_answer_0(icall, EIO);
    137137                return;
    138138        }
     
    142142                fibril_rwlock_read_unlock(&stopping_lock);
    143143                free(dev_name);
    144                 async_answer_0(icall_handle, ENOMEM);
     144                async_answer_0(icall, ENOMEM);
    145145                return;
    146146        }
     
    162162                fibril_rwlock_read_unlock(&stopping_lock);
    163163                dev_del_ref(dev);
    164                 async_answer_0(icall_handle, res);
     164                async_answer_0(icall, res);
    165165                return;
    166166        }
     
    171171        fibril_rwlock_read_unlock(&stopping_lock);
    172172
    173         async_answer_0(icall_handle, res);
    174 }
    175 
    176 static void driver_dev_remove(cap_call_handle_t icall_handle, ipc_call_t *icall)
     173        async_answer_0(icall, res);
     174}
     175
     176static void driver_dev_remove(ipc_call_t *icall)
    177177{
    178178        devman_handle_t devh = IPC_GET_ARG1(*icall);
     
    185185
    186186        if (dev == NULL) {
    187                 async_answer_0(icall_handle, ENOENT);
     187                async_answer_0(icall, ENOENT);
    188188                return;
    189189        }
     
    204204
    205205        dev_del_ref(dev);
    206         async_answer_0(icall_handle, rc);
    207 }
    208 
    209 static void driver_dev_gone(cap_call_handle_t icall_handle, ipc_call_t *icall)
     206        async_answer_0(icall, rc);
     207}
     208
     209static void driver_dev_gone(ipc_call_t *icall)
    210210{
    211211        devman_handle_t devh = IPC_GET_ARG1(*icall);
     
    218218
    219219        if (dev == NULL) {
    220                 async_answer_0(icall_handle, ENOENT);
     220                async_answer_0(icall, ENOENT);
    221221                return;
    222222        }
     
    237237
    238238        dev_del_ref(dev);
    239         async_answer_0(icall_handle, rc);
    240 }
    241 
    242 static void driver_fun_online(cap_call_handle_t icall_handle, ipc_call_t *icall)
     239        async_answer_0(icall, rc);
     240}
     241
     242static void driver_fun_online(ipc_call_t *icall)
    243243{
    244244        devman_handle_t funh = IPC_GET_ARG1(*icall);
     
    258258
    259259        if (fun == NULL) {
    260                 async_answer_0(icall_handle, ENOENT);
     260                async_answer_0(icall, ENOENT);
    261261                return;
    262262        }
     
    272272        fun_del_ref(fun);
    273273
    274         async_answer_0(icall_handle, rc);
    275 }
    276 
    277 static void driver_fun_offline(cap_call_handle_t icall_handle, ipc_call_t *icall)
     274        async_answer_0(icall, rc);
     275}
     276
     277static void driver_fun_offline(ipc_call_t *icall)
    278278{
    279279        devman_handle_t funh = IPC_GET_ARG1(*icall);
     
    293293
    294294        if (fun == NULL) {
    295                 async_answer_0(icall_handle, ENOENT);
     295                async_answer_0(icall, ENOENT);
    296296                return;
    297297        }
     
    305305                rc = ENOTSUP;
    306306
    307         async_answer_0(icall_handle, rc);
    308 }
    309 
    310 static void driver_stop(cap_call_handle_t icall_handle, ipc_call_t *icall)
     307        async_answer_0(icall, rc);
     308}
     309
     310static void driver_stop(ipc_call_t *icall)
    311311{
    312312        /* Prevent new devices from being added */
     
    321321                stopping = false;
    322322                fibril_rwlock_write_unlock(&stopping_lock);
    323                 async_answer_0(icall_handle, EBUSY);
     323                async_answer_0(icall, EBUSY);
    324324                return;
    325325        }
     
    333333
    334334        /* Reply with success and terminate */
    335         async_answer_0(icall_handle, EOK);
     335        async_answer_0(icall, EOK);
    336336        exit(0);
    337337}
    338338
    339 static void driver_connection_devman(cap_call_handle_t icall_handle, ipc_call_t *icall,
    340     void *arg)
     339static void driver_connection_devman(ipc_call_t *icall, void *arg)
    341340{
    342341        /* Accept connection */
    343         async_answer_0(icall_handle, EOK);
     342        async_answer_0(icall, EOK);
    344343
    345344        while (true) {
    346345                ipc_call_t call;
    347                 cap_call_handle_t chandle = async_get_call(&call);
     346                async_get_call(&call);
    348347
    349348                if (!IPC_GET_IMETHOD(call))
     
    352351                switch (IPC_GET_IMETHOD(call)) {
    353352                case DRIVER_DEV_ADD:
    354                         driver_dev_add(chandle, &call);
     353                        driver_dev_add(&call);
    355354                        break;
    356355                case DRIVER_DEV_REMOVE:
    357                         driver_dev_remove(chandle, &call);
     356                        driver_dev_remove(&call);
    358357                        break;
    359358                case DRIVER_DEV_GONE:
    360                         driver_dev_gone(chandle, &call);
     359                        driver_dev_gone(&call);
    361360                        break;
    362361                case DRIVER_FUN_ONLINE:
    363                         driver_fun_online(chandle, &call);
     362                        driver_fun_online(&call);
    364363                        break;
    365364                case DRIVER_FUN_OFFLINE:
    366                         driver_fun_offline(chandle, &call);
     365                        driver_fun_offline(&call);
    367366                        break;
    368367                case DRIVER_STOP:
    369                         driver_stop(chandle, &call);
     368                        driver_stop(&call);
    370369                        break;
    371370                default:
    372                         async_answer_0(chandle, ENOTSUP);
     371                        async_answer_0(&call, ENOTSUP);
    373372                }
    374373        }
     
    381380 *
    382381 */
    383 static void driver_connection_gen(cap_call_handle_t icall_handle, ipc_call_t *icall, bool drv)
     382static void driver_connection_gen(ipc_call_t *icall, bool drv)
    384383{
    385384        /*
     
    398397                printf("%s: driver_connection_gen error - no function with handle"
    399398                    " %" PRIun " was found.\n", driver->name, handle);
    400                 async_answer_0(icall_handle, ENOENT);
     399                async_answer_0(icall, ENOENT);
    401400                return;
    402401        }
     
    404403        if (fun->conn_handler != NULL) {
    405404                /* Driver has a custom connection handler. */
    406                 (*fun->conn_handler)(icall_handle, icall, (void *)fun);
     405                (*fun->conn_handler)(icall, (void *)fun);
    407406                fun_del_ref(fun);
    408407                return;
     
    419418                ret = (*fun->ops->open)(fun);
    420419
    421         async_answer_0(icall_handle, ret);
     420        async_answer_0(icall, ret);
    422421        if (ret != EOK) {
    423422                fun_del_ref(fun);
     
    426425
    427426        while (true) {
    428                 cap_call_handle_t chandle;
    429427                ipc_call_t call;
    430                 chandle = async_get_call(&call);
     428                async_get_call(&call);
     429
    431430                sysarg_t method = IPC_GET_IMETHOD(call);
    432431
     
    435434                        if (fun->ops != NULL && fun->ops->close != NULL)
    436435                                (*fun->ops->close)(fun);
    437                         async_answer_0(chandle, EOK);
     436                        async_answer_0(&call, EOK);
    438437                        fun_del_ref(fun);
    439438                        return;
     
    448447                            function_get_default_handler(fun);
    449448                        if (default_handler != NULL) {
    450                                 (*default_handler)(fun, chandle, &call);
     449                                (*default_handler)(fun, &call);
    451450                                continue;
    452451                        }
     
    459458                            "invalid interface id %d.",
    460459                            driver->name, iface_idx);
    461                         async_answer_0(chandle, ENOTSUP);
     460                        async_answer_0(&call, ENOTSUP);
    462461                        continue;
    463462                }
     
    471470                        printf("Function with handle %" PRIun " has no interface "
    472471                            "with id %d.\n", handle, iface_idx);
    473                         async_answer_0(chandle, ENOTSUP);
     472                        async_answer_0(&call, ENOTSUP);
    474473                        continue;
    475474                }
     
    490489                        printf("%s: driver_connection_gen error - "
    491490                            "invalid interface method.", driver->name);
    492                         async_answer_0(chandle, ENOTSUP);
     491                        async_answer_0(&call, ENOTSUP);
    493492                        continue;
    494493                }
     
    500499                 * associated with the function by its driver.
    501500                 */
    502                 (*iface_method_ptr)(fun, ops, chandle, &call);
    503         }
    504 }
    505 
    506 static void driver_connection_driver(cap_call_handle_t icall_handle, ipc_call_t *icall,
    507     void *arg)
    508 {
    509         driver_connection_gen(icall_handle, icall, true);
    510 }
    511 
    512 static void driver_connection_client(cap_call_handle_t icall_handle, ipc_call_t *icall,
    513     void *arg)
    514 {
    515         driver_connection_gen(icall_handle, icall, false);
     501                (*iface_method_ptr)(fun, ops, &call);
     502        }
     503}
     504
     505static void driver_connection_driver(ipc_call_t *icall, void *arg)
     506{
     507        driver_connection_gen(icall, true);
     508}
     509
     510static void driver_connection_client(ipc_call_t *icall, void *arg)
     511{
     512        driver_connection_gen(icall, false);
    516513}
    517514
Note: See TracChangeset for help on using the changeset viewer.