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/remote_audio_pcm.c

    r76f566d r984a9ba  
    600600 * SERVER SIDE
    601601 */
    602 static void remote_audio_pcm_get_info_str(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    603 static void remote_audio_pcm_query_caps(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    604 static void remote_audio_pcm_events_register(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    605 static void remote_audio_pcm_events_unregister(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    606 static void remote_audio_pcm_get_buffer_pos(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    607 static void remote_audio_pcm_test_format(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    608 static void remote_audio_pcm_get_buffer(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    609 static void remote_audio_pcm_release_buffer(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    610 static void remote_audio_pcm_start_playback(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    611 static void remote_audio_pcm_stop_playback(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    612 static void remote_audio_pcm_start_capture(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    613 static void remote_audio_pcm_stop_capture(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
     602static void remote_audio_pcm_get_info_str(ddf_fun_t *, void *, ipc_call_t *);
     603static void remote_audio_pcm_query_caps(ddf_fun_t *, void *, ipc_call_t *);
     604static void remote_audio_pcm_events_register(ddf_fun_t *, void *, ipc_call_t *);
     605static void remote_audio_pcm_events_unregister(ddf_fun_t *, void *, ipc_call_t *);
     606static void remote_audio_pcm_get_buffer_pos(ddf_fun_t *, void *, ipc_call_t *);
     607static void remote_audio_pcm_test_format(ddf_fun_t *, void *, ipc_call_t *);
     608static void remote_audio_pcm_get_buffer(ddf_fun_t *, void *, ipc_call_t *);
     609static void remote_audio_pcm_release_buffer(ddf_fun_t *, void *, ipc_call_t *);
     610static void remote_audio_pcm_start_playback(ddf_fun_t *, void *, ipc_call_t *);
     611static void remote_audio_pcm_stop_playback(ddf_fun_t *, void *, ipc_call_t *);
     612static void remote_audio_pcm_start_capture(ddf_fun_t *, void *, ipc_call_t *);
     613static void remote_audio_pcm_stop_capture(ddf_fun_t *, void *, ipc_call_t *);
    614614
    615615/** Remote audio pcm buffer interface operations. */
     
    636636
    637637void remote_audio_pcm_get_info_str(ddf_fun_t *fun, void *iface,
    638     cap_call_handle_t chandle, ipc_call_t *call)
     638    ipc_call_t *call)
    639639{
    640640        const audio_pcm_iface_t *pcm_iface = iface;
    641641
    642642        if (!pcm_iface->get_info_str) {
    643                 async_answer_0(chandle, ENOTSUP);
    644                 return;
    645         }
     643                async_answer_0(call, ENOTSUP);
     644                return;
     645        }
     646
    646647        const char *name = NULL;
    647648        const errno_t ret = pcm_iface->get_info_str(fun, &name);
    648649        const size_t name_size = name ? str_size(name) + 1 : 0;
    649         async_answer_1(chandle, ret, name_size);
     650        async_answer_1(call, ret, name_size);
     651
    650652        /* Send the string. */
    651653        if (ret == EOK && name_size > 0) {
     654                ipc_call_t call;
    652655                size_t size;
    653                 cap_call_handle_t name_id;
    654                 if (!async_data_read_receive(&name_id, &size)) {
    655                         async_answer_0(name_id, EPARTY);
     656                if (!async_data_read_receive(&call, &size)) {
     657                        async_answer_0(&call, EPARTY);
    656658                        return;
    657659                }
     660
    658661                if (size != name_size) {
    659                         async_answer_0(name_id, ELIMIT);
     662                        async_answer_0(&call, ELIMIT);
    660663                        return;
    661664                }
    662                 async_data_read_finalize(name_id, name, name_size);
     665
     666                async_data_read_finalize(&call, name, name_size);
    663667        }
    664668}
    665669
    666670void remote_audio_pcm_query_caps(ddf_fun_t *fun, void *iface,
    667     cap_call_handle_t chandle, ipc_call_t *call)
     671    ipc_call_t *call)
    668672{
    669673        const audio_pcm_iface_t *pcm_iface = iface;
     
    671675        if (pcm_iface->query_cap) {
    672676                const unsigned value = pcm_iface->query_cap(fun, cap);
    673                 async_answer_1(chandle, EOK, value);
     677                async_answer_1(call, EOK, value);
    674678        } else {
    675                 async_answer_0(chandle, ENOTSUP);
     679                async_answer_0(call, ENOTSUP);
    676680        }
    677681}
    678682
    679683static void remote_audio_pcm_events_register(ddf_fun_t *fun, void *iface,
    680     cap_call_handle_t chandle, ipc_call_t *call)
     684    ipc_call_t *call)
    681685{
    682686        const audio_pcm_iface_t *pcm_iface = iface;
    683687        if (!pcm_iface->get_event_session ||
    684688            !pcm_iface->set_event_session) {
    685                 async_answer_0(chandle, ENOTSUP);
    686                 return;
    687         }
    688 
    689         async_answer_0(chandle, EOK);
     689                async_answer_0(call, ENOTSUP);
     690                return;
     691        }
     692
     693        async_answer_0(call, EOK);
    690694
    691695        ipc_call_t callback_call;
    692         cap_call_handle_t callback_handle = async_get_call(&callback_call);
     696        async_get_call(&callback_call);
    693697        async_sess_t *sess =
    694698            async_callback_receive_start(EXCHANGE_ATOMIC, &callback_call);
    695699        if (sess == NULL) {
    696700                ddf_msg(LVL_DEBUG, "Failed to create event callback");
    697                 async_answer_0(callback_handle, EAGAIN);
    698                 return;
    699         }
     701                async_answer_0(&callback_call, EAGAIN);
     702                return;
     703        }
     704
    700705        const errno_t ret = pcm_iface->set_event_session(fun, sess);
    701706        if (ret != EOK) {
    702707                ddf_msg(LVL_DEBUG, "Failed to set event callback.");
    703708                async_hangup(sess);
    704                 async_answer_0(callback_handle, ret);
    705                 return;
    706         }
    707         async_answer_0(callback_handle, EOK);
     709                async_answer_0(&callback_call, ret);
     710                return;
     711        }
     712
     713        async_answer_0(&callback_call, EOK);
    708714}
    709715
    710716static void remote_audio_pcm_events_unregister(ddf_fun_t *fun, void *iface,
    711     cap_call_handle_t chandle, ipc_call_t *call)
     717    ipc_call_t *call)
    712718{
    713719        const audio_pcm_iface_t *pcm_iface = iface;
    714720        if (!pcm_iface->get_event_session ||
    715721            !pcm_iface->set_event_session) {
    716                 async_answer_0(chandle, ENOTSUP);
    717                 return;
    718         }
     722                async_answer_0(call, ENOTSUP);
     723                return;
     724        }
     725
    719726        async_sess_t *sess = pcm_iface->get_event_session(fun);
    720727        if (sess) {
     
    722729                pcm_iface->set_event_session(fun, NULL);
    723730        }
    724         async_answer_0(chandle, EOK);
     731
     732        async_answer_0(call, EOK);
    725733}
    726734
    727735void remote_audio_pcm_get_buffer_pos(ddf_fun_t *fun, void *iface,
    728     cap_call_handle_t chandle, ipc_call_t *call)
     736    ipc_call_t *call)
    729737{
    730738        const audio_pcm_iface_t *pcm_iface = iface;
     
    732740        const errno_t ret = pcm_iface->get_buffer_pos ?
    733741            pcm_iface->get_buffer_pos(fun, &pos) : ENOTSUP;
    734         async_answer_1(chandle, ret, pos);
     742        async_answer_1(call, ret, pos);
    735743}
    736744
    737745void remote_audio_pcm_test_format(ddf_fun_t *fun, void *iface,
    738     cap_call_handle_t chandle, ipc_call_t *call)
     746    ipc_call_t *call)
    739747{
    740748        const audio_pcm_iface_t *pcm_iface = iface;
     
    744752        const errno_t ret = pcm_iface->test_format ?
    745753            pcm_iface->test_format(fun, &channels, &rate, &format) : ENOTSUP;
    746         async_answer_3(chandle, ret, channels, rate, format);
     754        async_answer_3(call, ret, channels, rate, format);
    747755}
    748756
    749757void remote_audio_pcm_get_buffer(ddf_fun_t *fun, void *iface,
    750     cap_call_handle_t chandle, ipc_call_t *call)
     758    ipc_call_t *call)
    751759{
    752760        const audio_pcm_iface_t *pcm_iface = iface;
     
    754762        if (!pcm_iface->get_buffer ||
    755763            !pcm_iface->release_buffer) {
    756                 async_answer_0(chandle, ENOTSUP);
     764                async_answer_0(call, ENOTSUP);
    757765                return;
    758766        }
     
    760768        size_t size = DEV_IPC_GET_ARG1(*call);
    761769        errno_t ret = pcm_iface->get_buffer(fun, &buffer, &size);
    762         async_answer_1(chandle, ret, size);
     770        async_answer_1(call, ret, size);
    763771        if (ret != EOK || size == 0)
    764772                return;
    765773
    766774        /* Share the buffer. */
     775        ipc_call_t share;
    767776        size_t share_size = 0;
    768         cap_call_handle_t share_id = 0;
    769777
    770778        ddf_msg(LVL_DEBUG2, "Receiving share request.");
    771         if (!async_share_in_receive(&share_id, &share_size)) {
     779        if (!async_share_in_receive(&share, &share_size)) {
    772780                ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
    773781                pcm_iface->release_buffer(fun);
    774                 async_answer_0(share_id, EPARTY);
     782                async_answer_0(&share, EPARTY);
    775783                return;
    776784        }
     
    780788                ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
    781789                pcm_iface->release_buffer(fun);
    782                 async_answer_0(share_id, ELIMIT);
     790                async_answer_0(&share, ELIMIT);
    783791                return;
    784792        }
    785793
    786794        ddf_msg(LVL_DEBUG2, "Calling share finalize.");
    787         ret = async_share_in_finalize(share_id, buffer, AS_AREA_WRITE |
     795        ret = async_share_in_finalize(&share, buffer, AS_AREA_WRITE |
    788796            AS_AREA_READ);
    789797        if (ret != EOK) {
     
    797805
    798806void remote_audio_pcm_release_buffer(ddf_fun_t *fun, void *iface,
    799     cap_call_handle_t chandle, ipc_call_t *call)
     807    ipc_call_t *call)
    800808{
    801809        const audio_pcm_iface_t *pcm_iface = iface;
     
    803811        const errno_t ret = pcm_iface->release_buffer ?
    804812            pcm_iface->release_buffer(fun) : ENOTSUP;
    805         async_answer_0(chandle, ret);
     813        async_answer_0(call, ret);
    806814}
    807815
    808816void remote_audio_pcm_start_playback(ddf_fun_t *fun, void *iface,
    809     cap_call_handle_t chandle, ipc_call_t *call)
     817    ipc_call_t *call)
    810818{
    811819        const audio_pcm_iface_t *pcm_iface = iface;
     
    819827            pcm_iface->start_playback(fun, frames, channels, rate, format) :
    820828            ENOTSUP;
    821         async_answer_0(chandle, ret);
     829        async_answer_0(call, ret);
    822830}
    823831
    824832void remote_audio_pcm_stop_playback(ddf_fun_t *fun, void *iface,
    825     cap_call_handle_t chandle, ipc_call_t *call)
     833    ipc_call_t *call)
    826834{
    827835        const audio_pcm_iface_t *pcm_iface = iface;
     
    830838        const errno_t ret = pcm_iface->stop_playback ?
    831839            pcm_iface->stop_playback(fun, immediate) : ENOTSUP;
    832         async_answer_0(chandle, ret);
     840        async_answer_0(call, ret);
    833841}
    834842
    835843void remote_audio_pcm_start_capture(ddf_fun_t *fun, void *iface,
    836     cap_call_handle_t chandle, ipc_call_t *call)
     844    ipc_call_t *call)
    837845{
    838846        const audio_pcm_iface_t *pcm_iface = iface;
     
    846854            pcm_iface->start_capture(fun, frames, channels, rate, format) :
    847855            ENOTSUP;
    848         async_answer_0(chandle, ret);
     856        async_answer_0(call, ret);
    849857}
    850858
    851859void remote_audio_pcm_stop_capture(ddf_fun_t *fun, void *iface,
    852     cap_call_handle_t chandle, ipc_call_t *call)
     860    ipc_call_t *call)
    853861{
    854862        const audio_pcm_iface_t *pcm_iface = iface;
     
    857865        const errno_t ret = pcm_iface->stop_capture ?
    858866            pcm_iface->stop_capture(fun, immediate) : ENOTSUP;
    859         async_answer_0(chandle, ret);
     867        async_answer_0(call, ret);
    860868}
    861869
     
    863871 * @}
    864872 */
    865 
Note: See TracChangeset for help on using the changeset viewer.