Ignore:
File:
1 edited

Legend:

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

    r4d6629f r569a51a  
    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 *   }
     
    106106#include <fibril.h>
    107107#include <adt/hash_table.h>
     108#include <adt/hash.h>
    108109#include <adt/list.h>
    109110#include <assert.h>
     
    112113#include <libarch/barrier.h>
    113114#include <stdbool.h>
    114 #include <malloc.h>
     115#include <stdlib.h>
    115116#include <mem.h>
    116117#include <stdlib.h>
     
    184185        link_t link;
    185186       
    186         ipc_callid_t callid;
     187        cap_handle_t chandle;
    187188        ipc_call_t call;
    188189} msg_t;
     
    236237       
    237238        /** Identification of the opening call. */
    238         ipc_callid_t callid;
     239        cap_handle_t chandle;
    239240       
    240241        /** Call data of the opening call. */
     
    242243       
    243244        /** Identification of the closing call. */
    244         ipc_callid_t close_callid;
     245        cap_handle_t close_chandle;
    245246       
    246247        /** Fibril function that will be used to handle the connection. */
     
    373374/** Default fallback fibril function.
    374375 *
    375  * This fallback fibril function gets called on incomming
    376  * connections that do not have a specific handler defined.
    377  *
    378  * @param callid Hash of the incoming call.
    379  * @param call   Data of the incoming call.
    380  * @param arg    Local argument
    381  *
    382  */
    383 static void default_fallback_port_handler(ipc_callid_t callid, ipc_call_t *call,
    384     void *arg)
    385 {
    386         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);
    387388}
    388389
     
    587588};
    588589
    589 /** Compute hash into the connection hash table based on the source phone hash.
    590  *
    591  * @param key Pointer to source phone hash.
     590typedef struct {
     591        task_id_t task_id;
     592        sysarg_t phone_hash;
     593} conn_key_t;
     594
     595/** Compute hash into the connection hash table
     596 *
     597 * The hash is based on the source task ID and the source phone hash. The task
     598 * ID is included in the hash because a phone hash alone might not be unique
     599 * while we still track connections for killed tasks due to kernel's recycling
     600 * of phone structures.
     601 *
     602 * @param key Pointer to the connection key structure.
    592603 *
    593604 * @return Index into the connection hash table.
     
    596607static size_t conn_key_hash(void *key)
    597608{
    598         sysarg_t in_phone_hash = *(sysarg_t *) key;
    599         return in_phone_hash;
     609        conn_key_t *ck = (conn_key_t *) key;
     610
     611        size_t hash = 0;
     612        hash = hash_combine(hash, LOWER32(ck->task_id));
     613        hash = hash_combine(hash, UPPER32(ck->task_id));
     614        hash = hash_combine(hash, ck->phone_hash);
     615        return hash;
    600616}
    601617
     
    603619{
    604620        connection_t *conn = hash_table_get_inst(item, connection_t, link);
    605         return conn_key_hash(&conn->in_phone_hash);
     621        return conn_key_hash(&(conn_key_t){
     622                .task_id = conn->in_task_id,
     623                .phone_hash = conn->in_phone_hash
     624        });
    606625}
    607626
    608627static bool conn_key_equal(void *key, const ht_link_t *item)
    609628{
    610         sysarg_t in_phone_hash = *(sysarg_t *) key;
     629        conn_key_t *ck = (conn_key_t *) key;
    611630        connection_t *conn = hash_table_get_inst(item, connection_t, link);
    612         return (in_phone_hash == conn->in_phone_hash);
     631        return ((ck->task_id == conn->in_task_id) &&
     632            (ck->phone_hash == conn->in_phone_hash));
    613633}
    614634
     
    695715        client_t *client = async_client_get(fibril_connection->in_task_id, true);
    696716        if (!client) {
    697                 ipc_answer_0(fibril_connection->callid, ENOMEM);
     717                ipc_answer_0(fibril_connection->chandle, ENOMEM);
    698718                return 0;
    699719        }
     
    704724         * Call the connection handler function.
    705725         */
    706         fibril_connection->handler(fibril_connection->callid,
     726        fibril_connection->handler(fibril_connection->chandle,
    707727            &fibril_connection->call, fibril_connection->data);
    708728       
     
    716736         */
    717737        futex_down(&async_futex);
    718         hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
     738        hash_table_remove(&conn_hash_table, &(conn_key_t){
     739                .task_id = fibril_connection->in_task_id,
     740                .phone_hash = fibril_connection->in_phone_hash
     741        });
    719742        futex_up(&async_futex);
    720743       
     
    728751               
    729752                list_remove(&msg->link);
    730                 ipc_answer_0(msg->callid, EHANGUP);
     753                ipc_answer_0(msg->chandle, EHANGUP);
    731754                free(msg);
    732755        }
     
    736759         * i.e. IPC_M_PHONE_HUNGUP.
    737760         */
    738         if (fibril_connection->close_callid)
    739                 ipc_answer_0(fibril_connection->close_callid, EOK);
     761        if (fibril_connection->close_chandle)
     762                ipc_answer_0(fibril_connection->close_chandle, EOK);
    740763       
    741764        free(fibril_connection);
     
    745768/** Create a new fibril for a new connection.
    746769 *
    747  * Create new fibril for connection, fill in connection structures
    748  * and insert it into the hash table, so that later we can easily
    749  * do routing of messages to particular fibrils.
    750  *
    751  * @param in_task_id    Identification of the incoming connection.
    752  * @param in_phone_hash Identification of the incoming connection.
    753  * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
    754  *                      If callid is zero, the connection was opened by
    755  *                      accepting the IPC_M_CONNECT_TO_ME call and this
    756  *                      function is called directly by the server.
    757  * @param call          Call data of the opening call.
    758  * @param handler       Connection handler.
    759  * @param data          Client argument to pass to the connection handler.
    760  *
    761  * @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.
    762785 *
    763786 */
    764787static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    765     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,
    766789    void *data)
    767790{
    768791        connection_t *conn = malloc(sizeof(*conn));
    769792        if (!conn) {
    770                 if (callid)
    771                         ipc_answer_0(callid, ENOMEM);
     793                if (chandle != CAP_NIL)
     794                        ipc_answer_0(chandle, ENOMEM);
    772795               
    773796                return (uintptr_t) NULL;
     
    777800        conn->in_phone_hash = in_phone_hash;
    778801        list_initialize(&conn->msg_queue);
    779         conn->callid = callid;
    780         conn->close_callid = 0;
     802        conn->chandle = chandle;
     803        conn->close_chandle = CAP_NIL;
    781804        conn->handler = handler;
    782805        conn->data = data;
     
    792815                free(conn);
    793816               
    794                 if (callid)
    795                         ipc_answer_0(callid, ENOMEM);
     817                if (chandle != CAP_NIL)
     818                        ipc_answer_0(chandle, ENOMEM);
    796819               
    797820                return (uintptr_t) NULL;
     
    869892       
    870893        fid_t fid = async_new_connection(answer.in_task_id, phone_hash,
    871             0, NULL, handler, data);
     894            CAP_NIL, NULL, handler, data);
    872895        if (fid == (uintptr_t) NULL)
    873896                return ENOMEM;
     
    938961 * timeouts are unregistered.
    939962 *
    940  * @param callid Hash of the incoming call.
    941  * @param call   Data of the incoming call.
     963 * @param chandle  Handle of the incoming call.
     964 * @param call     Data of the incoming call.
    942965 *
    943966 * @return False if the call doesn't match any connection.
     
    945968 *
    946969 */
    947 static bool route_call(ipc_callid_t callid, ipc_call_t *call)
     970static bool route_call(cap_handle_t chandle, ipc_call_t *call)
    948971{
    949972        assert(call);
     
    951974        futex_down(&async_futex);
    952975       
    953         ht_link_t *link = hash_table_find(&conn_hash_table, &call->in_phone_hash);
     976        ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){
     977                .task_id = call->in_task_id,
     978                .phone_hash = call->in_phone_hash
     979        });
    954980        if (!link) {
    955981                futex_up(&async_futex);
     
    965991        }
    966992       
    967         msg->callid = callid;
     993        msg->chandle = chandle;
    968994        msg->call = *call;
    969995        list_append(&msg->link, &conn->msg_queue);
    970996       
    971997        if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP)
    972                 conn->close_callid = callid;
     998                conn->close_chandle = chandle;
    973999       
    9741000        /* If the connection fibril is waiting for an event, activate it */
     
    9911017/** Process notification.
    9921018 *
    993  * @param callid Hash of the incoming call.
    9941019 * @param call   Data of the incoming call.
    9951020 *
    9961021 */
    997 static void process_notification(ipc_callid_t callid, ipc_call_t *call)
     1022static void process_notification(ipc_call_t *call)
    9981023{
    9991024        async_notification_handler_t handler = NULL;
     
    10161041       
    10171042        if (handler)
    1018                 handler(callid, call, data);
     1043                handler(call, data);
    10191044}
    10201045
     
    10261051 * @param ucode   Top-half pseudocode handler.
    10271052 *
    1028  * @return IRQ capability handle on success.
     1053 * @param[out] handle  IRQ capability handle on success.
     1054 *
    10291055 * @return Negative error code.
    10301056 *
    10311057 */
    10321058int async_irq_subscribe(int inr, async_notification_handler_t handler,
    1033     void *data, const irq_code_t *ucode)
     1059    void *data, const irq_code_t *ucode, cap_handle_t *handle)
    10341060{
    10351061        notification_t *notification =
     
    10511077        futex_up(&async_futex);
    10521078       
    1053         return ipc_irq_subscribe(inr, imethod, ucode);
     1079        cap_handle_t cap;
     1080        int rc = ipc_irq_subscribe(inr, imethod, ucode, &cap);
     1081        if (rc == EOK && handle != NULL) {
     1082                *handle = cap;
     1083        }
     1084        return rc;
    10541085}
    10551086
     
    11611192/** Return new incoming message for the current (fibril-local) connection.
    11621193 *
    1163  * @param call  Storage where the incoming call data will be stored.
    1164  * @param usecs Timeout in microseconds. Zero denotes no timeout.
    1165  *
    1166  * @return If no timeout was specified, then a hash of the
    1167  *         incoming call is returned. If a timeout is specified,
    1168  *         then a hash of the incoming call is returned unless
    1169  *         the timeout expires prior to receiving a message. In
    1170  *         that case zero is returned.
    1171  *
    1172  */
    1173 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
     1194 * @param call   Storage where the incoming call data will be stored.
     1195 * @param usecs  Timeout in microseconds. Zero denotes no timeout.
     1196 *
     1197 * @return  If no timeout was specified, then a handle of the incoming call is
     1198 *          returned. If a timeout is specified, then a handle of the incoming
     1199 *          call is returned unless the timeout expires prior to receiving a
     1200 *          message. In that case zero CAP_NIL is returned.
     1201 */
     1202cap_handle_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
    11741203{
    11751204        assert(call);
     
    11941223        /* If nothing in queue, wait until something arrives */
    11951224        while (list_empty(&conn->msg_queue)) {
    1196                 if (conn->close_callid) {
     1225                if (conn->close_chandle) {
    11971226                        /*
    11981227                         * Handle the case when the connection was already
     
    12051234                        IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
    12061235                        futex_up(&async_futex);
    1207                         return conn->close_callid;
     1236                        return conn->close_chandle;
    12081237                }
    12091238               
     
    12301259                        /* If we timed out -> exit */
    12311260                        futex_up(&async_futex);
    1232                         return 0;
     1261                        return CAP_NIL;
    12331262                }
    12341263        }
     
    12381267        list_remove(&msg->link);
    12391268       
    1240         ipc_callid_t callid = msg->callid;
     1269        cap_handle_t chandle = msg->chandle;
    12411270        *call = msg->call;
    12421271        free(msg);
    12431272       
    12441273        futex_up(&async_futex);
    1245         return callid;
     1274        return chandle;
    12461275}
    12471276
     
    13061335 * Otherwise the call is routed to its connection fibril.
    13071336 *
    1308  * @param callid Hash of the incoming call.
    1309  * @param call   Data of the incoming call.
    1310  *
    1311  */
    1312 static void handle_call(ipc_callid_t callid, ipc_call_t *call)
     1337 * @param chandle  Handle of the incoming call.
     1338 * @param call     Data of the incoming call.
     1339 *
     1340 */
     1341static void handle_call(cap_handle_t chandle, ipc_call_t *call)
    13131342{
    13141343        assert(call);
    13151344       
    13161345        /* Kernel notification */
    1317         if ((callid & IPC_CALLID_NOTIFICATION)) {
     1346        if ((chandle == CAP_NIL) && (call->flags & IPC_CALL_NOTIF)) {
    13181347                fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data;
    13191348                unsigned oldsw = fibril->switches;
    13201349               
    1321                 process_notification(callid, call);
     1350                process_notification(call);
    13221351               
    13231352                if (oldsw != fibril->switches) {
     
    13451374                sysarg_t in_phone_hash = IPC_GET_ARG5(*call);
    13461375               
    1347                 async_notification_handler_t handler = fallback_port_handler;
     1376                async_port_handler_t handler = fallback_port_handler;
    13481377                void *data = fallback_port_data;
    13491378               
     
    13551384                }
    13561385               
    1357                 async_new_connection(call->in_task_id, in_phone_hash, callid,
     1386                async_new_connection(call->in_task_id, in_phone_hash, chandle,
    13581387                    call, handler, data);
    13591388                return;
     
    13611390       
    13621391        /* Try to route the call through the connection hash table */
    1363         if (route_call(callid, call))
     1392        if (route_call(chandle, call))
    13641393                return;
    13651394       
    13661395        /* Unknown call from unknown phone - hang it up */
    1367         ipc_answer_0(callid, EHANGUP);
     1396        ipc_answer_0(chandle, EHANGUP);
    13681397}
    13691398
     
    14601489               
    14611490                ipc_call_t call;
    1462                 ipc_callid_t callid = ipc_wait_cycle(&call, timeout, flags);
     1491                int rc = ipc_wait_cycle(&call, timeout, flags);
    14631492               
    14641493                atomic_dec(&threads_in_ipc_wait);
    14651494               
    1466                 if (!callid) {
    1467                         handle_expired_timeouts();
     1495                assert(rc == EOK);
     1496
     1497                if (call.cap_handle == CAP_NIL) {
     1498                        if (call.flags == 0) {
     1499                                /* This neither a notification nor an answer. */
     1500                                handle_expired_timeouts();
     1501                                continue;
     1502                        }
     1503                }
     1504
     1505                if (call.flags & IPC_CALL_ANSWERED)
    14681506                        continue;
    1469                 }
    1470                
    1471                 if (callid & IPC_CALLID_ANSWERED)
    1472                         continue;
    1473                
    1474                 handle_call(callid, &call);
    1475         }
    1476        
     1507
     1508                handle_call(call.cap_handle, &call);
     1509        }
     1510
    14771511        return 0;
    14781512}
     
    16051639 * @param arg3    Service-defined payload argument.
    16061640 * @param arg4    Service-defined payload argument.
    1607  * @param dataptr If non-NULL, storage where the reply data will be
    1608  *                stored.
     1641 * @param dataptr If non-NULL, storage where the reply data will be stored.
    16091642 *
    16101643 * @return Hash of the sent message or 0 on error.
     
    18431876}
    18441877
     1878/** Delay execution for the specified number of seconds
     1879 *
     1880 * @param sec Number of seconds to sleep
     1881 */
     1882void async_sleep(unsigned int sec)
     1883{
     1884        /*
     1885         * Sleep in 1000 second steps to support
     1886         * full argument range
     1887         */
     1888
     1889        while (sec > 0) {
     1890                unsigned int period = (sec > 1000) ? 1000 : sec;
     1891
     1892                async_usleep(period * 1000000);
     1893                sec -= period;
     1894        }
     1895}
     1896
    18451897/** Pseudo-synchronous message sending - fast version.
    18461898 *
     
    19922044}
    19932045
    1994 sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval)
    1995 {
    1996         return ipc_answer_0(callid, retval);
    1997 }
    1998 
    1999 sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)
    2000 {
    2001         return ipc_answer_1(callid, retval, arg1);
    2002 }
    2003 
    2004 sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2046sysarg_t async_answer_0(cap_handle_t chandle, sysarg_t retval)
     2047{
     2048        return ipc_answer_0(chandle, retval);
     2049}
     2050
     2051sysarg_t async_answer_1(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1)
     2052{
     2053        return ipc_answer_1(chandle, retval, arg1);
     2054}
     2055
     2056sysarg_t async_answer_2(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20052057    sysarg_t arg2)
    20062058{
    2007         return ipc_answer_2(callid, retval, arg1, arg2);
    2008 }
    2009 
    2010 sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2059        return ipc_answer_2(chandle, retval, arg1, arg2);
     2060}
     2061
     2062sysarg_t async_answer_3(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20112063    sysarg_t arg2, sysarg_t arg3)
    20122064{
    2013         return ipc_answer_3(callid, retval, arg1, arg2, arg3);
    2014 }
    2015 
    2016 sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2065        return ipc_answer_3(chandle, retval, arg1, arg2, arg3);
     2066}
     2067
     2068sysarg_t async_answer_4(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20172069    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    20182070{
    2019         return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4);
    2020 }
    2021 
    2022 sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     2071        return ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4);
     2072}
     2073
     2074sysarg_t async_answer_5(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1,
    20232075    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
    20242076{
    2025         return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5);
    2026 }
    2027 
    2028 int async_forward_fast(ipc_callid_t callid, async_exch_t *exch,
     2077        return ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5);
     2078}
     2079
     2080int async_forward_fast(cap_handle_t chandle, async_exch_t *exch,
    20292081    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    20302082{
     
    20322084                return ENOENT;
    20332085       
    2034         return ipc_forward_fast(callid, exch->phone, imethod, arg1, arg2, mode);
    2035 }
    2036 
    2037 int async_forward_slow(ipc_callid_t callid, async_exch_t *exch,
     2086        return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode);
     2087}
     2088
     2089int async_forward_slow(cap_handle_t chandle, async_exch_t *exch,
    20382090    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    20392091    sysarg_t arg4, sysarg_t arg5, unsigned int mode)
     
    20422094                return ENOENT;
    20432095       
    2044         return ipc_forward_slow(callid, exch->phone, imethod, arg1, arg2, arg3,
     2096        return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3,
    20452097            arg4, arg5, mode);
    20462098}
     
    20772129
    20782130static int async_connect_me_to_internal(int phone, sysarg_t arg1, sysarg_t arg2,
    2079     sysarg_t arg3, sysarg_t arg4)
     2131    sysarg_t arg3, sysarg_t arg4, int *out_phone)
    20802132{
    20812133        ipc_call_t result;
     2134       
     2135        // XXX: Workaround for GCC's inability to infer association between
     2136        // rc == EOK and *out_phone being assigned.
     2137        *out_phone = -1;
    20822138       
    20832139        amsg_t *msg = amsg_create();
     
    20972153                return rc;
    20982154       
    2099         return (int) IPC_GET_ARG5(result);
     2155        *out_phone = (int) IPC_GET_ARG5(result);
     2156        return EOK;
    21002157}
    21012158
     
    21272184        }
    21282185       
    2129         int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
    2130             0);
    2131         if (phone < 0) {
    2132                 errno = phone;
     2186        int phone;
     2187        int rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
     2188            0, &phone);
     2189        if (rc != EOK) {
     2190                errno = rc;
    21332191                free(sess);
    21342192                return NULL;
     
    21792237        }
    21802238       
    2181         int phone = async_connect_me_to_internal(exch->phone, iface, arg2,
    2182             arg3, 0);
    2183         if (phone < 0) {
    2184                 errno = phone;
     2239        int phone;
     2240        int rc = async_connect_me_to_internal(exch->phone, iface, arg2,
     2241            arg3, 0, &phone);
     2242        if (rc != EOK) {
     2243                errno = rc;
    21852244                free(sess);
    21862245                return NULL;
     
    22492308        }
    22502309       
    2251         int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
    2252             IPC_FLAG_BLOCKING);
    2253        
    2254         if (phone < 0) {
    2255                 errno = phone;
     2310        int phone;
     2311        int rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
     2312            IPC_FLAG_BLOCKING, &phone);
     2313       
     2314        if (rc != EOK) {
     2315                errno = rc;
    22562316                free(sess);
    22572317                return NULL;
     
    23022362        }
    23032363       
    2304         int phone = async_connect_me_to_internal(exch->phone, iface, arg2,
    2305             arg3, IPC_FLAG_BLOCKING);
    2306         if (phone < 0) {
    2307                 errno = phone;
     2364        int phone;
     2365        int rc = async_connect_me_to_internal(exch->phone, iface, arg2,
     2366            arg3, IPC_FLAG_BLOCKING, &phone);
     2367        if (rc != EOK) {
     2368                errno = rc;
    23082369                free(sess);
    23092370                return NULL;
     
    23372398        }
    23382399       
    2339         int phone = ipc_connect_kbox(id);
    2340         if (phone < 0) {
    2341                 errno = phone;
     2400        cap_handle_t phone;
     2401        int rc = ipc_connect_kbox(id, &phone);
     2402        if (rc != EOK) {
     2403                errno = rc;
    23422404                free(sess);
    23432405                return NULL;
     
    24562518                } else if (mgmt == EXCHANGE_PARALLEL) {
    24572519                        int phone;
     2520                        int rc;
    24582521                       
    24592522                retry:
     
    24612524                         * Make a one-time attempt to connect a new data phone.
    24622525                         */
    2463                         phone = async_connect_me_to_internal(sess->phone, sess->arg1,
    2464                             sess->arg2, sess->arg3, 0);
    2465                         if (phone >= 0) {
     2526                        rc = async_connect_me_to_internal(sess->phone, sess->arg1,
     2527                            sess->arg2, sess->arg3, 0, &phone);
     2528                        if (rc == EOK) {
    24662529                                exch = (async_exch_t *) malloc(sizeof(async_exch_t));
    24672530                                if (exch != NULL) {
     
    25782641 * So far, this wrapper is to be used from within a connection fibril.
    25792642 *
    2580  * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
    2581  * @param size   Destination address space area size.
     2643 * @param chandle  Storage for the handle of the IPC_M_SHARE_IN call.
     2644 * @param size     Destination address space area size.
    25822645 *
    25832646 * @return True on success, false on failure.
    25842647 *
    25852648 */
    2586 bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
    2587 {
    2588         assert(callid);
     2649bool async_share_in_receive(cap_handle_t *chandle, size_t *size)
     2650{
     2651        assert(chandle);
    25892652        assert(size);
    25902653       
    25912654        ipc_call_t data;
    2592         *callid = async_get_call(&data);
     2655        *chandle = async_get_call(&data);
    25932656       
    25942657        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
     
    26052668 * argument.
    26062669 *
    2607  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    2608  * @param src    Source address space base.
    2609  * @param flags  Flags to be used for sharing. Bits can be only cleared.
     2670 * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
     2671 * @param src      Source address space base.
     2672 * @param flags    Flags to be used for sharing. Bits can be only cleared.
    26102673 *
    26112674 * @return Zero on success or a value from @ref errno.h on failure.
    26122675 *
    26132676 */
    2614 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    2615 {
    2616         return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
     2677int async_share_in_finalize(cap_handle_t chandle, void *src, unsigned int flags)
     2678{
     2679        return ipc_answer_3(chandle, EOK, (sysarg_t) src, (sysarg_t) flags,
    26172680            (sysarg_t) __entry);
    26182681}
     
    26442707 * So far, this wrapper is to be used from within a connection fibril.
    26452708 *
    2646  * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
    2647  * @param size   Storage for the source address space area size.
    2648  * @param flags  Storage for the sharing flags.
     2709 * @param chandle Storage for the hash of the IPC_M_SHARE_OUT call.
     2710 * @param size     Storage for the source address space area size.
     2711 * @param flags    Storage for the sharing flags.
    26492712 *
    26502713 * @return True on success, false on failure.
    26512714 *
    26522715 */
    2653 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
    2654 {
    2655         assert(callid);
     2716bool async_share_out_receive(cap_handle_t *chandle, size_t *size,
     2717    unsigned int *flags)
     2718{
     2719        assert(chandle);
    26562720        assert(size);
    26572721        assert(flags);
    26582722       
    26592723        ipc_call_t data;
    2660         *callid = async_get_call(&data);
     2724        *chandle = async_get_call(&data);
    26612725       
    26622726        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
     
    26742738 * argument.
    26752739 *
    2676  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    2677  * @param dst    Address of the storage for the destination address space area
    2678  *               base address.
    2679  *
    2680  * @return Zero on success or a value from @ref errno.h on failure.
    2681  *
    2682  */
    2683 int async_share_out_finalize(ipc_callid_t callid, void **dst)
    2684 {
    2685         return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
     2740 * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
     2741 * @param dst      Address of the storage for the destination address space area
     2742 *                 base address.
     2743 *
     2744 * @return  Zero on success or a value from @ref errno.h on failure.
     2745 *
     2746 */
     2747int async_share_out_finalize(cap_handle_t chandle, void **dst)
     2748{
     2749        return ipc_answer_2(chandle, EOK, (sysarg_t) __entry, (sysarg_t) dst);
    26862750}
    26872751
     
    27292793 * So far, this wrapper is to be used from within a connection fibril.
    27302794 *
    2731  * @param callid Storage for the hash of the IPC_M_DATA_READ.
    2732  * @param size   Storage for the maximum size. Can be NULL.
     2795 * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
     2796 * @param size     Storage for the maximum size. Can be NULL.
    27332797 *
    27342798 * @return True on success, false on failure.
    27352799 *
    27362800 */
    2737 bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
     2801bool async_data_read_receive(cap_handle_t *chandle, size_t *size)
    27382802{
    27392803        ipc_call_t data;
    2740         return async_data_read_receive_call(callid, &data, size);
     2804        return async_data_read_receive_call(chandle, &data, size);
    27412805}
    27422806
     
    27492813 * So far, this wrapper is to be used from within a connection fibril.
    27502814 *
    2751  * @param callid Storage for the hash of the IPC_M_DATA_READ.
    2752  * @param size   Storage for the maximum size. Can be NULL.
     2815 * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
     2816 * @param size     Storage for the maximum size. Can be NULL.
    27532817 *
    27542818 * @return True on success, false on failure.
    27552819 *
    27562820 */
    2757 bool async_data_read_receive_call(ipc_callid_t *callid, ipc_call_t *data,
     2821bool async_data_read_receive_call(cap_handle_t *chandle, ipc_call_t *data,
    27582822    size_t *size)
    27592823{
    2760         assert(callid);
     2824        assert(chandle);
    27612825        assert(data);
    27622826       
    2763         *callid = async_get_call(data);
     2827        *chandle = async_get_call(data);
    27642828       
    27652829        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ)
     
    27782842 * argument.
    27792843 *
    2780  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    2781  * @param src    Source address for the IPC_M_DATA_READ call.
    2782  * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
    2783  *               the maximum size announced by the sender.
    2784  *
    2785  * @return Zero on success or a value from @ref errno.h on failure.
    2786  *
    2787  */
    2788 int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
    2789 {
    2790         return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
     2844 * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
     2845 * @param src      Source address for the IPC_M_DATA_READ call.
     2846 * @param size     Size for the IPC_M_DATA_READ call. Can be smaller than
     2847 *                 the maximum size announced by the sender.
     2848 *
     2849 * @return  Zero on success or a value from @ref errno.h on failure.
     2850 *
     2851 */
     2852int async_data_read_finalize(cap_handle_t chandle, const void *src, size_t size)
     2853{
     2854        return ipc_answer_2(chandle, EOK, (sysarg_t) src, (sysarg_t) size);
    27912855}
    27922856
     
    28012865                return ENOENT;
    28022866       
    2803         ipc_callid_t callid;
    2804         if (!async_data_read_receive(&callid, NULL)) {
    2805                 ipc_answer_0(callid, EINVAL);
     2867        cap_handle_t chandle;
     2868        if (!async_data_read_receive(&chandle, NULL)) {
     2869                ipc_answer_0(chandle, EINVAL);
    28062870                return EINVAL;
    28072871        }
     
    28102874            dataptr);
    28112875        if (msg == 0) {
    2812                 ipc_answer_0(callid, EINVAL);
     2876                ipc_answer_0(chandle, EINVAL);
    28132877                return EINVAL;
    28142878        }
    28152879       
    2816         int retval = ipc_forward_fast(callid, exch->phone, 0, 0, 0,
     2880        int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
    28172881            IPC_FF_ROUTE_FROM_ME);
    28182882        if (retval != EOK) {
    28192883                async_forget(msg);
    2820                 ipc_answer_0(callid, retval);
     2884                ipc_answer_0(chandle, retval);
    28212885                return retval;
    28222886        }
     
    28542918 * So far, this wrapper is to be used from within a connection fibril.
    28552919 *
    2856  * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
    2857  * @param size   Storage for the suggested size. May be NULL.
    2858  *
    2859  * @return True on success, false on failure.
    2860  *
    2861  */
    2862 bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
     2920 * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
     2921 * @param size     Storage for the suggested size. May be NULL.
     2922 *
     2923 * @return  True on success, false on failure.
     2924 *
     2925 */
     2926bool async_data_write_receive(cap_handle_t *chandle, size_t *size)
    28632927{
    28642928        ipc_call_t data;
    2865         return async_data_write_receive_call(callid, &data, size);
     2929        return async_data_write_receive_call(chandle, &data, size);
    28662930}
    28672931
     
    28742938 * So far, this wrapper is to be used from within a connection fibril.
    28752939 *
    2876  * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
    2877  * @param data   Storage for the ipc call data.
    2878  * @param size   Storage for the suggested size. May be NULL.
     2940 * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
     2941 * @param data     Storage for the ipc call data.
     2942 * @param size     Storage for the suggested size. May be NULL.
    28792943 *
    28802944 * @return True on success, false on failure.
    28812945 *
    28822946 */
    2883 bool async_data_write_receive_call(ipc_callid_t *callid, ipc_call_t *data,
     2947bool async_data_write_receive_call(cap_handle_t *chandle, ipc_call_t *data,
    28842948    size_t *size)
    28852949{
    2886         assert(callid);
     2950        assert(chandle);
    28872951        assert(data);
    28882952       
    2889         *callid = async_get_call(data);
     2953        *chandle = async_get_call(data);
    28902954       
    28912955        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE)
     
    29042968 * argument.
    29052969 *
    2906  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    2907  * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
    2908  * @param size   Final size for the IPC_M_DATA_WRITE call.
    2909  *
    2910  * @return Zero on success or a value from @ref errno.h on failure.
    2911  *
    2912  */
    2913 int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
    2914 {
    2915         return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
     2970 * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
     2971 * @param dst      Final destination address for the IPC_M_DATA_WRITE call.
     2972 * @param size     Final size for the IPC_M_DATA_WRITE call.
     2973 *
     2974 * @return  Zero on success or a value from @ref errno.h on failure.
     2975 *
     2976 */
     2977int async_data_write_finalize(cap_handle_t chandle, void *dst, size_t size)
     2978{
     2979        return ipc_answer_2(chandle, EOK, (sysarg_t) dst, (sysarg_t) size);
    29162980}
    29172981
     
    29433007        assert(data);
    29443008       
    2945         ipc_callid_t callid;
     3009        cap_handle_t chandle;
    29463010        size_t size;
    2947         if (!async_data_write_receive(&callid, &size)) {
    2948                 ipc_answer_0(callid, EINVAL);
     3011        if (!async_data_write_receive(&chandle, &size)) {
     3012                ipc_answer_0(chandle, EINVAL);
    29493013                return EINVAL;
    29503014        }
    29513015       
    29523016        if (size < min_size) {
    2953                 ipc_answer_0(callid, EINVAL);
     3017                ipc_answer_0(chandle, EINVAL);
    29543018                return EINVAL;
    29553019        }
    29563020       
    29573021        if ((max_size > 0) && (size > max_size)) {
    2958                 ipc_answer_0(callid, EINVAL);
     3022                ipc_answer_0(chandle, EINVAL);
    29593023                return EINVAL;
    29603024        }
    29613025       
    29623026        if ((granularity > 0) && ((size % granularity) != 0)) {
    2963                 ipc_answer_0(callid, EINVAL);
     3027                ipc_answer_0(chandle, EINVAL);
    29643028                return EINVAL;
    29653029        }
     
    29733037       
    29743038        if (arg_data == NULL) {
    2975                 ipc_answer_0(callid, ENOMEM);
     3039                ipc_answer_0(chandle, ENOMEM);
    29763040                return ENOMEM;
    29773041        }
    29783042       
    2979         int rc = async_data_write_finalize(callid, arg_data, size);
     3043        int rc = async_data_write_finalize(chandle, arg_data, size);
    29803044        if (rc != EOK) {
    29813045                free(arg_data);
     
    30023066void async_data_write_void(sysarg_t retval)
    30033067{
    3004         ipc_callid_t callid;
    3005         async_data_write_receive(&callid, NULL);
    3006         ipc_answer_0(callid, retval);
     3068        cap_handle_t chandle;
     3069        async_data_write_receive(&chandle, NULL);
     3070        ipc_answer_0(chandle, retval);
    30073071}
    30083072
     
    30173081                return ENOENT;
    30183082       
    3019         ipc_callid_t callid;
    3020         if (!async_data_write_receive(&callid, NULL)) {
    3021                 ipc_answer_0(callid, EINVAL);
     3083        cap_handle_t chandle;
     3084        if (!async_data_write_receive(&chandle, NULL)) {
     3085                ipc_answer_0(chandle, EINVAL);
    30223086                return EINVAL;
    30233087        }
     
    30263090            dataptr);
    30273091        if (msg == 0) {
    3028                 ipc_answer_0(callid, EINVAL);
     3092                ipc_answer_0(chandle, EINVAL);
    30293093                return EINVAL;
    30303094        }
    30313095       
    3032         int retval = ipc_forward_fast(callid, exch->phone, 0, 0, 0,
     3096        int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
    30333097            IPC_FF_ROUTE_FROM_ME);
    30343098        if (retval != EOK) {
    30353099                async_forget(msg);
    3036                 ipc_answer_0(callid, retval);
     3100                ipc_answer_0(chandle, retval);
    30373101                return retval;
    30383102        }
     
    30593123        /* Accept the phone */
    30603124        ipc_call_t call;
    3061         ipc_callid_t callid = async_get_call(&call);
    3062         int phone = (int) IPC_GET_ARG5(call);
    3063        
    3064         if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) ||
    3065             (phone < 0)) {
    3066                 async_answer_0(callid, EINVAL);
     3125        cap_handle_t chandle = async_get_call(&call);
     3126        cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call);
     3127       
     3128        if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) {
     3129                async_answer_0(chandle, EINVAL);
    30673130                return NULL;
    30683131        }
     
    30703133        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    30713134        if (sess == NULL) {
    3072                 async_answer_0(callid, ENOMEM);
     3135                async_answer_0(chandle, ENOMEM);
    30733136                return NULL;
    30743137        }
     
    30763139        sess->iface = 0;
    30773140        sess->mgmt = mgmt;
    3078         sess->phone = phone;
     3141        sess->phone = phandle;
    30793142        sess->arg1 = 0;
    30803143        sess->arg2 = 0;
     
    30893152       
    30903153        /* Acknowledge the connected phone */
    3091         async_answer_0(callid, EOK);
     3154        async_answer_0(chandle, EOK);
    30923155       
    30933156        return sess;
     
    31103173async_sess_t *async_callback_receive_start(exch_mgmt_t mgmt, ipc_call_t *call)
    31113174{
    3112         int phone = (int) IPC_GET_ARG5(*call);
    3113        
    3114         if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) ||
    3115             (phone < 0))
     3175        cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(*call);
     3176       
     3177        if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || (phandle < 0))
    31163178                return NULL;
    31173179       
     
    31223184        sess->iface = 0;
    31233185        sess->mgmt = mgmt;
    3124         sess->phone = phone;
     3186        sess->phone = phandle;
    31253187        sess->arg1 = 0;
    31263188        sess->arg2 = 0;
     
    31443206}
    31453207
    3146 bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1,
     3208bool async_state_change_receive(cap_handle_t *chandle, sysarg_t *arg1,
    31473209    sysarg_t *arg2, sysarg_t *arg3)
    31483210{
    3149         assert(callid);
     3211        assert(chandle);
    31503212       
    31513213        ipc_call_t call;
    3152         *callid = async_get_call(&call);
     3214        *chandle = async_get_call(&call);
    31533215       
    31543216        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
     
    31653227}
    31663228
    3167 int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch)
    3168 {
    3169         return ipc_answer_1(callid, EOK, other_exch->phone);
     3229int async_state_change_finalize(cap_handle_t chandle, async_exch_t *other_exch)
     3230{
     3231        return ipc_answer_1(chandle, EOK, other_exch->phone);
    31703232}
    31713233
Note: See TracChangeset for help on using the changeset viewer.