Changeset 984a9ba in mainline for uspace/lib/hound/src/protocol.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/hound/src/protocol.c

    r76f566d r984a9ba  
    142142        async_exchange_end(exch);
    143143        if (ret == EOK) {
    144                 *id = (hound_context_id_t)IPC_GET_ARG1(call);
     144                *id = (hound_context_id_t) IPC_GET_ARG1(call);
    145145        }
    146146
     
    384384/** Server side implementation of the hound protocol. IPC connection handler.
    385385 *
    386  * @param icall_handle   Initial call handle
    387  * @param icall          Pointer to initial call structure.
    388  * @param arg            (unused)
    389  */
    390 void hound_connection_handler(cap_call_handle_t icall_handle, ipc_call_t *icall,
    391     void *arg)
    392 {
    393         hound_context_id_t id;
     386 * @param icall Pointer to initial call structure.
     387 * @param arg   (unused)
     388 *
     389 */
     390void hound_connection_handler(ipc_call_t *icall, void *arg)
     391{
     392        hound_context_id_t context;
    394393        errno_t ret;
    395394        int flags;
     
    399398        /* Accept connection if there is a valid iface*/
    400399        if (server_iface) {
    401                 async_answer_0(icall_handle, EOK);
     400                async_answer_0(icall, EOK);
    402401        } else {
    403                 async_answer_0(icall_handle, ENOTSUP);
     402                async_answer_0(icall, ENOTSUP);
    404403                return;
    405404        }
     
    407406        while (true) {
    408407                ipc_call_t call;
    409                 cap_call_handle_t chandle = async_get_call(&call);
     408                async_get_call(&call);
     409
    410410                switch (IPC_GET_IMETHOD(call)) {
    411411                case IPC_M_HOUND_CONTEXT_REGISTER:
    412412                        /* check interface functions */
    413413                        if (!server_iface || !server_iface->add_context) {
    414                                 async_answer_0(chandle, ENOTSUP);
     414                                async_answer_0(&call, ENOTSUP);
    415415                                break;
    416416                        }
     
    421421                        ret = async_data_write_accept(&name, true, 0, 0, 0, 0);
    422422                        if (ret != EOK) {
    423                                 async_answer_0(chandle, ret);
    424                                 break;
    425                         }
    426 
    427                         id = 0;
     423                                async_answer_0(&call, ret);
     424                                break;
     425                        }
     426
     427                        context = 0;
    428428                        ret = server_iface->add_context(server_iface->server,
    429                             &id, name, record);
     429                            &context, name, record);
    430430                        /** new context should create a copy */
    431431                        free(name);
    432432                        if (ret != EOK) {
    433                                 async_answer_0(chandle, ret);
     433                                async_answer_0(&call, ret);
    434434                        } else {
    435                                 async_answer_1(chandle, EOK, CAP_HANDLE_RAW(id));
     435                                async_answer_1(&call, EOK, CAP_HANDLE_RAW(context));
    436436                        }
    437437                        break;
     
    439439                        /* check interface functions */
    440440                        if (!server_iface || !server_iface->rem_context) {
    441                                 async_answer_0(chandle, ENOTSUP);
     441                                async_answer_0(&call, ENOTSUP);
    442442                                break;
    443443                        }
    444444
    445445                        /* get id, 1st param */
    446                         id = (cap_handle_t) IPC_GET_ARG1(call);
     446                        context = (hound_context_id_t) IPC_GET_ARG1(call);
    447447                        ret = server_iface->rem_context(server_iface->server,
    448                             id);
    449                         async_answer_0(chandle, ret);
     448                            context);
     449                        async_answer_0(&call, ret);
    450450                        break;
    451451                case IPC_M_HOUND_GET_LIST:
    452452                        /* check interface functions */
    453453                        if (!server_iface || !server_iface->get_list) {
    454                                 async_answer_0(chandle, ENOTSUP);
     454                                async_answer_0(&call, ENOTSUP);
    455455                                break;
    456456                        }
     
    480480                        if (count && !sizes)
    481481                                ret = ENOMEM;
    482                         async_answer_1(chandle, ret, count);
     482                        async_answer_1(&call, ret, count);
    483483
    484484                        /* We are done */
     
    491491
    492492                        /* Send sizes table */
    493                         cap_call_handle_t id;
     493                        ipc_call_t id;
    494494                        if (async_data_read_receive(&id, NULL)) {
    495                                 ret = async_data_read_finalize(id, sizes,
     495                                ret = async_data_read_finalize(&id, sizes,
    496496                                    count * sizeof(size_t));
    497497                        }
     
    501501                        for (unsigned i = 0; i < count; ++i) {
    502502                                size_t size = str_size(list[i]);
    503                                 cap_call_handle_t id;
     503                                ipc_call_t id;
    504504                                if (ret == EOK &&
    505505                                    async_data_read_receive(&id, NULL)) {
    506                                         ret = async_data_read_finalize(id,
     506                                        ret = async_data_read_finalize(&id,
    507507                                            list[i], size);
    508508                                }
     
    514514                        /* check interface functions */
    515515                        if (!server_iface || !server_iface->connect) {
    516                                 async_answer_0(chandle, ENOTSUP);
     516                                async_answer_0(&call, ENOTSUP);
    517517                                break;
    518518                        }
     
    534534                        free(source);
    535535                        free(sink);
    536                         async_answer_0(chandle, ret);
     536                        async_answer_0(&call, ret);
    537537                        break;
    538538                case IPC_M_HOUND_DISCONNECT:
    539539                        /* check interface functions */
    540540                        if (!server_iface || !server_iface->disconnect) {
    541                                 async_answer_0(chandle, ENOTSUP);
     541                                async_answer_0(&call, ENOTSUP);
    542542                                break;
    543543                        }
     
    558558                        free(source);
    559559                        free(sink);
    560                         async_answer_0(chandle, ret);
     560                        async_answer_0(&call, ret);
    561561                        break;
    562562                case IPC_M_HOUND_STREAM_ENTER:
     
    565565                            !server_iface->add_stream ||
    566566                            !server_iface->rem_stream) {
    567                                 async_answer_0(chandle, ENOTSUP);
     567                                async_answer_0(&call, ENOTSUP);
    568568                                break;
    569569                        }
    570570
    571571                        /* get parameters */
    572                         id = (cap_handle_t) IPC_GET_ARG1(call);
     572                        context = (hound_context_id_t) IPC_GET_ARG1(call);
    573573                        flags = IPC_GET_ARG2(call);
    574574                        const format_convert_t c = { .arg = IPC_GET_ARG3(call) };
     
    582582                        void *stream;
    583583                        ret = server_iface->add_stream(server_iface->server,
    584                             id, flags, f, bsize, &stream);
     584                            context, flags, f, bsize, &stream);
    585585                        if (ret != EOK) {
    586                                 async_answer_0(chandle, ret);
     586                                async_answer_0(&call, ret);
    587587                                break;
    588588                        }
    589589                        const bool rec = server_iface->is_record_context(
    590                             server_iface->server, id);
     590                            server_iface->server, context);
    591591                        if (rec) {
    592592                                if (server_iface->stream_data_read) {
    593                                         async_answer_0(chandle, EOK);
     593                                        async_answer_0(&call, EOK);
    594594                                        /* start answering read calls */
    595595                                        hound_server_write_data(stream);
     
    597597                                            server_iface->server, stream);
    598598                                } else {
    599                                         async_answer_0(chandle, ENOTSUP);
     599                                        async_answer_0(&call, ENOTSUP);
    600600                                }
    601601                        } else {
    602602                                if (server_iface->stream_data_write) {
    603                                         async_answer_0(chandle, EOK);
     603                                        async_answer_0(&call, EOK);
    604604                                        /* accept write calls */
    605605                                        hound_server_read_data(stream);
     
    607607                                            server_iface->server, stream);
    608608                                } else {
    609                                         async_answer_0(chandle, ENOTSUP);
     609                                        async_answer_0(&call, ENOTSUP);
    610610                                }
    611611                        }
     
    614614                case IPC_M_HOUND_STREAM_DRAIN:
    615615                        /* Stream exit/drain is only allowed in stream context*/
    616                         async_answer_0(chandle, EINVAL);
     616                        async_answer_0(&call, EINVAL);
    617617                        break;
    618618                default:
    619                         async_answer_0(chandle, ENOTSUP);
     619                        async_answer_0(&call, ENOTSUP);
    620620                        return;
    621621                }
     
    629629static void hound_server_read_data(void *stream)
    630630{
    631         cap_call_handle_t chandle;
    632631        ipc_call_t call;
    633632        size_t size = 0;
    634633        errno_t ret_answer = EOK;
     634
    635635        /* accept data write or drain */
    636         while (async_data_write_receive_call(&chandle, &call, &size) ||
     636        while (async_data_write_receive(&call, &size) ||
    637637            (IPC_GET_IMETHOD(call) == IPC_M_HOUND_STREAM_DRAIN)) {
    638638                /* check drain first */
     
    641641                        if (server_iface->drain_stream)
    642642                                ret = server_iface->drain_stream(stream);
    643                         async_answer_0(chandle, ret);
     643                        async_answer_0(&call, ret);
    644644                        continue;
    645645                }
     
    647647                /* there was an error last time */
    648648                if (ret_answer != EOK) {
    649                         async_answer_0(chandle, ret_answer);
     649                        async_answer_0(&call, ret_answer);
    650650                        continue;
    651651                }
     
    653653                char *buffer = malloc(size);
    654654                if (!buffer) {
    655                         async_answer_0(chandle, ENOMEM);
     655                        async_answer_0(&call, ENOMEM);
    656656                        continue;
    657657                }
    658                 const errno_t ret = async_data_write_finalize(chandle, buffer, size);
     658                const errno_t ret = async_data_write_finalize(&call, buffer, size);
    659659                if (ret == EOK) {
    660660                        /* push data to stream */
     
    666666            EOK : EINVAL;
    667667
    668         async_answer_0(chandle, ret);
     668        async_answer_0(&call, ret);
    669669}
    670670
     
    676676{
    677677
    678         cap_call_handle_t chandle;
    679678        ipc_call_t call;
    680679        size_t size = 0;
    681680        errno_t ret_answer = EOK;
     681
    682682        /* accept data read and drain */
    683         while (async_data_read_receive_call(&chandle, &call, &size) ||
     683        while (async_data_read_receive(&call, &size) ||
    684684            (IPC_GET_IMETHOD(call) == IPC_M_HOUND_STREAM_DRAIN)) {
    685685                /* drain does not make much sense but it is allowed */
     
    688688                        if (server_iface->drain_stream)
    689689                                ret = server_iface->drain_stream(stream);
    690                         async_answer_0(chandle, ret);
     690                        async_answer_0(&call, ret);
    691691                        continue;
    692692                }
    693693                /* there was an error last time */
    694694                if (ret_answer != EOK) {
    695                         async_answer_0(chandle, ret_answer);
     695                        async_answer_0(&call, ret_answer);
    696696                        continue;
    697697                }
    698698                char *buffer = malloc(size);
    699699                if (!buffer) {
    700                         async_answer_0(chandle, ENOMEM);
     700                        async_answer_0(&call, ENOMEM);
    701701                        continue;
    702702                }
     
    704704                if (ret == EOK) {
    705705                        ret_answer =
    706                             async_data_read_finalize(chandle, buffer, size);
     706                            async_data_read_finalize(&call, buffer, size);
    707707                }
    708708        }
     
    710710            EOK : EINVAL;
    711711
    712         async_answer_0(chandle, ret);
     712        async_answer_0(&call, ret);
    713713}
    714714
Note: See TracChangeset for help on using the changeset viewer.