Changeset 01c3bb4 in mainline for uspace/lib/c


Ignore:
Timestamp:
2017-11-25T15:43:25Z (8 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.

Location:
uspace/lib/c
Files:
5 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
  • uspace/lib/c/generic/ipc.c

    r98cb5e0d r01c3bb4  
    5959        struct {
    6060                ipc_call_t data;
    61                 int phoneid;
    6261        } msg;
    6362} async_call_t;
     
    9190/** Epilogue for ipc_call_async_*() functions.
    9291 *
    93  * @param callid      Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
    94  * @param phoneid     Phone handle through which the call was made.
    95  * @param call        Structure returned by ipc_prepare_async().
    96  */
    97 static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
    98     async_call_t *call)
     92 * @param rc       Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
     93 * @param call     Structure returned by ipc_prepare_async().
     94 */
     95static inline void ipc_finish_async(int rc, async_call_t *call)
    9996{
    10097        if (!call) {
     
    103100        }
    104101       
    105         if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
     102        if (rc == IPC_CALLRET_FATAL) {
    106103                /* Call asynchronous handler with error code */
    107104                if (call->callback)
     
    124121 * error code. If the call cannot be temporarily made, it is queued.
    125122 *
    126  * @param phoneid     Phone handle for the call.
    127  * @param imethod     Requested interface and method.
    128  * @param arg1        Service-defined payload argument.
    129  * @param arg2        Service-defined payload argument.
    130  * @param arg3        Service-defined payload argument.
    131  * @param private     Argument to be passed to the answer/error callback.
    132  * @param callback    Answer or error callback.
    133  */
    134 void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
     123 * @param phandle   Phone handle for the call.
     124 * @param imethod   Requested interface and method.
     125 * @param arg1      Service-defined payload argument.
     126 * @param arg2      Service-defined payload argument.
     127 * @param arg3      Service-defined payload argument.
     128 * @param private   Argument to be passed to the answer/error callback.
     129 * @param callback  Answer or error callback.
     130 */
     131void ipc_call_async_fast(cap_handle_t phandle, sysarg_t imethod, sysarg_t arg1,
    135132    sysarg_t arg2, sysarg_t arg3, void *private, ipc_async_callback_t callback)
    136133{
     
    139136                return;
    140137       
    141         ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
    142             imethod, arg1, arg2, arg3, (sysarg_t) call);
    143        
    144         ipc_finish_async(callid, phoneid, call);
     138        int rc = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phandle, imethod, arg1,
     139            arg2, arg3, (sysarg_t) call);
     140       
     141        ipc_finish_async(rc, call);
    145142}
    146143
     
    153150 * error code. If the call cannot be temporarily made, it is queued.
    154151 *
    155  * @param phoneid     Phone handle for the call.
    156  * @param imethod     Requested interface and method.
    157  * @param arg1        Service-defined payload argument.
    158  * @param arg2        Service-defined payload argument.
    159  * @param arg3        Service-defined payload argument.
    160  * @param arg4        Service-defined payload argument.
    161  * @param arg5        Service-defined payload argument.
    162  * @param private     Argument to be passed to the answer/error callback.
    163  * @param callback    Answer or error callback.
    164  */
    165 void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
     152 * @param phandle   Phone handle for the call.
     153 * @param imethod   Requested interface and method.
     154 * @param arg1      Service-defined payload argument.
     155 * @param arg2      Service-defined payload argument.
     156 * @param arg3      Service-defined payload argument.
     157 * @param arg4      Service-defined payload argument.
     158 * @param arg5      Service-defined payload argument.
     159 * @param private   Argument to be passed to the answer/error callback.
     160 * @param callback  Answer or error callback.
     161 */
     162void ipc_call_async_slow(int phandle, sysarg_t imethod, sysarg_t arg1,
    166163    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
    167164    ipc_async_callback_t callback)
     
    178175        IPC_SET_ARG5(call->msg.data, arg5);
    179176       
    180         ipc_callid_t callid = __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phoneid,
     177        int rc = __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phandle,
    181178            (sysarg_t) &call->msg.data, (sysarg_t) call);
    182179       
    183         ipc_finish_async(callid, phoneid, call);
     180        ipc_finish_async(rc, call);
    184181}
    185182
     
    189186 * registers. If you need to return more, use the ipc_answer_slow() instead.
    190187 *
    191  * @param callid Hash of the call being answered.
    192  * @param retval Return value.
    193  * @param arg1   First return argument.
    194  * @param arg2   Second return argument.
    195  * @param arg3   Third return argument.
    196  * @param arg4   Fourth return argument.
     188 * @param chandle  Handle of the call being answered.
     189 * @param retval   Return value.
     190 * @param arg1     First return argument.
     191 * @param arg2     Second return argument.
     192 * @param arg3     Third return argument.
     193 * @param arg4     Fourth return argument.
    197194 *
    198195 * @return Zero on success.
     
    200197 *
    201198 */
    202 sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     199sysarg_t ipc_answer_fast(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    203200    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    204201{
    205         return __SYSCALL6(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2, arg3,
    206             arg4);
     202        return __SYSCALL6(SYS_IPC_ANSWER_FAST, chandle, retval, arg1, arg2,
     203            arg3, arg4);
    207204}
    208205
    209206/** Answer received call (entire payload).
    210207 *
    211  * @param callid Hash of the call being answered.
    212  * @param retval Return value.
    213  * @param arg1   First return argument.
    214  * @param arg2   Second return argument.
    215  * @param arg3   Third return argument.
    216  * @param arg4   Fourth return argument.
    217  * @param arg5   Fifth return argument.
     208 * @param chandle  Handle of the call being answered.
     209 * @param retval   Return value.
     210 * @param arg1     First return argument.
     211 * @param arg2     Second return argument.
     212 * @param arg3     Third return argument.
     213 * @param arg4     Fourth return argument.
     214 * @param arg5     Fifth return argument.
    218215 *
    219216 * @return Zero on success.
     
    221218 *
    222219 */
    223 sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     220sysarg_t ipc_answer_slow(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    224221    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
    225222{
     
    233230        IPC_SET_ARG5(data, arg5);
    234231       
    235         return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
     232        return __SYSCALL2(SYS_IPC_ANSWER_SLOW, chandle, (sysarg_t) &data);
    236233}
    237234
    238235/** Handle received answer.
    239236 *
    240  * @param callid Hash of the received answer.
    241  * @param data   Call data of the answer.
    242  */
    243 static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
     237 * @param data  Call data of the answer.
     238 */
     239static void handle_answer(ipc_call_t *data)
    244240{
    245241        async_call_t *call = data->label;
     
    255251/** Wait for first IPC call to come.
    256252 *
     253 * @param call   Incoming call storage.
     254 * @param usec   Timeout in microseconds
     255 * @param flags  Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
     256 *
     257 * @return  Call handle.
     258 * @return  Negative error code.
     259 */
     260cap_handle_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, unsigned int flags)
     261{
     262        cap_handle_t chandle =
     263            __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
     264       
     265        /* Handle received answers */
     266        if ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED))
     267                handle_answer(call);
     268       
     269        return chandle;
     270}
     271
     272/** Interrupt one thread of this task from waiting for IPC.
     273 *
     274 */
     275void ipc_poke(void)
     276{
     277        __SYSCALL0(SYS_IPC_POKE);
     278}
     279
     280/** Wait for first IPC call to come.
     281 *
     282 * Only requests are returned, answers are processed internally.
     283 *
    257284 * @param call  Incoming call storage.
    258285 * @param usec  Timeout in microseconds
    259  * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
    260  *
    261  * @return Hash of the call.
    262  */
    263 ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec,
    264     unsigned int flags)
    265 {
    266         ipc_callid_t callid =
    267             __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
    268        
    269         /* Handle received answers */
    270         if (callid && (call->flags & IPC_CALLID_ANSWERED))
    271                 handle_answer(callid, call);
    272        
    273         return callid;
    274 }
    275 
    276 /** Interrupt one thread of this task from waiting for IPC.
    277  *
    278  */
    279 void ipc_poke(void)
    280 {
    281         __SYSCALL0(SYS_IPC_POKE);
    282 }
    283 
    284 /** Wait for first IPC call to come.
     286 *
     287 * @return  Call handle.
     288 * @return  Negative error code.
     289 *
     290 */
     291cap_handle_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
     292{
     293        cap_handle_t chandle;
     294       
     295        do {
     296                chandle = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
     297        } while ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED));
     298       
     299        return chandle;
     300}
     301
     302/** Check if there is an IPC call waiting to be picked up.
    285303 *
    286304 * Only requests are returned, answers are processed internally.
    287305 *
    288  * @param call Incoming call storage.
    289  * @param usec Timeout in microseconds
    290  *
    291  * @return Hash of the call.
    292  *
    293  */
    294 ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
    295 {
    296         ipc_callid_t callid;
     306 * @param call  Incoming call storage.
     307 *
     308 * @return  Call handle.
     309 * @return  Negative error code.
     310 *
     311 */
     312cap_handle_t ipc_trywait_for_call(ipc_call_t *call)
     313{
     314        cap_handle_t chandle;
    297315       
    298316        do {
    299                 callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
    300         } while (callid && (call->flags & IPC_CALLID_ANSWERED));
    301        
    302         return callid;
    303 }
    304 
    305 /** Check if there is an IPC call waiting to be picked up.
    306  *
    307  * Only requests are returned, answers are processed internally.
    308  *
    309  * @param call Incoming call storage.
    310  *
    311  * @return Hash of the call.
    312  *
    313  */
    314 ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
    315 {
    316         ipc_callid_t callid;
    317        
    318         do {
    319                 callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
     317                chandle = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
    320318                    SYNCH_FLAGS_NON_BLOCKING);
    321         } while (callid && (call->flags & IPC_CALLID_ANSWERED));
    322        
    323         return callid;
     319        } while ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED));
     320       
     321        return chandle;
    324322}
    325323
    326324/** Hang up a phone.
    327325 *
    328  * @param phoneid Handle of the phone to be hung up.
    329  *
    330  * @return Zero on success or a negative error code.
    331  *
    332  */
    333 int ipc_hangup(int phoneid)
    334 {
    335         return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
     326 * @param phandle Handle of the phone to be hung up.
     327 *
     328 * @return  Zero on success or a negative error code.
     329 *
     330 */
     331int ipc_hangup(cap_handle_t phandle)
     332{
     333        return __SYSCALL1(SYS_IPC_HANGUP, phandle);
    336334}
    337335
    338336/** Forward a received call to another destination.
    339337 *
    340  * For non-system methods, the old method, arg1 and arg2 are rewritten
    341  * by the new values. For system methods, the new method, arg1 and arg2
    342  * are written to the old arg1, arg2 and arg3, respectivelly. Calls with
    343  * immutable methods are forwarded verbatim.
    344  *
    345  * @param callid  Hash of the call to forward.
    346  * @param phoneid Phone handle to use for forwarding.
    347  * @param imethod New interface and method for the forwarded call.
    348  * @param arg1    New value of the first argument for the forwarded call.
    349  * @param arg2    New value of the second argument for the forwarded call.
    350  * @param mode    Flags specifying mode of the forward operation.
    351  *
    352  * @return Zero on success or an error code.
    353  *
    354  */
    355 int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    356     sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    357 {
    358         return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
     338 * For non-system methods, the old method, arg1 and arg2 are rewritten by the
     339 * new values. For system methods, the new method, arg1 and arg2 are written to
     340 * the old arg1, arg2 and arg3, respectivelly. Calls with immutable methods are
     341 * forwarded verbatim.
     342 *
     343 * @param chandle  Handle of the call to forward.
     344 * @param phandle Phone handle to use for forwarding.
     345 * @param imethod  New interface and method for the forwarded call.
     346 * @param arg1     New value of the first argument for the forwarded call.
     347 * @param arg2     New value of the second argument for the forwarded call.
     348 * @param mode     Flags specifying mode of the forward operation.
     349 *
     350 * @return  Zero on success or an error code.
     351 *
     352 */
     353int ipc_forward_fast(cap_handle_t chandle, cap_handle_t phandle,
     354    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
     355{
     356        return __SYSCALL6(SYS_IPC_FORWARD_FAST, chandle, phandle, imethod, arg1,
    359357            arg2, mode);
    360358}
    361359
    362 int ipc_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    363     sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    364     unsigned int mode)
     360int ipc_forward_slow(cap_handle_t chandle, cap_handle_t phandle,
     361    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
     362    sysarg_t arg4, sysarg_t arg5, unsigned int mode)
    365363{
    366364        ipc_call_t data;
     
    373371        IPC_SET_ARG5(data, arg5);
    374372       
    375         return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
    376             mode);
     373        return __SYSCALL4(SYS_IPC_FORWARD_SLOW, chandle, phandle,
     374            (sysarg_t) &data, mode);
    377375}
    378376
  • uspace/lib/c/include/async.h

    r98cb5e0d r01c3bb4  
    4949#include <abi/ipc/event.h>
    5050#include <abi/ipc/interfaces.h>
    51 
    52 typedef ipc_callid_t aid_t;
     51#include <abi/cap.h>
     52
     53typedef sysarg_t aid_t;
    5354typedef sysarg_t port_id_t;
    5455
     
    5859/** Port connection handler
    5960 *
    60  * @param callid ID of incoming call or 0 if connection initiated from
    61  *               inside using async_create_callback_port()
    62  * @param call   Incoming call or 0 if connection initiated from inside
    63  *               using async_create_callback_port()
    64  * @param arg    Local argument.
    65  *
    66  */
    67 typedef void (*async_port_handler_t)(ipc_callid_t, ipc_call_t *, void *);
     61 * @param chandle  Handle of the incoming call or CAP_NIL if connection
     62 *                 initiated from inside using async_create_callback_port()
     63 * @param call     Incoming call or 0 if connection initiated from inside
     64 *                 using async_create_callback_port()
     65 * @param arg      Local argument.
     66 *
     67 */
     68typedef void (*async_port_handler_t)(cap_handle_t, ipc_call_t *, void *);
    6869
    6970/** Notification handler */
    70 typedef void (*async_notification_handler_t)(ipc_callid_t, ipc_call_t *,
    71     void *);
     71typedef void (*async_notification_handler_t)(ipc_call_t *, void *);
    7272
    7373/** Exchange management style
     
    119119        async_get_call_timeout(data, 0)
    120120
    121 extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t);
     121extern cap_handle_t async_get_call_timeout(ipc_call_t *, suseconds_t);
    122122
    123123/*
     
    196196 */
    197197
    198 extern sysarg_t async_answer_0(ipc_callid_t, sysarg_t);
    199 extern sysarg_t async_answer_1(ipc_callid_t, sysarg_t, sysarg_t);
    200 extern sysarg_t async_answer_2(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t);
    201 extern sysarg_t async_answer_3(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
     198extern sysarg_t async_answer_0(cap_handle_t, sysarg_t);
     199extern sysarg_t async_answer_1(cap_handle_t, sysarg_t, sysarg_t);
     200extern sysarg_t async_answer_2(cap_handle_t, sysarg_t, sysarg_t, sysarg_t);
     201extern sysarg_t async_answer_3(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
    202202    sysarg_t);
    203 extern sysarg_t async_answer_4(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
     203extern sysarg_t async_answer_4(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
    204204    sysarg_t, sysarg_t);
    205 extern sysarg_t async_answer_5(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
     205extern sysarg_t async_answer_5(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
    206206    sysarg_t, sysarg_t, sysarg_t);
    207207
     
    210210 */
    211211
    212 extern int async_forward_fast(ipc_callid_t, async_exch_t *, sysarg_t, sysarg_t,
     212extern int async_forward_fast(cap_handle_t, async_exch_t *, sysarg_t, sysarg_t,
    213213    sysarg_t, unsigned int);
    214 extern int async_forward_slow(ipc_callid_t, async_exch_t *, sysarg_t, sysarg_t,
     214extern int async_forward_slow(cap_handle_t, async_exch_t *, sysarg_t, sysarg_t,
    215215    sysarg_t, sysarg_t, sysarg_t, sysarg_t, unsigned int);
    216216
     
    382382extern int async_share_in_start(async_exch_t *, size_t, sysarg_t,
    383383    unsigned int *, void **);
    384 extern bool async_share_in_receive(ipc_callid_t *, size_t *);
    385 extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
     384extern bool async_share_in_receive(cap_handle_t *, size_t *);
     385extern int async_share_in_finalize(cap_handle_t, void *, unsigned int);
    386386
    387387extern int async_share_out_start(async_exch_t *, void *, unsigned int);
    388 extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
    389 extern int async_share_out_finalize(ipc_callid_t, void **);
     388extern bool async_share_out_receive(cap_handle_t *, size_t *, unsigned int *);
     389extern int async_share_out_finalize(cap_handle_t, void **);
    390390
    391391/*
     
    421421extern aid_t async_data_read(async_exch_t *, void *, size_t, ipc_call_t *);
    422422extern int async_data_read_start(async_exch_t *, void *, size_t);
    423 extern bool async_data_read_receive(ipc_callid_t *, size_t *);
    424 extern bool async_data_read_receive_call(ipc_callid_t *, ipc_call_t *, size_t *);
    425 extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
     423extern bool async_data_read_receive(cap_handle_t *, size_t *);
     424extern bool async_data_read_receive_call(cap_handle_t *, ipc_call_t *, size_t *);
     425extern int async_data_read_finalize(cap_handle_t, const void *, size_t);
    426426
    427427extern int async_data_read_forward_fast(async_exch_t *, sysarg_t, sysarg_t,
     
    460460
    461461extern int async_data_write_start(async_exch_t *, const void *, size_t);
    462 extern bool async_data_write_receive(ipc_callid_t *, size_t *);
    463 extern bool async_data_write_receive_call(ipc_callid_t *, ipc_call_t *, size_t *);
    464 extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
     462extern bool async_data_write_receive(cap_handle_t *, size_t *);
     463extern bool async_data_write_receive_call(cap_handle_t *, ipc_call_t *, size_t *);
     464extern int async_data_write_finalize(cap_handle_t, void *, size_t);
    465465
    466466extern int async_data_write_accept(void **, const bool, const size_t,
     
    476476extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t,
    477477    sysarg_t, async_exch_t *);
    478 extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *,
     478extern bool async_state_change_receive(cap_handle_t *, sysarg_t *, sysarg_t *,
    479479    sysarg_t *);
    480 extern int async_state_change_finalize(ipc_callid_t, async_exch_t *);
     480extern int async_state_change_finalize(cap_handle_t, async_exch_t *);
    481481
    482482extern void *async_remote_state_acquire(async_sess_t *);
  • uspace/lib/c/include/ipc/common.h

    r98cb5e0d r01c3bb4  
    4040#include <abi/proc/task.h>
    4141#include <futex.h>
     42#include <abi/cap.h>
    4243
    4344#define IPC_FLAG_BLOCKING  0x01
     
    5354} ipc_call_t;
    5455
    55 typedef sysarg_t ipc_callid_t;
     56typedef cap_handle_t ipc_callid_t;
    5657
    5758extern futex_t async_futex;
  • uspace/lib/c/include/ipc/ipc.h

    r98cb5e0d r01c3bb4  
    4444#include <abi/synch.h>
    4545#include <abi/proc/task.h>
     46#include <abi/cap.h>
    4647
    4748typedef void (*ipc_async_callback_t)(void *, int, ipc_call_t *);
    4849
    49 extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
     50extern cap_handle_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
    5051extern void ipc_poke(void);
    5152
     
    5354        ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
    5455
    55 extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
    56 extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
     56extern cap_handle_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
     57extern cap_handle_t ipc_trywait_for_call(ipc_call_t *);
    5758
    5859/*
     
    6364 */
    6465
    65 #define ipc_answer_0(callid, retval) \
    66         ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
    67 #define ipc_answer_1(callid, retval, arg1) \
    68         ipc_answer_fast((callid), (retval), (arg1), 0, 0, 0)
    69 #define ipc_answer_2(callid, retval, arg1, arg2) \
    70         ipc_answer_fast((callid), (retval), (arg1), (arg2), 0, 0)
    71 #define ipc_answer_3(callid, retval, arg1, arg2, arg3) \
    72         ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), 0)
    73 #define ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4) \
    74         ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), (arg4))
    75 #define ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5) \
    76         ipc_answer_slow((callid), (retval), (arg1), (arg2), (arg3), (arg4), (arg5))
     66#define ipc_answer_0(chandle, retval) \
     67        ipc_answer_fast((chandle), (retval), 0, 0, 0, 0)
     68#define ipc_answer_1(chandle, retval, arg1) \
     69        ipc_answer_fast((chandle), (retval), (arg1), 0, 0, 0)
     70#define ipc_answer_2(chandle, retval, arg1, arg2) \
     71        ipc_answer_fast((chandle), (retval), (arg1), (arg2), 0, 0)
     72#define ipc_answer_3(chandle, retval, arg1, arg2, arg3) \
     73        ipc_answer_fast((chandle), (retval), (arg1), (arg2), (arg3), 0)
     74#define ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4) \
     75        ipc_answer_fast((chandle), (retval), (arg1), (arg2), (arg3), (arg4))
     76#define ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5) \
     77        ipc_answer_slow((chandle), (retval), (arg1), (arg2), (arg3), (arg4), \
     78            (arg5))
    7779
    78 extern sysarg_t ipc_answer_fast(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
     80extern sysarg_t ipc_answer_fast(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
    7981    sysarg_t, sysarg_t);
    80 extern sysarg_t ipc_answer_slow(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
     82extern sysarg_t ipc_answer_slow(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
    8183    sysarg_t, sysarg_t, sysarg_t);
    8284
     
    8890 */
    8991
    90 #define ipc_call_async_0(phoneid, method, private, callback) \
    91         ipc_call_async_fast((phoneid), (method), 0, 0, 0, (private), (callback))
    92 #define ipc_call_async_1(phoneid, method, arg1, private, callback) \
    93         ipc_call_async_fast((phoneid), (method), (arg1), 0, 0, (private), \
     92#define ipc_call_async_0(phandle, method, private, callback) \
     93        ipc_call_async_fast((phandle), (method), 0, 0, 0, (private), (callback))
     94#define ipc_call_async_1(phandle, method, arg1, private, callback) \
     95        ipc_call_async_fast((phandle), (method), (arg1), 0, 0, (private), \
    9496            (callback))
    95 #define ipc_call_async_2(phoneid, method, arg1, arg2, private, callback) \
    96         ipc_call_async_fast((phoneid), (method), (arg1), (arg2), 0, \
     97#define ipc_call_async_2(phandle, method, arg1, arg2, private, callback) \
     98        ipc_call_async_fast((phandle), (method), (arg1), (arg2), 0, \
    9799            (private), (callback))
    98 #define ipc_call_async_3(phoneid, method, arg1, arg2, arg3, private, callback) \
    99         ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     100#define ipc_call_async_3(phandle, method, arg1, arg2, arg3, private, callback) \
     101        ipc_call_async_fast((phandle), (method), (arg1), (arg2), (arg3), \
    100102            (private), (callback))
    101 #define ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, private, \
     103#define ipc_call_async_4(phandle, method, arg1, arg2, arg3, arg4, private, \
    102104    callback) \
    103         ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
     105        ipc_call_async_slow((phandle), (method), (arg1), (arg2), (arg3), \
    104106            (arg4), 0, (private), (callback))
    105 #define ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, \
     107#define ipc_call_async_5(phandle, method, arg1, arg2, arg3, arg4, arg5, \
    106108    private, callback) \
    107         ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
     109        ipc_call_async_slow((phandle), (method), (arg1), (arg2), (arg3), \
    108110            (arg4), (arg5), (private), (callback))
    109111
    110 extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    111     void *, ipc_async_callback_t);
    112 extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    113     sysarg_t, sysarg_t, void *, ipc_async_callback_t);
     112extern void ipc_call_async_fast(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
     113    sysarg_t, void *, ipc_async_callback_t);
     114extern void ipc_call_async_slow(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
     115    sysarg_t, sysarg_t, sysarg_t, void *, ipc_async_callback_t);
    114116
    115 extern int ipc_hangup(int);
     117extern int ipc_hangup(cap_handle_t);
    116118
    117 extern int ipc_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
    118     unsigned int);
    119 extern int ipc_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
    120     sysarg_t, sysarg_t, sysarg_t, unsigned int);
     119extern int ipc_forward_fast(cap_handle_t, cap_handle_t, sysarg_t, sysarg_t,
     120    sysarg_t, unsigned int);
     121extern int ipc_forward_slow(cap_handle_t, cap_handle_t, sysarg_t, sysarg_t,
     122    sysarg_t, sysarg_t, sysarg_t, sysarg_t, unsigned int);
    121123
    122124extern int ipc_connect_kbox(task_id_t);
Note: See TracChangeset for help on using the changeset viewer.