Changeset 01c3bb4 in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2017-11-25T15:43:25Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce4a21a0
Parents:
98cb5e0d
Message:

Convert call-handling syscalls to capabilities

This commit modifies the behavior of sys_ipc_wait_for_call() to return a
capability handle for requests. This capability handle can be used
either by sys_ipc_answer*() to answer the call or by sys_ipc_forward*()
to forward it further along. Answering or forwarding the call results in
destruction of the respective capability. For requests and
notifications, sys_ipc_wait_for_call() returns CAP_NIL and sets call
flags accordingly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r98cb5e0d r01c3bb4  
    7777 *   }
    7878 *
    79  *   port_handler(icallid, *icall)
     79 *   port_handler(ichandle, *icall)
    8080 *   {
    8181 *     if (want_refuse) {
    82  *       async_answer_0(icallid, ELIMIT);
     82 *       async_answer_0(ichandle, ELIMIT);
    8383 *       return;
    8484 *     }
    85  *     async_answer_0(icallid, EOK);
    86  *
    87  *     callid = async_get_call(&call);
    88  *     somehow_handle_the_call(callid, call);
    89  *     async_answer_2(callid, 1, 2, 3);
    90  *
    91  *     callid = async_get_call(&call);
     85 *     async_answer_0(ichandle, EOK);
     86 *
     87 *     chandle = async_get_call(&call);
     88 *     somehow_handle_the_call(chandle, call);
     89 *     async_answer_2(chandle, 1, 2, 3);
     90 *
     91 *     chandle = async_get_call(&call);
    9292 *     ...
    9393 *   }
     
    185185        link_t link;
    186186       
    187         ipc_callid_t callid;
     187        cap_handle_t chandle;
    188188        ipc_call_t call;
    189189} msg_t;
     
    237237       
    238238        /** Identification of the opening call. */
    239         ipc_callid_t callid;
     239        cap_handle_t chandle;
    240240       
    241241        /** Call data of the opening call. */
     
    243243       
    244244        /** Identification of the closing call. */
    245         ipc_callid_t close_callid;
     245        cap_handle_t close_chandle;
    246246       
    247247        /** Fibril function that will be used to handle the connection. */
     
    374374/** Default fallback fibril function.
    375375 *
    376  * This fallback fibril function gets called on incomming
    377  * connections that do not have a specific handler defined.
    378  *
    379  * @param callid Hash of the incoming call.
    380  * @param call   Data of the incoming call.
    381  * @param arg    Local argument
    382  *
    383  */
    384 static void default_fallback_port_handler(ipc_callid_t callid, ipc_call_t *call,
    385     void *arg)
    386 {
    387         ipc_answer_0(callid, ENOENT);
     376 * This fallback fibril function gets called on incomming connections that do
     377 * not have a specific handler defined.
     378 *
     379 * @param chandle  Handle of the incoming call.
     380 * @param call     Data of the incoming call.
     381 * @param arg      Local argument
     382 *
     383 */
     384static void default_fallback_port_handler(cap_handle_t chandle,
     385    ipc_call_t *call, void *arg)
     386{
     387        ipc_answer_0(chandle, ENOENT);
    388388}
    389389
     
    715715        client_t *client = async_client_get(fibril_connection->in_task_id, true);
    716716        if (!client) {
    717                 ipc_answer_0(fibril_connection->callid, ENOMEM);
     717                ipc_answer_0(fibril_connection->chandle, ENOMEM);
    718718                return 0;
    719719        }
     
    724724         * Call the connection handler function.
    725725         */
    726         fibril_connection->handler(fibril_connection->callid,
     726        fibril_connection->handler(fibril_connection->chandle,
    727727            &fibril_connection->call, fibril_connection->data);
    728728       
     
    751751               
    752752                list_remove(&msg->link);
    753                 ipc_answer_0(msg->callid, EHANGUP);
     753                ipc_answer_0(msg->chandle, EHANGUP);
    754754                free(msg);
    755755        }
     
    759759         * i.e. IPC_M_PHONE_HUNGUP.
    760760         */
    761         if (fibril_connection->close_callid)
    762                 ipc_answer_0(fibril_connection->close_callid, EOK);
     761        if (fibril_connection->close_chandle)
     762                ipc_answer_0(fibril_connection->close_chandle, EOK);
    763763       
    764764        free(fibril_connection);
     
    768768/** Create a new fibril for a new connection.
    769769 *
    770  * Create new fibril for connection, fill in connection structures
    771  * and insert it into the hash table, so that later we can easily
    772  * do routing of messages to particular fibrils.
    773  *
    774  * @param in_task_id    Identification of the incoming connection.
    775  * @param in_phone_hash Identification of the incoming connection.
    776  * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
    777  *                      If callid is zero, the connection was opened by
    778  *                      accepting the IPC_M_CONNECT_TO_ME call and this
    779  *                      function is called directly by the server.
    780  * @param call          Call data of the opening call.
    781  * @param handler       Connection handler.
    782  * @param data          Client argument to pass to the connection handler.
    783  *
    784  * @return New fibril id or NULL on failure.
     770 * Create new fibril for connection, fill in connection structures and insert it
     771 * into the hash table, so that later we can easily do routing of messages to
     772 * particular fibrils.
     773 *
     774 * @param in_task_id     Identification of the incoming connection.
     775 * @param in_phone_hash  Identification of the incoming connection.
     776 * @param chandle        Handle of the opening IPC_M_CONNECT_ME_TO call.
     777 *                       If chandle is CAP_NIL, the connection was opened by
     778 *                       accepting the IPC_M_CONNECT_TO_ME call and this
     779 *                       function is called directly by the server.
     780 * @param call           Call data of the opening call.
     781 * @param handler        Connection handler.
     782 * @param data           Client argument to pass to the connection handler.
     783 *
     784 * @return  New fibril id or NULL on failure.
    785785 *
    786786 */
    787787static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    788     ipc_callid_t callid, ipc_call_t *call, async_port_handler_t handler,
     788    cap_handle_t chandle, ipc_call_t *call, async_port_handler_t handler,
    789789    void *data)
    790790{
    791791        connection_t *conn = malloc(sizeof(*conn));
    792792        if (!conn) {
    793                 if (callid)
    794                         ipc_answer_0(callid, ENOMEM);
     793                if (chandle != CAP_NIL)
     794                        ipc_answer_0(chandle, ENOMEM);
    795795               
    796796                return (uintptr_t) NULL;
     
    800800        conn->in_phone_hash = in_phone_hash;
    801801        list_initialize(&conn->msg_queue);
    802         conn->callid = callid;
    803         conn->close_callid = 0;
     802        conn->chandle = chandle;
     803        conn->close_chandle = CAP_NIL;
    804804        conn->handler = handler;
    805805        conn->data = data;
     
    815815                free(conn);
    816816               
    817                 if (callid)
    818                         ipc_answer_0(callid, ENOMEM);
     817                if (chandle != CAP_NIL)
     818                        ipc_answer_0(chandle, ENOMEM);
    819819               
    820820                return (uintptr_t) NULL;
     
    892892       
    893893        fid_t fid = async_new_connection(answer.in_task_id, phone_hash,
    894             0, NULL, handler, data);
     894            CAP_NIL, NULL, handler, data);
    895895        if (fid == (uintptr_t) NULL)
    896896                return ENOMEM;
     
    961961 * timeouts are unregistered.
    962962 *
    963  * @param callid Hash of the incoming call.
    964  * @param call   Data of the incoming call.
     963 * @param chandle  Handle of the incoming call.
     964 * @param call     Data of the incoming call.
    965965 *
    966966 * @return False if the call doesn't match any connection.
     
    968968 *
    969969 */
    970 static bool route_call(ipc_callid_t callid, ipc_call_t *call)
     970static bool route_call(cap_handle_t chandle, ipc_call_t *call)
    971971{
    972972        assert(call);
     
    991991        }
    992992       
    993         msg->callid = callid;
     993        msg->chandle = chandle;
    994994        msg->call = *call;
    995995        list_append(&msg->link, &conn->msg_queue);
    996996       
    997997        if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP)
    998                 conn->close_callid = callid;
     998                conn->close_chandle = chandle;
    999999       
    10001000        /* If the connection fibril is waiting for an event, activate it */
     
    10171017/** Process notification.
    10181018 *
    1019  * @param callid Hash of the incoming call.
    10201019 * @param call   Data of the incoming call.
    10211020 *
    10221021 */
    1023 static void process_notification(ipc_callid_t callid, ipc_call_t *call)
     1022static void process_notification(ipc_call_t *call)
    10241023{
    10251024        async_notification_handler_t handler = NULL;
     
    10421041       
    10431042        if (handler)
    1044                 handler(callid, call, data);
     1043                handler(call, data);
    10451044}
    10461045
     
    11871186/** Return new incoming message for the current (fibril-local) connection.
    11881187 *
    1189  * @param call  Storage where the incoming call data will be stored.
    1190  * @param usecs Timeout in microseconds. Zero denotes no timeout.
    1191  *
    1192  * @return If no timeout was specified, then a hash of the
    1193  *         incoming call is returned. If a timeout is specified,
    1194  *         then a hash of the incoming call is returned unless
    1195  *         the timeout expires prior to receiving a message. In
    1196  *         that case zero is returned.
    1197  *
    1198  */
    1199 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
     1188 * @param call   Storage where the incoming call data will be stored.
     1189 * @param usecs  Timeout in microseconds. Zero denotes no timeout.
     1190 *
     1191 * @return  If no timeout was specified, then a handle of the incoming call is
     1192 *          returned. If a timeout is specified, then a handle of the incoming
     1193 *          call is returned unless the timeout expires prior to receiving a
     1194 *          message. In that case zero CAP_NIL is returned.
     1195 */
     1196cap_handle_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
    12001197{
    12011198        assert(call);
     
    12201217        /* If nothing in queue, wait until something arrives */
    12211218        while (list_empty(&conn->msg_queue)) {
    1222                 if (conn->close_callid) {
     1219                if (conn->close_chandle) {
    12231220                        /*
    12241221                         * Handle the case when the connection was already
     
    12311228                        IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
    12321229                        futex_up(&async_futex);
    1233                         return conn->close_callid;
     1230                        return conn->close_chandle;
    12341231                }
    12351232               
     
    12561253                        /* If we timed out -> exit */
    12571254                        futex_up(&async_futex);
    1258                         return 0;
     1255                        return CAP_NIL;
    12591256                }
    12601257        }
     
    12641261        list_remove(&msg->link);
    12651262       
    1266         ipc_callid_t callid = msg->callid;
     1263        cap_handle_t chandle = msg->chandle;
    12671264        *call = msg->call;
    12681265        free(msg);
    12691266       
    12701267        futex_up(&async_futex);
    1271         return callid;
     1268        return chandle;
    12721269}
    12731270
     
    13321329 * Otherwise the call is routed to its connection fibril.
    13331330 *
    1334  * @param callid Hash of the incoming call.
    1335  * @param call   Data of the incoming call.
    1336  *
    1337  */
    1338 static void handle_call(ipc_callid_t callid, ipc_call_t *call)
     1331 * @param chandle  Handle of the incoming call.
     1332 * @param call     Data of the incoming call.
     1333 *
     1334 */
     1335static void handle_call(cap_handle_t chandle, ipc_call_t *call)
    13391336{
    13401337        assert(call);
    13411338       
    13421339        /* Kernel notification */
    1343         if (call->flags & IPC_CALLID_NOTIFICATION) {
     1340        if ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_NOTIFICATION)) {
    13441341                fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data;
    13451342                unsigned oldsw = fibril->switches;
    13461343               
    1347                 process_notification(callid, call);
     1344                process_notification(call);
    13481345               
    13491346                if (oldsw != fibril->switches) {
     
    13711368                sysarg_t in_phone_hash = IPC_GET_ARG5(*call);
    13721369               
    1373                 async_notification_handler_t handler = fallback_port_handler;
     1370                async_port_handler_t handler = fallback_port_handler;
    13741371                void *data = fallback_port_data;
    13751372               
     
    13811378                }
    13821379               
    1383                 async_new_connection(call->in_task_id, in_phone_hash, callid,
     1380                async_new_connection(call->in_task_id, in_phone_hash, chandle,
    13841381                    call, handler, data);
    13851382                return;
     
    13871384       
    13881385        /* Try to route the call through the connection hash table */
    1389         if (route_call(callid, call))
     1386        if (route_call(chandle, call))
    13901387                return;
    13911388       
    13921389        /* Unknown call from unknown phone - hang it up */
    1393         ipc_answer_0(callid, EHANGUP);
     1390        ipc_answer_0(chandle, EHANGUP);
    13941391}
    13951392
     
    14861483               
    14871484                ipc_call_t call;
    1488                 ipc_callid_t callid = ipc_wait_cycle(&call, timeout, flags);
     1485                cap_handle_t chandle = ipc_wait_cycle(&call, timeout, flags);
    14891486               
    14901487                atomic_dec(&threads_in_ipc_wait);
    14911488               
    1492                 if (!callid) {
    1493                         handle_expired_timeouts();
    1494                         continue;
     1489                assert(chandle >= 0);
     1490
     1491                if (chandle == CAP_NIL) {
     1492                        if (call.flags == 0) {
     1493                                /* This neither a notification nor an answer. */
     1494                                handle_expired_timeouts();
     1495                                continue;
     1496                        }
    14951497                }
    1496                
     1498
    14971499                if (call.flags & IPC_CALLID_ANSWERED)
    14981500                        continue;
    1499                
    1500                 handle_call(callid, &call);
    1501         }
    1502        
     1501
     1502                handle_call(chandle, &call);
     1503        }
     1504
    15031505        return 0;
    15041506}
     
    16311633 * @param arg3    Service-defined payload argument.
    16321634 * @param arg4    Service-defined payload argument.
    1633  * @param dataptr If non-NULL, storage where the reply data will be
    1634  *                stored.
     1635 * @param dataptr If non-NULL, storage where the reply data will be stored.
    16351636 *
    16361637 * @return Hash of the sent message or 0 on error.
     
    20182019}
    20192020
    2020 sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval)
    2021 {
    2022         return ipc_answer_0(callid, retval);
    2023 }
    2024 
    2025 sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)
    2026 {
    2027         return ipc_answer_1(callid, retval, arg1);
    2028 }
    2029 
    2030 sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2021sysarg_t async_answer_0(cap_handle_t chandle, sysarg_t retval)
     2022{
     2023        return ipc_answer_0(chandle, retval);
     2024}
     2025
     2026sysarg_t async_answer_1(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1)
     2027{
     2028        return ipc_answer_1(chandle, retval, arg1);
     2029}
     2030
     2031sysarg_t async_answer_2(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20312032    sysarg_t arg2)
    20322033{
    2033         return ipc_answer_2(callid, retval, arg1, arg2);
    2034 }
    2035 
    2036 sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2034        return ipc_answer_2(chandle, retval, arg1, arg2);
     2035}
     2036
     2037sysarg_t async_answer_3(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20372038    sysarg_t arg2, sysarg_t arg3)
    20382039{
    2039         return ipc_answer_3(callid, retval, arg1, arg2, arg3);
    2040 }
    2041 
    2042 sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2040        return ipc_answer_3(chandle, retval, arg1, arg2, arg3);
     2041}
     2042
     2043sysarg_t async_answer_4(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20432044    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    20442045{
    2045         return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4);
    2046 }
    2047 
    2048 sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2046        return ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4);
     2047}
     2048
     2049sysarg_t async_answer_5(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20492050    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
    20502051{
    2051         return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5);
    2052 }
    2053 
    2054 int async_forward_fast(ipc_callid_t callid, async_exch_t *exch,
     2052        return ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5);
     2053}
     2054
     2055int async_forward_fast(cap_handle_t chandle, async_exch_t *exch,
    20552056    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    20562057{
     
    20582059                return ENOENT;
    20592060       
    2060         return ipc_forward_fast(callid, exch->phone, imethod, arg1, arg2, mode);
    2061 }
    2062 
    2063 int async_forward_slow(ipc_callid_t callid, async_exch_t *exch,
     2061        return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode);
     2062}
     2063
     2064int async_forward_slow(cap_handle_t chandle, async_exch_t *exch,
    20642065    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    20652066    sysarg_t arg4, sysarg_t arg5, unsigned int mode)
     
    20682069                return ENOENT;
    20692070       
    2070         return ipc_forward_slow(callid, exch->phone, imethod, arg1, arg2, arg3,
     2071        return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3,
    20712072            arg4, arg5, mode);
    20722073}
     
    26042605 * So far, this wrapper is to be used from within a connection fibril.
    26052606 *
    2606  * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
    2607  * @param size   Destination address space area size.
     2607 * @param chandle  Storage for the handle of the IPC_M_SHARE_IN call.
     2608 * @param size     Destination address space area size.
    26082609 *
    26092610 * @return True on success, false on failure.
    26102611 *
    26112612 */
    2612 bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
    2613 {
    2614         assert(callid);
     2613bool async_share_in_receive(cap_handle_t *chandle, size_t *size)
     2614{
     2615        assert(chandle);
    26152616        assert(size);
    26162617       
    26172618        ipc_call_t data;
    2618         *callid = async_get_call(&data);
     2619        *chandle = async_get_call(&data);
    26192620       
    26202621        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
     
    26312632 * argument.
    26322633 *
    2633  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    2634  * @param src    Source address space base.
    2635  * @param flags  Flags to be used for sharing. Bits can be only cleared.
     2634 * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
     2635 * @param src      Source address space base.
     2636 * @param flags    Flags to be used for sharing. Bits can be only cleared.
    26362637 *
    26372638 * @return Zero on success or a value from @ref errno.h on failure.
    26382639 *
    26392640 */
    2640 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    2641 {
    2642         return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
     2641int async_share_in_finalize(cap_handle_t chandle, void *src, unsigned int flags)
     2642{
     2643        return ipc_answer_3(chandle, EOK, (sysarg_t) src, (sysarg_t) flags,
    26432644            (sysarg_t) __entry);
    26442645}
     
    26702671 * So far, this wrapper is to be used from within a connection fibril.
    26712672 *
    2672  * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
    2673  * @param size   Storage for the source address space area size.
    2674  * @param flags  Storage for the sharing flags.
     2673 * @param chandle Storage for the hash of the IPC_M_SHARE_OUT call.
     2674 * @param size     Storage for the source address space area size.
     2675 * @param flags    Storage for the sharing flags.
    26752676 *
    26762677 * @return True on success, false on failure.
    26772678 *
    26782679 */
    2679 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
    2680 {
    2681         assert(callid);
     2680bool async_share_out_receive(cap_handle_t *chandle, size_t *size,
     2681    unsigned int *flags)
     2682{
     2683        assert(chandle);
    26822684        assert(size);
    26832685        assert(flags);
    26842686       
    26852687        ipc_call_t data;
    2686         *callid = async_get_call(&data);
     2688        *chandle = async_get_call(&data);
    26872689       
    26882690        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
     
    27002702 * argument.
    27012703 *
    2702  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    2703  * @param dst    Address of the storage for the destination address space area
    2704  *               base address.
    2705  *
    2706  * @return Zero on success or a value from @ref errno.h on failure.
    2707  *
    2708  */
    2709 int async_share_out_finalize(ipc_callid_t callid, void **dst)
    2710 {
    2711         return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
     2704 * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
     2705 * @param dst      Address of the storage for the destination address space area
     2706 *                 base address.
     2707 *
     2708 * @return  Zero on success or a value from @ref errno.h on failure.
     2709 *
     2710 */
     2711int async_share_out_finalize(cap_handle_t chandle, void **dst)
     2712{
     2713        return ipc_answer_2(chandle, EOK, (sysarg_t) __entry, (sysarg_t) dst);
    27122714}
    27132715
     
    27552757 * So far, this wrapper is to be used from within a connection fibril.
    27562758 *
    2757  * @param callid Storage for the hash of the IPC_M_DATA_READ.
    2758  * @param size   Storage for the maximum size. Can be NULL.
     2759 * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
     2760 * @param size     Storage for the maximum size. Can be NULL.
    27592761 *
    27602762 * @return True on success, false on failure.
    27612763 *
    27622764 */
    2763 bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
     2765bool async_data_read_receive(cap_handle_t *chandle, size_t *size)
    27642766{
    27652767        ipc_call_t data;
    2766         return async_data_read_receive_call(callid, &data, size);
     2768        return async_data_read_receive_call(chandle, &data, size);
    27672769}
    27682770
     
    27752777 * So far, this wrapper is to be used from within a connection fibril.
    27762778 *
    2777  * @param callid Storage for the hash of the IPC_M_DATA_READ.
    2778  * @param size   Storage for the maximum size. Can be NULL.
     2779 * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
     2780 * @param size     Storage for the maximum size. Can be NULL.
    27792781 *
    27802782 * @return True on success, false on failure.
    27812783 *
    27822784 */
    2783 bool async_data_read_receive_call(ipc_callid_t *callid, ipc_call_t *data,
     2785bool async_data_read_receive_call(cap_handle_t *chandle, ipc_call_t *data,
    27842786    size_t *size)
    27852787{
    2786         assert(callid);
     2788        assert(chandle);
    27872789        assert(data);
    27882790       
    2789         *callid = async_get_call(data);
     2791        *chandle = async_get_call(data);
    27902792       
    27912793        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ)
     
    28042806 * argument.
    28052807 *
    2806  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    2807  * @param src    Source address for the IPC_M_DATA_READ call.
    2808  * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
    2809  *               the maximum size announced by the sender.
    2810  *
    2811  * @return Zero on success or a value from @ref errno.h on failure.
    2812  *
    2813  */
    2814 int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
    2815 {
    2816         return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
     2808 * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
     2809 * @param src      Source address for the IPC_M_DATA_READ call.
     2810 * @param size     Size for the IPC_M_DATA_READ call. Can be smaller than
     2811 *                 the maximum size announced by the sender.
     2812 *
     2813 * @return  Zero on success or a value from @ref errno.h on failure.
     2814 *
     2815 */
     2816int async_data_read_finalize(cap_handle_t chandle, const void *src, size_t size)
     2817{
     2818        return ipc_answer_2(chandle, EOK, (sysarg_t) src, (sysarg_t) size);
    28172819}
    28182820
     
    28272829                return ENOENT;
    28282830       
    2829         ipc_callid_t callid;
    2830         if (!async_data_read_receive(&callid, NULL)) {
    2831                 ipc_answer_0(callid, EINVAL);
     2831        cap_handle_t chandle;
     2832        if (!async_data_read_receive(&chandle, NULL)) {
     2833                ipc_answer_0(chandle, EINVAL);
    28322834                return EINVAL;
    28332835        }
     
    28362838            dataptr);
    28372839        if (msg == 0) {
    2838                 ipc_answer_0(callid, EINVAL);
     2840                ipc_answer_0(chandle, EINVAL);
    28392841                return EINVAL;
    28402842        }
    28412843       
    2842         int retval = ipc_forward_fast(callid, exch->phone, 0, 0, 0,
     2844        int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
    28432845            IPC_FF_ROUTE_FROM_ME);
    28442846        if (retval != EOK) {
    28452847                async_forget(msg);
    2846                 ipc_answer_0(callid, retval);
     2848                ipc_answer_0(chandle, retval);
    28472849                return retval;
    28482850        }
     
    28802882 * So far, this wrapper is to be used from within a connection fibril.
    28812883 *
    2882  * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
    2883  * @param size   Storage for the suggested size. May be NULL.
    2884  *
    2885  * @return True on success, false on failure.
    2886  *
    2887  */
    2888 bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
     2884 * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
     2885 * @param size     Storage for the suggested size. May be NULL.
     2886 *
     2887 * @return  True on success, false on failure.
     2888 *
     2889 */
     2890bool async_data_write_receive(cap_handle_t *chandle, size_t *size)
    28892891{
    28902892        ipc_call_t data;
    2891         return async_data_write_receive_call(callid, &data, size);
     2893        return async_data_write_receive_call(chandle, &data, size);
    28922894}
    28932895
     
    29002902 * So far, this wrapper is to be used from within a connection fibril.
    29012903 *
    2902  * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
    2903  * @param data   Storage for the ipc call data.
    2904  * @param size   Storage for the suggested size. May be NULL.
     2904 * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
     2905 * @param data     Storage for the ipc call data.
     2906 * @param size     Storage for the suggested size. May be NULL.
    29052907 *
    29062908 * @return True on success, false on failure.
    29072909 *
    29082910 */
    2909 bool async_data_write_receive_call(ipc_callid_t *callid, ipc_call_t *data,
     2911bool async_data_write_receive_call(cap_handle_t *chandle, ipc_call_t *data,
    29102912    size_t *size)
    29112913{
    2912         assert(callid);
     2914        assert(chandle);
    29132915        assert(data);
    29142916       
    2915         *callid = async_get_call(data);
     2917        *chandle = async_get_call(data);
    29162918       
    29172919        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE)
     
    29302932 * argument.
    29312933 *
    2932  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    2933  * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
    2934  * @param size   Final size for the IPC_M_DATA_WRITE call.
    2935  *
    2936  * @return Zero on success or a value from @ref errno.h on failure.
    2937  *
    2938  */
    2939 int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
    2940 {
    2941         return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
     2934 * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
     2935 * @param dst      Final destination address for the IPC_M_DATA_WRITE call.
     2936 * @param size     Final size for the IPC_M_DATA_WRITE call.
     2937 *
     2938 * @return  Zero on success or a value from @ref errno.h on failure.
     2939 *
     2940 */
     2941int async_data_write_finalize(cap_handle_t chandle, void *dst, size_t size)
     2942{
     2943        return ipc_answer_2(chandle, EOK, (sysarg_t) dst, (sysarg_t) size);
    29422944}
    29432945
     
    29692971        assert(data);
    29702972       
    2971         ipc_callid_t callid;
     2973        cap_handle_t chandle;
    29722974        size_t size;
    2973         if (!async_data_write_receive(&callid, &size)) {
    2974                 ipc_answer_0(callid, EINVAL);
     2975        if (!async_data_write_receive(&chandle, &size)) {
     2976                ipc_answer_0(chandle, EINVAL);
    29752977                return EINVAL;
    29762978        }
    29772979       
    29782980        if (size < min_size) {
    2979                 ipc_answer_0(callid, EINVAL);
     2981                ipc_answer_0(chandle, EINVAL);
    29802982                return EINVAL;
    29812983        }
    29822984       
    29832985        if ((max_size > 0) && (size > max_size)) {
    2984                 ipc_answer_0(callid, EINVAL);
     2986                ipc_answer_0(chandle, EINVAL);
    29852987                return EINVAL;
    29862988        }
    29872989       
    29882990        if ((granularity > 0) && ((size % granularity) != 0)) {
    2989                 ipc_answer_0(callid, EINVAL);
     2991                ipc_answer_0(chandle, EINVAL);
    29902992                return EINVAL;
    29912993        }
     
    29993001       
    30003002        if (arg_data == NULL) {
    3001                 ipc_answer_0(callid, ENOMEM);
     3003                ipc_answer_0(chandle, ENOMEM);
    30023004                return ENOMEM;
    30033005        }
    30043006       
    3005         int rc = async_data_write_finalize(callid, arg_data, size);
     3007        int rc = async_data_write_finalize(chandle, arg_data, size);
    30063008        if (rc != EOK) {
    30073009                free(arg_data);
     
    30283030void async_data_write_void(sysarg_t retval)
    30293031{
    3030         ipc_callid_t callid;
    3031         async_data_write_receive(&callid, NULL);
    3032         ipc_answer_0(callid, retval);
     3032        cap_handle_t chandle;
     3033        async_data_write_receive(&chandle, NULL);
     3034        ipc_answer_0(chandle, retval);
    30333035}
    30343036
     
    30433045                return ENOENT;
    30443046       
    3045         ipc_callid_t callid;
    3046         if (!async_data_write_receive(&callid, NULL)) {
    3047                 ipc_answer_0(callid, EINVAL);
     3047        cap_handle_t chandle;
     3048        if (!async_data_write_receive(&chandle, NULL)) {
     3049                ipc_answer_0(chandle, EINVAL);
    30483050                return EINVAL;
    30493051        }
     
    30523054            dataptr);
    30533055        if (msg == 0) {
    3054                 ipc_answer_0(callid, EINVAL);
     3056                ipc_answer_0(chandle, EINVAL);
    30553057                return EINVAL;
    30563058        }
    30573059       
    3058         int retval = ipc_forward_fast(callid, exch->phone, 0, 0, 0,
     3060        int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
    30593061            IPC_FF_ROUTE_FROM_ME);
    30603062        if (retval != EOK) {
    30613063                async_forget(msg);
    3062                 ipc_answer_0(callid, retval);
     3064                ipc_answer_0(chandle, retval);
    30633065                return retval;
    30643066        }
     
    30853087        /* Accept the phone */
    30863088        ipc_call_t call;
    3087         ipc_callid_t callid = async_get_call(&call);
    3088         int phone = (int) IPC_GET_ARG5(call);
    3089        
    3090         if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) ||
    3091             (phone < 0)) {
    3092                 async_answer_0(callid, EINVAL);
     3089        cap_handle_t chandle = async_get_call(&call);
     3090        cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call);
     3091       
     3092        if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) {
     3093                async_answer_0(chandle, EINVAL);
    30933094                return NULL;
    30943095        }
     
    30963097        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    30973098        if (sess == NULL) {
    3098                 async_answer_0(callid, ENOMEM);
     3099                async_answer_0(chandle, ENOMEM);
    30993100                return NULL;
    31003101        }
     
    31023103        sess->iface = 0;
    31033104        sess->mgmt = mgmt;
    3104         sess->phone = phone;
     3105        sess->phone = phandle;
    31053106        sess->arg1 = 0;
    31063107        sess->arg2 = 0;
     
    31153116       
    31163117        /* Acknowledge the connected phone */
    3117         async_answer_0(callid, EOK);
     3118        async_answer_0(chandle, EOK);
    31183119       
    31193120        return sess;
     
    31363137async_sess_t *async_callback_receive_start(exch_mgmt_t mgmt, ipc_call_t *call)
    31373138{
    3138         int phone = (int) IPC_GET_ARG5(*call);
    3139        
    3140         if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) ||
    3141             (phone < 0))
     3139        cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(*call);
     3140       
     3141        if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || (phandle < 0))
    31423142                return NULL;
    31433143       
     
    31483148        sess->iface = 0;
    31493149        sess->mgmt = mgmt;
    3150         sess->phone = phone;
     3150        sess->phone = phandle;
    31513151        sess->arg1 = 0;
    31523152        sess->arg2 = 0;
     
    31703170}
    31713171
    3172 bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1,
     3172bool async_state_change_receive(cap_handle_t *chandle, sysarg_t *arg1,
    31733173    sysarg_t *arg2, sysarg_t *arg3)
    31743174{
    3175         assert(callid);
     3175        assert(chandle);
    31763176       
    31773177        ipc_call_t call;
    3178         *callid = async_get_call(&call);
     3178        *chandle = async_get_call(&call);
    31793179       
    31803180        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
     
    31913191}
    31923192
    3193 int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch)
    3194 {
    3195         return ipc_answer_1(callid, EOK, other_exch->phone);
     3193int async_state_change_finalize(cap_handle_t chandle, async_exch_t *other_exch)
     3194{
     3195        return ipc_answer_1(chandle, EOK, other_exch->phone);
    31963196}
    31973197
Note: See TracChangeset for help on using the changeset viewer.