Changeset a35b458 in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

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

    r3061bc1 ra35b458  
    125125        /** List of inactive exchanges */
    126126        list_t exch_list;
    127        
     127
    128128        /** Session interface */
    129129        iface_t iface;
    130        
     130
    131131        /** Exchange management style */
    132132        exch_mgmt_t mgmt;
    133        
     133
    134134        /** Session identification */
    135135        int phone;
    136        
     136
    137137        /** First clone connection argument */
    138138        sysarg_t arg1;
    139        
     139
    140140        /** Second clone connection argument */
    141141        sysarg_t arg2;
    142        
     142
    143143        /** Third clone connection argument */
    144144        sysarg_t arg3;
    145        
     145
    146146        /** Exchange mutex */
    147147        fibril_mutex_t mutex;
    148        
     148
    149149        /** Number of opened exchanges */
    150150        atomic_t refcnt;
    151        
     151
    152152        /** Mutex for stateful connections */
    153153        fibril_mutex_t remote_state_mtx;
    154        
     154
    155155        /** Data for stateful connections */
    156156        void *remote_state_data;
     
    161161        /** Link into list of inactive exchanges */
    162162        link_t sess_link;
    163        
     163
    164164        /** Link into global list of inactive exchanges */
    165165        link_t global_link;
    166        
     166
    167167        /** Session pointer */
    168168        async_sess_t *sess;
    169        
     169
    170170        /** Exchange identification */
    171171        int phone;
     
    184184typedef struct {
    185185        link_t link;
    186        
     186
    187187        cap_handle_t chandle;
    188188        ipc_call_t call;
     
    192192typedef struct {
    193193        awaiter_t wdata;
    194        
     194
    195195        /** If reply was received. */
    196196        bool done;
    197        
     197
    198198        /** If the message / reply should be discarded on arrival. */
    199199        bool forget;
    200        
     200
    201201        /** If already destroyed. */
    202202        bool destroyed;
    203        
     203
    204204        /** Pointer to where the answer data is stored. */
    205205        ipc_call_t *dataptr;
    206        
     206
    207207        errno_t retval;
    208208} amsg_t;
     
    211211typedef struct {
    212212        ht_link_t link;
    213        
     213
    214214        task_id_t in_task_id;
    215215        atomic_t refcnt;
     
    220220typedef struct {
    221221        awaiter_t wdata;
    222        
     222
    223223        /** Hash table link. */
    224224        ht_link_t link;
    225        
     225
    226226        /** Incoming client task ID. */
    227227        task_id_t in_task_id;
    228        
     228
    229229        /** Incoming phone hash. */
    230230        sysarg_t in_phone_hash;
    231        
     231
    232232        /** Link to the client tracking structure. */
    233233        client_t *client;
    234        
     234
    235235        /** Messages that should be delivered to this fibril. */
    236236        list_t msg_queue;
    237        
     237
    238238        /** Identification of the opening call. */
    239239        cap_handle_t chandle;
    240        
     240
    241241        /** Call data of the opening call. */
    242242        ipc_call_t call;
    243        
     243
    244244        /** Identification of the closing call. */
    245245        cap_handle_t close_chandle;
    246        
     246
    247247        /** Fibril function that will be used to handle the connection. */
    248248        async_port_handler_t handler;
    249        
     249
    250250        /** Client data */
    251251        void *data;
     
    255255typedef struct {
    256256        ht_link_t link;
    257        
     257
    258258        /** Interface ID */
    259259        iface_t iface;
    260        
     260
    261261        /** Futex protecting the hash table */
    262262        futex_t futex;
    263        
     263
    264264        /** Interface ports */
    265265        hash_table_t port_hash_table;
    266        
     266
    267267        /** Next available port ID */
    268268        port_id_t port_id_avail;
     
    272272typedef struct {
    273273        ht_link_t link;
    274        
     274
    275275        /** Port ID */
    276276        port_id_t id;
    277        
     277
    278278        /** Port connection handler */
    279279        async_port_handler_t handler;
    280        
     280
    281281        /** Client data */
    282282        void *data;
     
    286286typedef struct {
    287287        ht_link_t link;
    288        
     288
    289289        /** Notification method */
    290290        sysarg_t imethod;
    291        
     291
    292292        /** Notification handler */
    293293        async_notification_handler_t handler;
    294        
     294
    295295        /** Notification data */
    296296        void *data;
     
    303303{
    304304        struct timeval tv = { 0, 0 };
    305        
     305
    306306        to->inlist = false;
    307307        to->occurred = false;
     
    335335                awaiter_initialize(&msg->wdata);
    336336        }
    337        
     337
    338338        return msg;
    339339}
     
    456456        if (!interface)
    457457                return NULL;
    458        
     458
    459459        bool ret = hash_table_create(&interface->port_hash_table, 0, 0,
    460460            &port_hash_table_ops);
     
    463463                return NULL;
    464464        }
    465        
     465
    466466        interface->iface = iface;
    467467        futex_initialize(&interface->futex, 1);
    468468        interface->port_id_avail = 0;
    469        
     469
    470470        hash_table_insert(&interface_hash_table, &interface->link);
    471        
     471
    472472        return interface;
    473473}
     
    479479        if (!port)
    480480                return NULL;
    481        
     481
    482482        futex_down(&interface->futex);
    483        
     483
    484484        port_id_t id = interface->port_id_avail;
    485485        interface->port_id_avail++;
    486        
     486
    487487        port->id = id;
    488488        port->handler = handler;
    489489        port->data = data;
    490        
     490
    491491        hash_table_insert(&interface->port_hash_table, &port->link);
    492        
     492
    493493        futex_up(&interface->futex);
    494        
     494
    495495        return port;
    496496}
     
    516516        if ((iface & IFACE_MOD_MASK) == IFACE_MOD_CALLBACK)
    517517                return EINVAL;
    518        
     518
    519519        interface_t *interface;
    520        
     520
    521521        futex_down(&async_futex);
    522        
     522
    523523        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
    524524        if (link)
     
    526526        else
    527527                interface = async_new_interface(iface);
    528        
     528
    529529        if (!interface) {
    530530                futex_up(&async_futex);
    531531                return ENOMEM;
    532532        }
    533        
     533
    534534        port_t *port = async_new_port(interface, handler, data);
    535535        if (!port) {
     
    537537                return ENOMEM;
    538538        }
    539        
     539
    540540        *port_id = port->id;
    541        
     541
    542542        futex_up(&async_futex);
    543        
     543
    544544        return EOK;
    545545}
     
    548548{
    549549        assert(handler != NULL);
    550        
     550
    551551        fallback_port_handler = handler;
    552552        fallback_port_data = data;
     
    645645{
    646646        client_t *client = NULL;
    647        
     647
    648648        futex_down(&async_futex);
    649649        ht_link_t *link = hash_table_find(&client_hash_table, &client_id);
     
    656656                        client->in_task_id = client_id;
    657657                        client->data = async_client_data_create();
    658                        
     658
    659659                        atomic_set(&client->refcnt, 1);
    660660                        hash_table_insert(&client_hash_table, &client->link);
    661661                }
    662662        }
    663        
     663
    664664        futex_up(&async_futex);
    665665        return client;
     
    669669{
    670670        bool destroy;
    671        
     671
    672672        futex_down(&async_futex);
    673        
     673
    674674        if (atomic_predec(&client->refcnt) == 0) {
    675675                hash_table_remove(&client_hash_table, &client->in_task_id);
     
    677677        } else
    678678                destroy = false;
    679        
     679
    680680        futex_up(&async_futex);
    681        
     681
    682682        if (destroy) {
    683683                if (client->data)
    684684                        async_client_data_destroy(client->data);
    685                
     685
    686686                free(client);
    687687        }
     
    701701{
    702702        assert(arg);
    703        
     703
    704704        /*
    705705         * Setup fibril-local connection pointer.
    706706         */
    707707        fibril_connection = (connection_t *) arg;
    708        
     708
    709709        /*
    710710         * Add our reference for the current connection in the client task
     
    712712         * hash in a new tracking structure.
    713713         */
    714        
     714
    715715        client_t *client = async_client_get(fibril_connection->in_task_id, true);
    716716        if (!client) {
     
    718718                return 0;
    719719        }
    720        
     720
    721721        fibril_connection->client = client;
    722        
     722
    723723        /*
    724724         * Call the connection handler function.
     
    726726        fibril_connection->handler(fibril_connection->chandle,
    727727            &fibril_connection->call, fibril_connection->data);
    728        
     728
    729729        /*
    730730         * Remove the reference for this client task connection.
    731731         */
    732732        async_client_put(client);
    733        
     733
    734734        /*
    735735         * Remove myself from the connection hash table.
     
    741741        });
    742742        futex_up(&async_futex);
    743        
     743
    744744        /*
    745745         * Answer all remaining messages with EHANGUP.
     
    749749                    list_get_instance(list_first(&fibril_connection->msg_queue),
    750750                    msg_t, link);
    751                
     751
    752752                list_remove(&msg->link);
    753753                ipc_answer_0(msg->chandle, EHANGUP);
    754754                free(msg);
    755755        }
    756        
     756
    757757        /*
    758758         * If the connection was hung-up, answer the last call,
     
    761761        if (fibril_connection->close_chandle)
    762762                ipc_answer_0(fibril_connection->close_chandle, EOK);
    763        
     763
    764764        free(fibril_connection);
    765765        return EOK;
     
    793793                if (chandle != CAP_NIL)
    794794                        ipc_answer_0(chandle, ENOMEM);
    795                
     795
    796796                return (uintptr_t) NULL;
    797797        }
    798        
     798
    799799        conn->in_task_id = in_task_id;
    800800        conn->in_phone_hash = in_phone_hash;
     
    804804        conn->handler = handler;
    805805        conn->data = data;
    806        
     806
    807807        if (call)
    808808                conn->call = *call;
    809        
     809
    810810        /* We will activate the fibril ASAP */
    811811        conn->wdata.active = true;
    812812        conn->wdata.fid = fibril_create(connection_fibril, conn);
    813        
     813
    814814        if (conn->wdata.fid == 0) {
    815815                free(conn);
    816                
     816
    817817                if (chandle != CAP_NIL)
    818818                        ipc_answer_0(chandle, ENOMEM);
    819                
     819
    820820                return (uintptr_t) NULL;
    821821        }
    822        
     822
    823823        /* Add connection to the connection hash table */
    824        
     824
    825825        futex_down(&async_futex);
    826826        hash_table_insert(&conn_hash_table, &conn->link);
    827827        futex_up(&async_futex);
    828        
     828
    829829        fibril_add_ready(conn->wdata.fid);
    830        
     830
    831831        return conn->wdata.fid;
    832832}
     
    852852        if ((iface & IFACE_MOD_CALLBACK) != IFACE_MOD_CALLBACK)
    853853                return EINVAL;
    854        
     854
    855855        if (exch == NULL)
    856856                return ENOENT;
    857        
     857
    858858        ipc_call_t answer;
    859859        aid_t req = async_send_3(exch, IPC_M_CONNECT_TO_ME, iface, arg1, arg2,
    860860            &answer);
    861        
     861
    862862        errno_t ret;
    863863        async_wait_for(req, &ret);
    864864        if (ret != EOK)
    865865                return (errno_t) ret;
    866        
     866
    867867        sysarg_t phone_hash = IPC_GET_ARG5(answer);
    868868        interface_t *interface;
    869        
     869
    870870        futex_down(&async_futex);
    871        
     871
    872872        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
    873873        if (link)
     
    875875        else
    876876                interface = async_new_interface(iface);
    877        
     877
    878878        if (!interface) {
    879879                futex_up(&async_futex);
    880880                return ENOMEM;
    881881        }
    882        
     882
    883883        port_t *port = async_new_port(interface, handler, data);
    884884        if (!port) {
     
    886886                return ENOMEM;
    887887        }
    888        
     888
    889889        *port_id = port->id;
    890        
     890
    891891        futex_up(&async_futex);
    892        
     892
    893893        fid_t fid = async_new_connection(answer.in_task_id, phone_hash,
    894894            CAP_NIL, NULL, handler, data);
    895895        if (fid == (uintptr_t) NULL)
    896896                return ENOMEM;
    897        
     897
    898898        return EOK;
    899899}
     
    937937{
    938938        assert(wd);
    939        
     939
    940940        wd->to_event.occurred = false;
    941941        wd->to_event.inlist = true;
    942        
     942
    943943        link_t *tmp = timeout_list.head.next;
    944944        while (tmp != &timeout_list.head) {
    945945                awaiter_t *cur
    946946                    = list_get_instance(tmp, awaiter_t, to_event.link);
    947                
     947
    948948                if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
    949949                        break;
    950                
     950
    951951                tmp = tmp->next;
    952952        }
    953        
     953
    954954        list_insert_before(&wd->to_event.link, tmp);
    955955}
     
    971971{
    972972        assert(call);
    973        
     973
    974974        futex_down(&async_futex);
    975        
     975
    976976        ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){
    977977                .task_id = call->in_task_id,
     
    982982                return false;
    983983        }
    984        
     984
    985985        connection_t *conn = hash_table_get_inst(link, connection_t, link);
    986        
     986
    987987        msg_t *msg = malloc(sizeof(*msg));
    988988        if (!msg) {
     
    990990                return false;
    991991        }
    992        
     992
    993993        msg->chandle = chandle;
    994994        msg->call = *call;
    995995        list_append(&msg->link, &conn->msg_queue);
    996        
     996
    997997        if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP)
    998998                conn->close_chandle = chandle;
    999        
     999
    10001000        /* If the connection fibril is waiting for an event, activate it */
    10011001        if (!conn->wdata.active) {
    1002                
     1002
    10031003                /* If in timeout list, remove it */
    10041004                if (conn->wdata.to_event.inlist) {
     
    10061006                        list_remove(&conn->wdata.to_event.link);
    10071007                }
    1008                
     1008
    10091009                conn->wdata.active = true;
    10101010                fibril_add_ready(conn->wdata.fid);
    10111011        }
    1012        
     1012
    10131013        futex_up(&async_futex);
    10141014        return true;
     
    10261026
    10271027        assert(call);
    1028        
     1028
    10291029        futex_down(&async_futex);
    1030        
     1030
    10311031        ht_link_t *link = hash_table_find(&notification_hash_table,
    10321032            &IPC_GET_IMETHOD(*call));
     
    10371037                data = notification->data;
    10381038        }
    1039        
     1039
    10401040        futex_up(&async_futex);
    1041        
     1041
    10421042        if (handler)
    10431043                handler(call, data);
     
    10631063        if (!notification)
    10641064                return ENOMEM;
    1065        
     1065
    10661066        futex_down(&async_futex);
    1067        
     1067
    10681068        sysarg_t imethod = notification_avail;
    10691069        notification_avail++;
    1070        
     1070
    10711071        notification->imethod = imethod;
    10721072        notification->handler = handler;
    10731073        notification->data = data;
    1074        
     1074
    10751075        hash_table_insert(&notification_hash_table, &notification->link);
    1076        
     1076
    10771077        futex_up(&async_futex);
    1078        
     1078
    10791079        cap_handle_t cap;
    10801080        errno_t rc = ipc_irq_subscribe(inr, imethod, ucode, &cap);
     
    10961096        // TODO: Remove entry from hash table
    10971097        //       to avoid memory leak
    1098        
     1098
    10991099        return ipc_irq_unsubscribe(cap);
    11001100}
     
    11161116        if (!notification)
    11171117                return ENOMEM;
    1118        
     1118
    11191119        futex_down(&async_futex);
    1120        
     1120
    11211121        sysarg_t imethod = notification_avail;
    11221122        notification_avail++;
    1123        
     1123
    11241124        notification->imethod = imethod;
    11251125        notification->handler = handler;
    11261126        notification->data = data;
    1127        
     1127
    11281128        hash_table_insert(&notification_hash_table, &notification->link);
    1129        
     1129
    11301130        futex_up(&async_futex);
    1131        
     1131
    11321132        return ipc_event_subscribe(evno, imethod);
    11331133}
     
    11491149        if (!notification)
    11501150                return ENOMEM;
    1151        
     1151
    11521152        futex_down(&async_futex);
    1153        
     1153
    11541154        sysarg_t imethod = notification_avail;
    11551155        notification_avail++;
    1156        
     1156
    11571157        notification->imethod = imethod;
    11581158        notification->handler = handler;
    11591159        notification->data = data;
    1160        
     1160
    11611161        hash_table_insert(&notification_hash_table, &notification->link);
    1162        
     1162
    11631163        futex_up(&async_futex);
    1164        
     1164
    11651165        return ipc_event_task_subscribe(evno, imethod);
    11661166}
     
    12041204        assert(call);
    12051205        assert(fibril_connection);
    1206        
     1206
    12071207        /* Why doing this?
    12081208         * GCC 4.1.0 coughs on fibril_connection-> dereference.
     
    12121212         */
    12131213        connection_t *conn = fibril_connection;
    1214        
     1214
    12151215        futex_down(&async_futex);
    1216        
     1216
    12171217        if (usecs) {
    12181218                getuptime(&conn->wdata.to_event.expires);
     
    12201220        } else
    12211221                conn->wdata.to_event.inlist = false;
    1222        
     1222
    12231223        /* If nothing in queue, wait until something arrives */
    12241224        while (list_empty(&conn->msg_queue)) {
     
    12361236                        return conn->close_chandle;
    12371237                }
    1238                
     1238
    12391239                if (usecs)
    12401240                        async_insert_timeout(&conn->wdata);
    1241                
     1241
    12421242                conn->wdata.active = false;
    1243                
     1243
    12441244                /*
    12451245                 * Note: the current fibril will be rescheduled either due to a
     
    12491249                 */
    12501250                fibril_switch(FIBRIL_TO_MANAGER);
    1251                
     1251
    12521252                /*
    12531253                 * Futex is up after getting back from async_manager.
     
    12621262                }
    12631263        }
    1264        
     1264
    12651265        msg_t *msg = list_get_instance(list_first(&conn->msg_queue),
    12661266            msg_t, link);
    12671267        list_remove(&msg->link);
    1268        
     1268
    12691269        cap_handle_t chandle = msg->chandle;
    12701270        *call = msg->call;
    12711271        free(msg);
    1272        
     1272
    12731273        futex_up(&async_futex);
    12741274        return chandle;
     
    12861286        if (!client)
    12871287                return NULL;
    1288        
     1288
    12891289        if (!client->data) {
    12901290                async_client_put(client);
    12911291                return NULL;
    12921292        }
    1293        
     1293
    12941294        return client->data;
    12951295}
     
    12981298{
    12991299        client_t *client = async_client_get(client_id, false);
    1300        
     1300
    13011301        assert(client);
    13021302        assert(client->data);
    1303        
     1303
    13041304        /* Drop the reference we got in async_get_client_data_by_hash(). */
    13051305        async_client_put(client);
    1306        
     1306
    13071307        /* Drop our own reference we got at the beginning of this function. */
    13081308        async_client_put(client);
     
    13121312{
    13131313        port_t *port = NULL;
    1314        
     1314
    13151315        futex_down(&async_futex);
    1316        
     1316
    13171317        ht_link_t *link = hash_table_find(&interface_hash_table, &iface);
    13181318        if (link) {
    13191319                interface_t *interface =
    13201320                    hash_table_get_inst(link, interface_t, link);
    1321                
     1321
    13221322                link = hash_table_find(&interface->port_hash_table, &port_id);
    13231323                if (link)
    13241324                        port = hash_table_get_inst(link, port_t, link);
    13251325        }
    1326        
     1326
    13271327        futex_up(&async_futex);
    1328        
     1328
    13291329        return port;
    13301330}
     
    13421342{
    13431343        assert(call);
    1344        
     1344
    13451345        /* Kernel notification */
    13461346        if ((chandle == CAP_NIL) && (call->flags & IPC_CALL_NOTIF)) {
    13471347                fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data;
    13481348                unsigned oldsw = fibril->switches;
    1349                
     1349
    13501350                process_notification(call);
    1351                
     1351
    13521352                if (oldsw != fibril->switches) {
    13531353                        /*
     
    13651365                        fibril_switch(FIBRIL_FROM_DEAD);
    13661366                }
    1367                
     1367
    13681368                return;
    13691369        }
    1370        
     1370
    13711371        /* New connection */
    13721372        if (IPC_GET_IMETHOD(*call) == IPC_M_CONNECT_ME_TO) {
    13731373                iface_t iface = (iface_t) IPC_GET_ARG1(*call);
    13741374                sysarg_t in_phone_hash = IPC_GET_ARG5(*call);
    1375                
     1375
    13761376                async_port_handler_t handler = fallback_port_handler;
    13771377                void *data = fallback_port_data;
    1378                
     1378
    13791379                // TODO: Currently ignores all ports but the first one
    13801380                port_t *port = async_find_port(iface, 0);
     
    13831383                        data = port->data;
    13841384                }
    1385                
     1385
    13861386                async_new_connection(call->in_task_id, in_phone_hash, chandle,
    13871387                    call, handler, data);
    13881388                return;
    13891389        }
    1390        
     1390
    13911391        /* Try to route the call through the connection hash table */
    13921392        if (route_call(chandle, call))
    13931393                return;
    1394        
     1394
    13951395        /* Unknown call from unknown phone - hang it up */
    13961396        ipc_answer_0(chandle, EHANGUP);
     
    14021402        struct timeval tv;
    14031403        getuptime(&tv);
    1404        
     1404
    14051405        futex_down(&async_futex);
    1406        
     1406
    14071407        link_t *cur = list_first(&timeout_list);
    14081408        while (cur != NULL) {
    14091409                awaiter_t *waiter =
    14101410                    list_get_instance(cur, awaiter_t, to_event.link);
    1411                
     1411
    14121412                if (tv_gt(&waiter->to_event.expires, &tv))
    14131413                        break;
    1414                
     1414
    14151415                list_remove(&waiter->to_event.link);
    14161416                waiter->to_event.inlist = false;
    14171417                waiter->to_event.occurred = true;
    1418                
     1418
    14191419                /*
    14201420                 * Redundant condition?
     
    14251425                        fibril_add_ready(waiter->fid);
    14261426                }
    1427                
     1427
    14281428                cur = list_first(&timeout_list);
    14291429        }
    1430        
     1430
    14311431        futex_up(&async_futex);
    14321432}
     
    14481448                        continue;
    14491449                }
    1450                
     1450
    14511451                futex_down(&async_futex);
    1452                
     1452
    14531453                suseconds_t timeout;
    14541454                unsigned int flags = SYNCH_FLAGS_NONE;
     
    14561456                        awaiter_t *waiter = list_get_instance(
    14571457                            list_first(&timeout_list), awaiter_t, to_event.link);
    1458                        
     1458
    14591459                        struct timeval tv;
    14601460                        getuptime(&tv);
    1461                        
     1461
    14621462                        if (tv_gteq(&tv, &waiter->to_event.expires)) {
    14631463                                futex_up(&async_futex);
     
    14851485                        timeout = SYNCH_NO_TIMEOUT;
    14861486                }
    1487                
     1487
    14881488                atomic_inc(&threads_in_ipc_wait);
    1489                
     1489
    14901490                ipc_call_t call;
    14911491                errno_t rc = ipc_wait_cycle(&call, timeout, flags);
    1492                
     1492
    14931493                atomic_dec(&threads_in_ipc_wait);
    1494                
     1494
    14951495                assert(rc == EOK);
    14961496
     
    15241524{
    15251525        futex_up(&async_futex);
    1526        
     1526
    15271527        /*
    15281528         * async_futex is always locked when entering manager
    15291529         */
    15301530        async_manager_worker();
    1531        
     1531
    15321532        return 0;
    15331533}
     
    15551555            &interface_hash_table_ops))
    15561556                abort();
    1557        
     1557
    15581558        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    15591559                abort();
    1560        
     1560
    15611561        if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
    15621562                abort();
    1563        
     1563
    15641564        if (!hash_table_create(&notification_hash_table, 0, 0,
    15651565            &notification_hash_table_ops))
    15661566                abort();
    1567        
     1567
    15681568        session_ns = (async_sess_t *) malloc(sizeof(async_sess_t));
    15691569        if (session_ns == NULL)
    15701570                abort();
    1571        
     1571
    15721572        session_ns->iface = 0;
    15731573        session_ns->mgmt = EXCHANGE_ATOMIC;
     
    15761576        session_ns->arg2 = 0;
    15771577        session_ns->arg3 = 0;
    1578        
     1578
    15791579        fibril_mutex_initialize(&session_ns->remote_state_mtx);
    15801580        session_ns->remote_state_data = NULL;
    1581        
     1581
    15821582        list_initialize(&session_ns->exch_list);
    15831583        fibril_mutex_initialize(&session_ns->mutex);
     
    16001600{
    16011601        assert(arg);
    1602        
     1602
    16031603        futex_down(&async_futex);
    1604        
     1604
    16051605        amsg_t *msg = (amsg_t *) arg;
    16061606        msg->retval = retval;
    1607        
     1607
    16081608        /* Copy data after futex_down, just in case the call was detached */
    16091609        if ((msg->dataptr) && (data))
    16101610                *msg->dataptr = *data;
    1611        
     1611
    16121612        write_barrier();
    1613        
     1613
    16141614        /* Remove message from timeout list */
    16151615        if (msg->wdata.to_event.inlist)
    16161616                list_remove(&msg->wdata.to_event.link);
    1617        
     1617
    16181618        msg->done = true;
    1619        
     1619
    16201620        if (msg->forget) {
    16211621                assert(msg->wdata.active);
     
    16251625                fibril_add_ready(msg->wdata.fid);
    16261626        }
    1627        
     1627
    16281628        futex_up(&async_futex);
    16291629}
     
    16501650        if (exch == NULL)
    16511651                return 0;
    1652        
     1652
    16531653        amsg_t *msg = amsg_create();
    16541654        if (msg == NULL)
    16551655                return 0;
    1656        
     1656
    16571657        msg->dataptr = dataptr;
    16581658        msg->wdata.active = true;
    1659        
     1659
    16601660        ipc_call_async_4(exch->phone, imethod, arg1, arg2, arg3, arg4, msg,
    16611661            reply_received);
    1662        
     1662
    16631663        return (aid_t) msg;
    16641664}
     
    16881688        if (exch == NULL)
    16891689                return 0;
    1690        
     1690
    16911691        amsg_t *msg = amsg_create();
    16921692        if (msg == NULL)
    16931693                return 0;
    1694        
     1694
    16951695        msg->dataptr = dataptr;
    16961696        msg->wdata.active = true;
    1697        
     1697
    16981698        ipc_call_async_5(exch->phone, imethod, arg1, arg2, arg3, arg4, arg5,
    16991699            msg, reply_received);
    1700        
     1700
    17011701        return (aid_t) msg;
    17021702}
     
    17121712{
    17131713        assert(amsgid);
    1714        
     1714
    17151715        amsg_t *msg = (amsg_t *) amsgid;
    1716        
     1716
    17171717        futex_down(&async_futex);
    1718        
     1718
    17191719        assert(!msg->forget);
    17201720        assert(!msg->destroyed);
    1721        
     1721
    17221722        if (msg->done) {
    17231723                futex_up(&async_futex);
    17241724                goto done;
    17251725        }
    1726        
     1726
    17271727        msg->wdata.fid = fibril_get_id();
    17281728        msg->wdata.active = false;
    17291729        msg->wdata.to_event.inlist = false;
    1730        
     1730
    17311731        /* Leave the async_futex locked when entering this function */
    17321732        fibril_switch(FIBRIL_TO_MANAGER);
    1733        
     1733
    17341734        /* Futex is up automatically after fibril_switch */
    1735        
     1735
    17361736done:
    17371737        if (retval)
    17381738                *retval = msg->retval;
    1739        
     1739
    17401740        amsg_destroy(msg);
    17411741}
     
    17581758{
    17591759        assert(amsgid);
    1760        
     1760
    17611761        amsg_t *msg = (amsg_t *) amsgid;
    1762        
     1762
    17631763        futex_down(&async_futex);
    1764        
     1764
    17651765        assert(!msg->forget);
    17661766        assert(!msg->destroyed);
    1767        
     1767
    17681768        if (msg->done) {
    17691769                futex_up(&async_futex);
    17701770                goto done;
    17711771        }
    1772        
     1772
    17731773        /*
    17741774         * Negative timeout is converted to zero timeout to avoid
     
    17771777        if (timeout < 0)
    17781778                timeout = 0;
    1779        
     1779
    17801780        getuptime(&msg->wdata.to_event.expires);
    17811781        tv_add_diff(&msg->wdata.to_event.expires, timeout);
    1782        
     1782
    17831783        /*
    17841784         * Current fibril is inserted as waiting regardless of the
     
    18011801        msg->wdata.active = false;
    18021802        async_insert_timeout(&msg->wdata);
    1803        
     1803
    18041804        /* Leave the async_futex locked when entering this function */
    18051805        fibril_switch(FIBRIL_TO_MANAGER);
    1806        
     1806
    18071807        /* Futex is up automatically after fibril_switch */
    1808        
     1808
    18091809        if (!msg->done)
    18101810                return ETIMEOUT;
    1811        
     1811
    18121812done:
    18131813        if (retval)
    18141814                *retval = msg->retval;
    1815        
     1815
    18161816        amsg_destroy(msg);
    1817        
     1817
    18181818        return 0;
    18191819}
    1820  
     1820
    18211821/** Discard the message / reply on arrival.
    18221822 *
     
    18301830{
    18311831        amsg_t *msg = (amsg_t *) amsgid;
    1832        
     1832
    18331833        assert(msg);
    18341834        assert(!msg->forget);
    18351835        assert(!msg->destroyed);
    1836        
     1836
    18371837        futex_down(&async_futex);
    1838        
     1838
    18391839        if (msg->done) {
    18401840                amsg_destroy(msg);
     
    18431843                msg->forget = true;
    18441844        }
    1845        
     1845
    18461846        futex_up(&async_futex);
    18471847}
     
    18581858        awaiter_t awaiter;
    18591859        awaiter_initialize(&awaiter);
    1860        
     1860
    18611861        awaiter.fid = fibril_get_id();
    1862        
     1862
    18631863        getuptime(&awaiter.to_event.expires);
    18641864        tv_add_diff(&awaiter.to_event.expires, timeout);
    1865        
     1865
    18661866        futex_down(&async_futex);
    1867        
     1867
    18681868        async_insert_timeout(&awaiter);
    1869        
     1869
    18701870        /* Leave the async_futex locked when entering this function */
    18711871        fibril_switch(FIBRIL_TO_MANAGER);
    1872        
     1872
    18731873        /* Futex is up automatically after fibril_switch() */
    18741874}
     
    19211921        if (exch == NULL)
    19221922                return ENOENT;
    1923        
     1923
    19241924        ipc_call_t result;
    19251925        aid_t aid = async_send_4(exch, imethod, arg1, arg2, arg3, arg4,
    19261926            &result);
    1927        
     1927
    19281928        errno_t rc;
    19291929        async_wait_for(aid, &rc);
    1930        
     1930
    19311931        if (r1)
    19321932                *r1 = IPC_GET_ARG1(result);
    1933        
     1933
    19341934        if (r2)
    19351935                *r2 = IPC_GET_ARG2(result);
    1936        
     1936
    19371937        if (r3)
    19381938                *r3 = IPC_GET_ARG3(result);
    1939        
     1939
    19401940        if (r4)
    19411941                *r4 = IPC_GET_ARG4(result);
    1942        
     1942
    19431943        if (r5)
    19441944                *r5 = IPC_GET_ARG5(result);
    1945        
     1945
    19461946        return rc;
    19471947}
     
    19731973        if (exch == NULL)
    19741974                return ENOENT;
    1975        
     1975
    19761976        ipc_call_t result;
    19771977        aid_t aid = async_send_5(exch, imethod, arg1, arg2, arg3, arg4, arg5,
    19781978            &result);
    1979        
     1979
    19801980        errno_t rc;
    19811981        async_wait_for(aid, &rc);
    1982        
     1982
    19831983        if (r1)
    19841984                *r1 = IPC_GET_ARG1(result);
    1985        
     1985
    19861986        if (r2)
    19871987                *r2 = IPC_GET_ARG2(result);
    1988        
     1988
    19891989        if (r3)
    19901990                *r3 = IPC_GET_ARG3(result);
    1991        
     1991
    19921992        if (r4)
    19931993                *r4 = IPC_GET_ARG4(result);
    1994        
     1994
    19951995        if (r5)
    19961996                *r5 = IPC_GET_ARG5(result);
    1997        
     1997
    19981998        return rc;
    19991999}
     
    20812081        if (exch == NULL)
    20822082                return ENOENT;
    2083        
     2083
    20842084        return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode);
    20852085}
     
    20912091        if (exch == NULL)
    20922092                return ENOENT;
    2093        
     2093
    20942094        return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3,
    20952095            arg4, arg5, mode);
     
    21132113        if (exch == NULL)
    21142114                return ENOENT;
    2115        
     2115
    21162116        ipc_call_t answer;
    21172117        aid_t req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    21182118            &answer);
    2119        
     2119
    21202120        errno_t rc;
    21212121        async_wait_for(req, &rc);
    21222122        if (rc != EOK)
    21232123                return (errno_t) rc;
    2124        
     2124
    21252125        return EOK;
    21262126}
     
    21302130{
    21312131        ipc_call_t result;
    2132        
     2132
    21332133        // XXX: Workaround for GCC's inability to infer association between
    21342134        // rc == EOK and *out_phone being assigned.
    21352135        *out_phone = -1;
    2136        
     2136
    21372137        amsg_t *msg = amsg_create();
    21382138        if (!msg)
    21392139                return ENOENT;
    2140        
     2140
    21412141        msg->dataptr = &result;
    21422142        msg->wdata.active = true;
    2143        
     2143
    21442144        ipc_call_async_4(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, arg4,
    21452145            msg, reply_received);
    2146        
     2146
    21472147        errno_t rc;
    21482148        async_wait_for((aid_t) msg, &rc);
    2149        
     2149
    21502150        if (rc != EOK)
    21512151                return rc;
    2152        
     2152
    21532153        *out_phone = (int) IPC_GET_ARG5(result);
    21542154        return EOK;
     
    21752175                return NULL;
    21762176        }
    2177        
     2177
    21782178        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    21792179        if (sess == NULL) {
     
    21812181                return NULL;
    21822182        }
    2183        
     2183
    21842184        int phone;
    21852185        errno_t rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
     
    21902190                return NULL;
    21912191        }
    2192        
     2192
    21932193        sess->iface = 0;
    21942194        sess->mgmt = mgmt;
     
    21972197        sess->arg2 = arg2;
    21982198        sess->arg3 = arg3;
    2199        
     2199
    22002200        fibril_mutex_initialize(&sess->remote_state_mtx);
    22012201        sess->remote_state_data = NULL;
    2202        
     2202
    22032203        list_initialize(&sess->exch_list);
    22042204        fibril_mutex_initialize(&sess->mutex);
    22052205        atomic_set(&sess->refcnt, 0);
    2206        
     2206
    22072207        return sess;
    22082208}
     
    22282228                return NULL;
    22292229        }
    2230        
     2230
    22312231        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    22322232        if (sess == NULL) {
     
    22342234                return NULL;
    22352235        }
    2236        
     2236
    22372237        int phone;
    22382238        errno_t rc = async_connect_me_to_internal(exch->phone, iface, arg2,
     
    22432243                return NULL;
    22442244        }
    2245        
     2245
    22462246        sess->iface = iface;
    22472247        sess->phone = phone;
     
    22492249        sess->arg2 = arg2;
    22502250        sess->arg3 = arg3;
    2251        
     2251
    22522252        fibril_mutex_initialize(&sess->remote_state_mtx);
    22532253        sess->remote_state_data = NULL;
    2254        
     2254
    22552255        list_initialize(&sess->exch_list);
    22562256        fibril_mutex_initialize(&sess->mutex);
    22572257        atomic_set(&sess->refcnt, 0);
    2258        
     2258
    22592259        return sess;
    22602260}
     
    22992299                return NULL;
    23002300        }
    2301        
     2301
    23022302        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    23032303        if (sess == NULL) {
     
    23052305                return NULL;
    23062306        }
    2307        
     2307
    23082308        int phone;
    23092309        errno_t rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
    23102310            IPC_FLAG_BLOCKING, &phone);
    2311        
     2311
    23122312        if (rc != EOK) {
    23132313                errno = rc;
     
    23152315                return NULL;
    23162316        }
    2317        
     2317
    23182318        sess->iface = 0;
    23192319        sess->mgmt = mgmt;
     
    23222322        sess->arg2 = arg2;
    23232323        sess->arg3 = arg3;
    2324        
     2324
    23252325        fibril_mutex_initialize(&sess->remote_state_mtx);
    23262326        sess->remote_state_data = NULL;
    2327        
     2327
    23282328        list_initialize(&sess->exch_list);
    23292329        fibril_mutex_initialize(&sess->mutex);
    23302330        atomic_set(&sess->refcnt, 0);
    2331        
     2331
    23322332        return sess;
    23332333}
     
    23532353                return NULL;
    23542354        }
    2355        
     2355
    23562356        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    23572357        if (sess == NULL) {
     
    23592359                return NULL;
    23602360        }
    2361        
     2361
    23622362        int phone;
    23632363        errno_t rc = async_connect_me_to_internal(exch->phone, iface, arg2,
     
    23682368                return NULL;
    23692369        }
    2370        
     2370
    23712371        sess->iface = iface;
    23722372        sess->phone = phone;
     
    23742374        sess->arg2 = arg2;
    23752375        sess->arg3 = arg3;
    2376        
     2376
    23772377        fibril_mutex_initialize(&sess->remote_state_mtx);
    23782378        sess->remote_state_data = NULL;
    2379        
     2379
    23802380        list_initialize(&sess->exch_list);
    23812381        fibril_mutex_initialize(&sess->mutex);
    23822382        atomic_set(&sess->refcnt, 0);
    2383        
     2383
    23842384        return sess;
    23852385}
     
    23952395                return NULL;
    23962396        }
    2397        
     2397
    23982398        cap_handle_t phone;
    23992399        errno_t rc = ipc_connect_kbox(id, &phone);
     
    24032403                return NULL;
    24042404        }
    2405        
     2405
    24062406        sess->iface = 0;
    24072407        sess->mgmt = EXCHANGE_ATOMIC;
     
    24102410        sess->arg2 = 0;
    24112411        sess->arg3 = 0;
    2412        
     2412
    24132413        fibril_mutex_initialize(&sess->remote_state_mtx);
    24142414        sess->remote_state_data = NULL;
    2415        
     2415
    24162416        list_initialize(&sess->exch_list);
    24172417        fibril_mutex_initialize(&sess->mutex);
    24182418        atomic_set(&sess->refcnt, 0);
    2419        
     2419
    24202420        return sess;
    24212421}
     
    24362436{
    24372437        async_exch_t *exch;
    2438        
     2438
    24392439        assert(sess);
    2440        
     2440
    24412441        if (atomic_get(&sess->refcnt) > 0)
    24422442                return EBUSY;
    2443        
     2443
    24442444        fibril_mutex_lock(&async_sess_mutex);
    2445        
     2445
    24462446        errno_t rc = async_hangup_internal(sess->phone);
    2447        
     2447
    24482448        while (!list_empty(&sess->exch_list)) {
    24492449                exch = (async_exch_t *)
    24502450                    list_get_instance(list_first(&sess->exch_list),
    24512451                    async_exch_t, sess_link);
    2452                
     2452
    24532453                list_remove(&exch->sess_link);
    24542454                list_remove(&exch->global_link);
     
    24582458
    24592459        free(sess);
    2460        
     2460
    24612461        fibril_mutex_unlock(&async_sess_mutex);
    2462        
     2462
    24632463        return rc;
    24642464}
     
    24812481        if (sess == NULL)
    24822482                return NULL;
    2483        
     2483
    24842484        exch_mgmt_t mgmt = sess->mgmt;
    24852485        if (sess->iface != 0)
    24862486                mgmt = sess->iface & IFACE_EXCHANGE_MASK;
    2487        
     2487
    24882488        async_exch_t *exch = NULL;
    2489        
     2489
    24902490        fibril_mutex_lock(&async_sess_mutex);
    2491        
     2491
    24922492        if (!list_empty(&sess->exch_list)) {
    24932493                /*
     
    24972497                    list_get_instance(list_first(&sess->exch_list),
    24982498                    async_exch_t, sess_link);
    2499                
     2499
    25002500                list_remove(&exch->sess_link);
    25012501                list_remove(&exch->global_link);
     
    25042504                 * There are no available exchanges in the session.
    25052505                 */
    2506                
     2506
    25072507                if ((mgmt == EXCHANGE_ATOMIC) ||
    25082508                    (mgmt == EXCHANGE_SERIALIZE)) {
     
    25172517                        int phone;
    25182518                        errno_t rc;
    2519                        
     2519
    25202520                retry:
    25212521                        /*
     
    25422542                                    list_get_instance(list_first(&inactive_exch_list),
    25432543                                    async_exch_t, global_link);
    2544                                
     2544
    25452545                                list_remove(&exch->sess_link);
    25462546                                list_remove(&exch->global_link);
     
    25572557                }
    25582558        }
    2559        
     2559
    25602560        fibril_mutex_unlock(&async_sess_mutex);
    2561        
     2561
    25622562        if (exch != NULL) {
    25632563                atomic_inc(&sess->refcnt);
    2564                
     2564
    25652565                if (mgmt == EXCHANGE_SERIALIZE)
    25662566                        fibril_mutex_lock(&sess->mutex);
    25672567        }
    2568        
     2568
    25692569        return exch;
    25702570}
     
    25792579        if (exch == NULL)
    25802580                return;
    2581        
     2581
    25822582        async_sess_t *sess = exch->sess;
    25832583        assert(sess != NULL);
    2584        
     2584
    25852585        exch_mgmt_t mgmt = sess->mgmt;
    25862586        if (sess->iface != 0)
    25872587                mgmt = sess->iface & IFACE_EXCHANGE_MASK;
    2588        
     2588
    25892589        atomic_dec(&sess->refcnt);
    2590        
     2590
    25912591        if (mgmt == EXCHANGE_SERIALIZE)
    25922592                fibril_mutex_unlock(&sess->mutex);
    2593        
     2593
    25942594        fibril_mutex_lock(&async_sess_mutex);
    2595        
     2595
    25962596        list_append(&exch->sess_link, &sess->exch_list);
    25972597        list_append(&exch->global_link, &inactive_exch_list);
    25982598        fibril_condvar_signal(&avail_phone_cv);
    2599        
     2599
    26002600        fibril_mutex_unlock(&async_sess_mutex);
    26012601}
     
    26182618        if (exch == NULL)
    26192619                return ENOENT;
    2620        
     2620
    26212621        sysarg_t _flags = 0;
    26222622        sysarg_t _dst = (sysarg_t) -1;
    26232623        errno_t res = async_req_2_4(exch, IPC_M_SHARE_IN, (sysarg_t) size,
    26242624            arg, NULL, &_flags, NULL, &_dst);
    2625        
     2625
    26262626        if (flags)
    26272627                *flags = (unsigned int) _flags;
    2628        
     2628
    26292629        *dst = (void *) _dst;
    26302630        return res;
     
    26492649        assert(chandle);
    26502650        assert(size);
    2651        
     2651
    26522652        ipc_call_t data;
    26532653        *chandle = async_get_call(&data);
    2654        
     2654
    26552655        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
    26562656                return false;
    2657        
     2657
    26582658        *size = (size_t) IPC_GET_ARG1(data);
    26592659        return true;
     
    26922692        if (exch == NULL)
    26932693                return ENOENT;
    2694        
     2694
    26952695        return async_req_3_0(exch, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
    26962696            (sysarg_t) flags);
     
    27182718        assert(size);
    27192719        assert(flags);
    2720        
     2720
    27212721        ipc_call_t data;
    27222722        *chandle = async_get_call(&data);
    2723        
     2723
    27242724        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
    27252725                return false;
    2726        
     2726
    27272727        *size = (size_t) IPC_GET_ARG2(data);
    27282728        *flags = (unsigned int) IPC_GET_ARG3(data);
     
    27782778        if (exch == NULL)
    27792779                return ENOENT;
    2780        
     2780
    27812781        return async_req_2_0(exch, IPC_M_DATA_READ, (sysarg_t) dst,
    27822782            (sysarg_t) size);
     
    28222822        assert(chandle);
    28232823        assert(data);
    2824        
     2824
    28252825        *chandle = async_get_call(data);
    2826        
     2826
    28272827        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ)
    28282828                return false;
    2829        
     2829
    28302830        if (size)
    28312831                *size = (size_t) IPC_GET_ARG2(*data);
    2832        
     2832
    28332833        return true;
    28342834}
     
    28622862        if (exch == NULL)
    28632863                return ENOENT;
    2864        
     2864
    28652865        cap_handle_t chandle;
    28662866        if (!async_data_read_receive(&chandle, NULL)) {
     
    28682868                return EINVAL;
    28692869        }
    2870        
     2870
    28712871        aid_t msg = async_send_fast(exch, imethod, arg1, arg2, arg3, arg4,
    28722872            dataptr);
     
    28752875                return EINVAL;
    28762876        }
    2877        
     2877
    28782878        errno_t retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
    28792879            IPC_FF_ROUTE_FROM_ME);
     
    28832883                return retval;
    28842884        }
    2885        
     2885
    28862886        errno_t rc;
    28872887        async_wait_for(msg, &rc);
    2888        
     2888
    28892889        return (errno_t) rc;
    28902890}
     
    29032903        if (exch == NULL)
    29042904                return ENOENT;
    2905        
     2905
    29062906        return async_req_2_0(exch, IPC_M_DATA_WRITE, (sysarg_t) src,
    29072907            (sysarg_t) size);
     
    29482948        assert(chandle);
    29492949        assert(data);
    2950        
     2950
    29512951        *chandle = async_get_call(data);
    2952        
     2952
    29532953        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE)
    29542954                return false;
    2955        
     2955
    29562956        if (size)
    29572957                *size = (size_t) IPC_GET_ARG2(*data);
    2958        
     2958
    29592959        return true;
    29602960}
     
    30043004{
    30053005        assert(data);
    3006        
     3006
    30073007        cap_handle_t chandle;
    30083008        size_t size;
     
    30113011                return EINVAL;
    30123012        }
    3013        
     3013
    30143014        if (size < min_size) {
    30153015                ipc_answer_0(chandle, EINVAL);
    30163016                return EINVAL;
    30173017        }
    3018        
     3018
    30193019        if ((max_size > 0) && (size > max_size)) {
    30203020                ipc_answer_0(chandle, EINVAL);
    30213021                return EINVAL;
    30223022        }
    3023        
     3023
    30243024        if ((granularity > 0) && ((size % granularity) != 0)) {
    30253025                ipc_answer_0(chandle, EINVAL);
    30263026                return EINVAL;
    30273027        }
    3028        
     3028
    30293029        void *arg_data;
    3030        
     3030
    30313031        if (nullterm)
    30323032                arg_data = malloc(size + 1);
    30333033        else
    30343034                arg_data = malloc(size);
    3035        
     3035
    30363036        if (arg_data == NULL) {
    30373037                ipc_answer_0(chandle, ENOMEM);
    30383038                return ENOMEM;
    30393039        }
    3040        
     3040
    30413041        errno_t rc = async_data_write_finalize(chandle, arg_data, size);
    30423042        if (rc != EOK) {
     
    30443044                return rc;
    30453045        }
    3046        
     3046
    30473047        if (nullterm)
    30483048                ((char *) arg_data)[size] = 0;
    3049        
     3049
    30503050        *data = arg_data;
    30513051        if (received != NULL)
    30523052                *received = size;
    3053        
     3053
    30543054        return EOK;
    30553055}
     
    30783078        if (exch == NULL)
    30793079                return ENOENT;
    3080        
     3080
    30813081        cap_handle_t chandle;
    30823082        if (!async_data_write_receive(&chandle, NULL)) {
     
    30843084                return EINVAL;
    30853085        }
    3086        
     3086
    30873087        aid_t msg = async_send_fast(exch, imethod, arg1, arg2, arg3, arg4,
    30883088            dataptr);
     
    30913091                return EINVAL;
    30923092        }
    3093        
     3093
    30943094        errno_t retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
    30953095            IPC_FF_ROUTE_FROM_ME);
     
    30993099                return retval;
    31003100        }
    3101        
     3101
    31023102        errno_t rc;
    31033103        async_wait_for(msg, &rc);
    3104        
     3104
    31053105        return (errno_t) rc;
    31063106}
     
    31233123        cap_handle_t chandle = async_get_call(&call);
    31243124        cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call);
    3125        
     3125
    31263126        if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) {
    31273127                async_answer_0(chandle, EINVAL);
    31283128                return NULL;
    31293129        }
    3130        
     3130
    31313131        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    31323132        if (sess == NULL) {
     
    31343134                return NULL;
    31353135        }
    3136        
     3136
    31373137        sess->iface = 0;
    31383138        sess->mgmt = mgmt;
     
    31413141        sess->arg2 = 0;
    31423142        sess->arg3 = 0;
    3143        
     3143
    31443144        fibril_mutex_initialize(&sess->remote_state_mtx);
    31453145        sess->remote_state_data = NULL;
    3146        
     3146
    31473147        list_initialize(&sess->exch_list);
    31483148        fibril_mutex_initialize(&sess->mutex);
    31493149        atomic_set(&sess->refcnt, 0);
    3150        
     3150
    31513151        /* Acknowledge the connected phone */
    31523152        async_answer_0(chandle, EOK);
    3153        
     3153
    31543154        return sess;
    31553155}
     
    31723172{
    31733173        cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(*call);
    3174        
     3174
    31753175        if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || (phandle < 0))
    31763176                return NULL;
    3177        
     3177
    31783178        async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
    31793179        if (sess == NULL)
    31803180                return NULL;
    3181        
     3181
    31823182        sess->iface = 0;
    31833183        sess->mgmt = mgmt;
     
    31863186        sess->arg2 = 0;
    31873187        sess->arg3 = 0;
    3188        
     3188
    31893189        fibril_mutex_initialize(&sess->remote_state_mtx);
    31903190        sess->remote_state_data = NULL;
    3191        
     3191
    31923192        list_initialize(&sess->exch_list);
    31933193        fibril_mutex_initialize(&sess->mutex);
    31943194        atomic_set(&sess->refcnt, 0);
    3195        
     3195
    31963196        return sess;
    31973197}
     
    32083208{
    32093209        assert(chandle);
    3210        
     3210
    32113211        ipc_call_t call;
    32123212        *chandle = async_get_call(&call);
    3213        
     3213
    32143214        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
    32153215                return false;
    3216        
     3216
    32173217        if (arg1)
    32183218                *arg1 = IPC_GET_ARG1(call);
     
    32213221        if (arg3)
    32223222                *arg3 = IPC_GET_ARG3(call);
    3223        
     3223
    32243224        return true;
    32253225}
     
    32743274{
    32753275        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
    3276        
     3276
    32773277        fibril_mutex_unlock(&sess->remote_state_mtx);
    32783278}
     
    32923292        if (exch == NULL)
    32933293                return;
    3294        
     3294
    32953295        async_sess_t *sess = exch->sess;
    32963296        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
    3297        
     3297
    32983298        async_exchange_end(exch);
    32993299        fibril_mutex_unlock(&sess->remote_state_mtx);
Note: See TracChangeset for help on using the changeset viewer.