source: mainline/uspace/lib/c/generic/async.c@ 09696b54

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 09696b54 was c7bbf029, checked in by Martin Decky <martin@…>, 14 years ago

improve stack traces and assertions
reduce header files pollution

  • Property mode set to 100644
File size: 47.2 KB
RevLine 
[06502f7d]1/*
[df4ed85]2 * Copyright (c) 2006 Ondrej Palkovsky
[06502f7d]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[b2951e2]27 */
28
[a46da63]29/** @addtogroup libc
[b2951e2]30 * @{
31 */
32/** @file
[c07544d3]33 */
[06502f7d]34
[80649a91]35/**
36 * Asynchronous library
37 *
[c07544d3]38 * The aim of this library is to provide a facility for writing programs which
39 * utilize the asynchronous nature of HelenOS IPC, yet using a normal way of
40 * programming.
[80649a91]41 *
[9591265]42 * You should be able to write very simple multithreaded programs, the async
43 * framework will automatically take care of most synchronization problems.
[80649a91]44 *
[9591265]45 * Example of use (pseudo C):
[c07544d3]46 *
[80649a91]47 * 1) Multithreaded client application
[9591265]48 *
[c07544d3]49 * fibril_create(fibril1, ...);
50 * fibril_create(fibril2, ...);
51 * ...
52 *
53 * int fibril1(void *arg)
54 * {
[007e6efa]55 * conn = async_connect_me_to();
[c07544d3]56 * c1 = async_send(conn);
57 * c2 = async_send(conn);
58 * async_wait_for(c1);
59 * async_wait_for(c2);
60 * ...
61 * }
[80649a91]62 *
63 *
64 * 2) Multithreaded server application
65 *
[c07544d3]66 * main()
67 * {
68 * async_manager();
69 * }
70 *
71 * my_client_connection(icallid, *icall)
72 * {
73 * if (want_refuse) {
[64d2b10]74 * async_answer_0(icallid, ELIMIT);
[c07544d3]75 * return;
76 * }
[64d2b10]77 * async_answer_0(icallid, EOK);
[80649a91]78 *
[c07544d3]79 * callid = async_get_call(&call);
[0772aff]80 * somehow_handle_the_call(callid, call);
[64d2b10]81 * async_answer_2(callid, 1, 2, 3);
[53ca318]82 *
[c07544d3]83 * callid = async_get_call(&call);
84 * ...
85 * }
[a2cd194]86 *
[80649a91]87 */
[9591265]88
[64d2b10]89#define LIBC_ASYNC_C_
90#include <ipc/ipc.h>
[80649a91]91#include <async.h>
[64d2b10]92#undef LIBC_ASYNC_C_
93
94#include <futex.h>
[bc1f1c2]95#include <fibril.h>
[80649a91]96#include <stdio.h>
[d9c8c81]97#include <adt/hash_table.h>
98#include <adt/list.h>
[80649a91]99#include <assert.h>
100#include <errno.h>
[daa90e8]101#include <sys/time.h>
[c042bdd]102#include <arch/barrier.h>
[0cc4313]103#include <bool.h>
[c7bbf029]104#include <stdlib.h>
105#include <malloc.h>
[e26a4633]106#include "private/async.h"
[80649a91]107
[fc42b28]108atomic_t async_futex = FUTEX_INITIALIZER;
[80649a91]109
[8619f25]110/** Number of threads waiting for IPC in the kernel. */
111atomic_t threads_in_ipc_wait = { 0 };
112
[49d072e]113typedef struct {
114 awaiter_t wdata;
[e70bfa5]115
116 /** If reply was received. */
[c07544d3]117 bool done;
118
[e70bfa5]119 /** Pointer to where the answer data is stored. */
[c07544d3]120 ipc_call_t *dataptr;
121
[96b02eb9]122 sysarg_t retval;
[01ff41c]123} amsg_t;
124
[36c9234]125/**
[47b7006]126 * Structures of this type are used to group information about
127 * a call and about a message queue link.
[36c9234]128 */
[80649a91]129typedef struct {
130 link_t link;
131 ipc_callid_t callid;
132 ipc_call_t call;
133} msg_t;
134
[c80fdd0]135typedef struct {
136 sysarg_t in_task_hash;
137 link_t link;
138 int refcnt;
139 void *data;
140} client_t;
141
[80649a91]142typedef struct {
[49d072e]143 awaiter_t wdata;
[c07544d3]144
[e70bfa5]145 /** Hash table link. */
146 link_t link;
[c07544d3]147
[3c22f70]148 /** Incoming client task hash. */
149 sysarg_t in_task_hash;
[e70bfa5]150 /** Incoming phone hash. */
[96b02eb9]151 sysarg_t in_phone_hash;
[c07544d3]152
[23882034]153 /** Link to the client tracking structure. */
154 client_t *client;
[47b7006]155
[e70bfa5]156 /** Messages that should be delivered to this fibril. */
[c07544d3]157 link_t msg_queue;
158
[e70bfa5]159 /** Identification of the opening call. */
[80649a91]160 ipc_callid_t callid;
[e70bfa5]161 /** Call data of the opening call. */
[80649a91]162 ipc_call_t call;
[c07544d3]163
[e70bfa5]164 /** Identification of the closing call. */
165 ipc_callid_t close_callid;
[c07544d3]166
[e70bfa5]167 /** Fibril function that will be used to handle the connection. */
[bc1f1c2]168 void (*cfibril)(ipc_callid_t, ipc_call_t *);
[80649a91]169} connection_t;
170
[bc1f1c2]171/** Identifier of the incoming connection handled by the current fibril. */
[47b7006]172static fibril_local connection_t *FIBRIL_connection;
[e70bfa5]173
[46eec3b]174static void *default_client_data_constructor(void)
175{
176 return NULL;
177}
178
179static void default_client_data_destructor(void *data)
180{
181}
182
183static async_client_data_ctor_t async_client_data_create =
184 default_client_data_constructor;
185static async_client_data_dtor_t async_client_data_destroy =
186 default_client_data_destructor;
187
188void async_set_client_data_constructor(async_client_data_ctor_t ctor)
189{
190 async_client_data_create = ctor;
191}
192
193void async_set_client_data_destructor(async_client_data_dtor_t dtor)
194{
195 async_client_data_destroy = dtor;
196}
197
[23882034]198void *async_client_data_get(void)
199{
200 assert(FIBRIL_connection);
201 return FIBRIL_connection->client->data;
202}
203
[47b7006]204/** Default fibril function that gets called to handle new connection.
205 *
206 * This function is defined as a weak symbol - to be redefined in user code.
207 *
208 * @param callid Hash of the incoming call.
209 * @param call Data of the incoming call.
210 *
211 */
212static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
213{
214 ipc_answer_0(callid, ENOENT);
215}
[36c9234]216
217/**
218 * Pointer to a fibril function that will be used to handle connections.
219 */
[da0c91e7]220static async_client_conn_t client_connection = default_client_connection;
[c07544d3]221
[47b7006]222/** Default fibril function that gets called to handle interrupt notifications.
223 *
224 * This function is defined as a weak symbol - to be redefined in user code.
225 *
226 * @param callid Hash of the incoming call.
227 * @param call Data of the incoming call.
228 *
229 */
230static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
231{
232}
233
[36c9234]234/**
235 * Pointer to a fibril function that will be used to handle interrupt
236 * notifications.
237 */
[51dbadf3]238static async_client_conn_t interrupt_received = default_interrupt_received;
[da0c91e7]239
[c80fdd0]240static hash_table_t client_hash_table;
[c07544d3]241static hash_table_t conn_hash_table;
242static LIST_INITIALIZE(timeout_list);
243
[47b7006]244#define CLIENT_HASH_TABLE_BUCKETS 32
245#define CONN_HASH_TABLE_BUCKETS 32
[c80fdd0]246
[47b7006]247static hash_index_t client_hash(unsigned long key[])
[c80fdd0]248{
249 assert(key);
[47b7006]250 return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
[c80fdd0]251}
252
253static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
254{
[47b7006]255 client_t *client = hash_table_get_instance(item, client_t, link);
256 return (key[0] == client->in_task_hash);
[c80fdd0]257}
258
259static void client_remove(link_t *item)
260{
261}
262
263/** Operations for the client hash table. */
264static hash_table_operations_t client_hash_table_ops = {
265 .hash = client_hash,
266 .compare = client_compare,
267 .remove_callback = client_remove
268};
[80649a91]269
[e70bfa5]270/** Compute hash into the connection hash table based on the source phone hash.
271 *
[c07544d3]272 * @param key Pointer to source phone hash.
273 *
274 * @return Index into the connection hash table.
[e70bfa5]275 *
276 */
[47b7006]277static hash_index_t conn_hash(unsigned long key[])
[450cd3a]278{
[80649a91]279 assert(key);
[47b7006]280 return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
[450cd3a]281}
[06502f7d]282
[e70bfa5]283/** Compare hash table item with a key.
284 *
[c07544d3]285 * @param key Array containing the source phone hash as the only item.
286 * @param keys Expected 1 but ignored.
287 * @param item Connection hash table item.
288 *
289 * @return True on match, false otherwise.
[e70bfa5]290 *
291 */
[80649a91]292static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
[450cd3a]293{
[47b7006]294 connection_t *conn = hash_table_get_instance(item, connection_t, link);
295 return (key[0] == conn->in_phone_hash);
[450cd3a]296}
[06502f7d]297
[80649a91]298static void conn_remove(link_t *item)
[450cd3a]299{
300}
301
[e70bfa5]302/** Operations for the connection hash table. */
[80649a91]303static hash_table_operations_t conn_hash_table_ops = {
304 .hash = conn_hash,
305 .compare = conn_compare,
306 .remove_callback = conn_remove
307};
308
[e70bfa5]309/** Sort in current fibril's timeout request.
[49d072e]310 *
[c07544d3]311 * @param wd Wait data of the current fibril.
312 *
[49d072e]313 */
[b6ee5b1]314void async_insert_timeout(awaiter_t *wd)
[49d072e]315{
[f53cc81]316 wd->to_event.occurred = false;
317 wd->to_event.inlist = true;
[c07544d3]318
319 link_t *tmp = timeout_list.next;
[49d072e]320 while (tmp != &timeout_list) {
[47b7006]321 awaiter_t *cur
322 = list_get_instance(tmp, awaiter_t, to_event.link);
[c07544d3]323
[f53cc81]324 if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
[49d072e]325 break;
[47b7006]326
[49d072e]327 tmp = tmp->next;
328 }
[c07544d3]329
[f53cc81]330 list_append(&wd->to_event.link, tmp);
[49d072e]331}
332
[e70bfa5]333/** Try to route a call to an appropriate connection fibril.
[80649a91]334 *
[36c9234]335 * If the proper connection fibril is found, a message with the call is added to
336 * its message queue. If the fibril was not active, it is activated and all
337 * timeouts are unregistered.
338 *
[c07544d3]339 * @param callid Hash of the incoming call.
340 * @param call Data of the incoming call.
341 *
342 * @return False if the call doesn't match any connection.
[47b7006]343 * @return True if the call was passed to the respective connection fibril.
[36c9234]344 *
[80649a91]345 */
[c07544d3]346static bool route_call(ipc_callid_t callid, ipc_call_t *call)
[450cd3a]347{
[01ff41c]348 futex_down(&async_futex);
[c07544d3]349
350 unsigned long key = call->in_phone_hash;
351 link_t *hlp = hash_table_find(&conn_hash_table, &key);
352
[80649a91]353 if (!hlp) {
[01ff41c]354 futex_up(&async_futex);
[c07544d3]355 return false;
[450cd3a]356 }
[c07544d3]357
358 connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
359
360 msg_t *msg = malloc(sizeof(*msg));
361 if (!msg) {
362 futex_up(&async_futex);
363 return false;
364 }
365
[80649a91]366 msg->callid = callid;
367 msg->call = *call;
368 list_append(&msg->link, &conn->msg_queue);
[c07544d3]369
[228e490]370 if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP)
[41269bd]371 conn->close_callid = callid;
[80649a91]372
[36c9234]373 /* If the connection fibril is waiting for an event, activate it */
[49d072e]374 if (!conn->wdata.active) {
[c07544d3]375
[49d072e]376 /* If in timeout list, remove it */
[f53cc81]377 if (conn->wdata.to_event.inlist) {
378 conn->wdata.to_event.inlist = false;
379 list_remove(&conn->wdata.to_event.link);
[49d072e]380 }
[c07544d3]381
382 conn->wdata.active = true;
[bc1f1c2]383 fibril_add_ready(conn->wdata.fid);
[80649a91]384 }
[c07544d3]385
[01ff41c]386 futex_up(&async_futex);
[c07544d3]387 return true;
388}
[80649a91]389
[c07544d3]390/** Notification fibril.
391 *
392 * When a notification arrives, a fibril with this implementing function is
393 * created. It calls interrupt_received() and does the final cleanup.
394 *
395 * @param arg Message structure pointer.
396 *
397 * @return Always zero.
398 *
399 */
400static int notification_fibril(void *arg)
401{
402 msg_t *msg = (msg_t *) arg;
403 interrupt_received(msg->callid, &msg->call);
404
405 free(msg);
406 return 0;
407}
408
409/** Process interrupt notification.
410 *
411 * A new fibril is created which would process the notification.
412 *
413 * @param callid Hash of the incoming call.
414 * @param call Data of the incoming call.
415 *
416 * @return False if an error occured.
417 * True if the call was passed to the notification fibril.
418 *
419 */
420static bool process_notification(ipc_callid_t callid, ipc_call_t *call)
421{
422 futex_down(&async_futex);
423
424 msg_t *msg = malloc(sizeof(*msg));
425 if (!msg) {
426 futex_up(&async_futex);
427 return false;
428 }
429
430 msg->callid = callid;
431 msg->call = *call;
432
433 fid_t fid = fibril_create(notification_fibril, msg);
[86d7bfa]434 if (fid == 0) {
435 free(msg);
436 futex_up(&async_futex);
437 return false;
438 }
439
[c07544d3]440 fibril_add_ready(fid);
441
442 futex_up(&async_futex);
443 return true;
[80649a91]444}
445
[e70bfa5]446/** Return new incoming message for the current (fibril-local) connection.
447 *
[c07544d3]448 * @param call Storage where the incoming call data will be stored.
449 * @param usecs Timeout in microseconds. Zero denotes no timeout.
450 *
451 * @return If no timeout was specified, then a hash of the
452 * incoming call is returned. If a timeout is specified,
453 * then a hash of the incoming call is returned unless
454 * the timeout expires prior to receiving a message. In
455 * that case zero is returned.
[e70bfa5]456 *
457 */
[49d072e]458ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
[80649a91]459{
[bc1f1c2]460 assert(FIBRIL_connection);
[c07544d3]461
462 /* Why doing this?
463 * GCC 4.1.0 coughs on FIBRIL_connection-> dereference.
[6c46350]464 * GCC 4.1.1 happilly puts the rdhwr instruction in delay slot.
[c07544d3]465 * I would never expect to find so many errors in
466 * a compiler.
[6c46350]467 */
[c07544d3]468 connection_t *conn = FIBRIL_connection;
469
[01ff41c]470 futex_down(&async_futex);
[c07544d3]471
[49d072e]472 if (usecs) {
[f53cc81]473 gettimeofday(&conn->wdata.to_event.expires, NULL);
474 tv_add(&conn->wdata.to_event.expires, usecs);
[c07544d3]475 } else
[f53cc81]476 conn->wdata.to_event.inlist = false;
[c07544d3]477
[e70bfa5]478 /* If nothing in queue, wait until something arrives */
[6c46350]479 while (list_empty(&conn->msg_queue)) {
[8c8f8d6]480 if (conn->close_callid) {
481 /*
482 * Handle the case when the connection was already
483 * closed by the client but the server did not notice
484 * the first IPC_M_PHONE_HUNGUP call and continues to
485 * call async_get_call_timeout(). Repeat
[47b7006]486 * IPC_M_PHONE_HUNGUP until the caller notices.
[8c8f8d6]487 */
488 memset(call, 0, sizeof(ipc_call_t));
[228e490]489 IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
[8c8f8d6]490 futex_up(&async_futex);
491 return conn->close_callid;
492 }
[47b7006]493
[085bd54]494 if (usecs)
[b6ee5b1]495 async_insert_timeout(&conn->wdata);
[c07544d3]496
497 conn->wdata.active = false;
498
[c7509e5]499 /*
500 * Note: the current fibril will be rescheduled either due to a
501 * timeout or due to an arriving message destined to it. In the
502 * former case, handle_expired_timeouts() and, in the latter
503 * case, route_call() will perform the wakeup.
504 */
[116d3f6f]505 fibril_switch(FIBRIL_TO_MANAGER);
[c07544d3]506
[e70bfa5]507 /*
[c07544d3]508 * Futex is up after getting back from async_manager.
509 * Get it again.
[c7509e5]510 */
[49d072e]511 futex_down(&async_futex);
[f53cc81]512 if ((usecs) && (conn->wdata.to_event.occurred)
[c07544d3]513 && (list_empty(&conn->msg_queue))) {
[e70bfa5]514 /* If we timed out -> exit */
[49d072e]515 futex_up(&async_futex);
516 return 0;
517 }
[450cd3a]518 }
519
[c07544d3]520 msg_t *msg = list_get_instance(conn->msg_queue.next, msg_t, link);
[80649a91]521 list_remove(&msg->link);
[c07544d3]522
523 ipc_callid_t callid = msg->callid;
[80649a91]524 *call = msg->call;
525 free(msg);
526
[01ff41c]527 futex_up(&async_futex);
[80649a91]528 return callid;
529}
530
[f2f0392]531/** Wrapper for client connection fibril.
532 *
[36c9234]533 * When a new connection arrives, a fibril with this implementing function is
[f2f0392]534 * created. It calls client_connection() and does the final cleanup.
[a2cd194]535 *
[c07544d3]536 * @param arg Connection structure pointer.
537 *
538 * @return Always zero.
[a2cd194]539 *
540 */
[c07544d3]541static int connection_fibril(void *arg)
[80649a91]542{
[c07544d3]543 /*
[c80fdd0]544 * Setup fibril-local connection pointer.
[c07544d3]545 */
[bc1f1c2]546 FIBRIL_connection = (connection_t *) arg;
[47b7006]547
548 futex_down(&async_futex);
549
[c80fdd0]550 /*
551 * Add our reference for the current connection in the client task
552 * tracking structure. If this is the first reference, create and
553 * hash in a new tracking structure.
554 */
[47b7006]555
556 unsigned long key = FIBRIL_connection->in_task_hash;
557 link_t *lnk = hash_table_find(&client_hash_table, &key);
558
559 client_t *client;
560
[c80fdd0]561 if (lnk) {
[47b7006]562 client = hash_table_get_instance(lnk, client_t, link);
563 client->refcnt++;
[c80fdd0]564 } else {
[47b7006]565 client = malloc(sizeof(client_t));
566 if (!client) {
[c80fdd0]567 ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
568 futex_up(&async_futex);
569 return 0;
570 }
[47b7006]571
572 client->in_task_hash = FIBRIL_connection->in_task_hash;
573
[46eec3b]574 async_serialize_start();
[47b7006]575 client->data = async_client_data_create();
[46eec3b]576 async_serialize_end();
[47b7006]577
578 client->refcnt = 1;
579 hash_table_insert(&client_hash_table, &key, &client->link);
[c80fdd0]580 }
[47b7006]581
[c80fdd0]582 futex_up(&async_futex);
[47b7006]583
584 FIBRIL_connection->client = client;
585
[c80fdd0]586 /*
587 * Call the connection handler function.
588 */
[bc1f1c2]589 FIBRIL_connection->cfibril(FIBRIL_connection->callid,
590 &FIBRIL_connection->call);
[a46da63]591
[c80fdd0]592 /*
593 * Remove the reference for this client task connection.
594 */
[47b7006]595 bool destroy;
596
[01ff41c]597 futex_down(&async_futex);
[47b7006]598
599 if (--client->refcnt == 0) {
[c80fdd0]600 hash_table_remove(&client_hash_table, &key, 1);
[8526e585]601 destroy = true;
[47b7006]602 } else
603 destroy = false;
604
[c80fdd0]605 futex_up(&async_futex);
[47b7006]606
[8526e585]607 if (destroy) {
[47b7006]608 if (client->data)
609 async_client_data_destroy(client->data);
610
611 free(client);
[8526e585]612 }
[47b7006]613
[c80fdd0]614 /*
615 * Remove myself from the connection hash table.
616 */
617 futex_down(&async_futex);
618 key = FIBRIL_connection->in_phone_hash;
[a2cd194]619 hash_table_remove(&conn_hash_table, &key, 1);
[01ff41c]620 futex_up(&async_futex);
[a46da63]621
[c80fdd0]622 /*
623 * Answer all remaining messages with EHANGUP.
624 */
[bc1f1c2]625 while (!list_empty(&FIBRIL_connection->msg_queue)) {
[47b7006]626 msg_t *msg =
627 list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
628 link);
[c07544d3]629
[a2cd194]630 list_remove(&msg->link);
[b74959bd]631 ipc_answer_0(msg->callid, EHANGUP);
[a2cd194]632 free(msg);
633 }
[c07544d3]634
[c80fdd0]635 /*
636 * If the connection was hung-up, answer the last call,
637 * i.e. IPC_M_PHONE_HUNGUP.
638 */
[bc1f1c2]639 if (FIBRIL_connection->close_callid)
[b74959bd]640 ipc_answer_0(FIBRIL_connection->close_callid, EOK);
[a46da63]641
[9c31643]642 free(FIBRIL_connection);
[a46da63]643 return 0;
[80649a91]644}
645
[f2f0392]646/** Create a new fibril for a new connection.
[80649a91]647 *
[c07544d3]648 * Create new fibril for connection, fill in connection structures and inserts
[f2f0392]649 * it into the hash table, so that later we can easily do routing of messages to
650 * particular fibrils.
[53ca318]651 *
[3c22f70]652 * @param in_task_hash Identification of the incoming connection.
[c07544d3]653 * @param in_phone_hash Identification of the incoming connection.
654 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call.
655 * If callid is zero, the connection was opened by
656 * accepting the IPC_M_CONNECT_TO_ME call and this function
657 * is called directly by the server.
658 * @param call Call data of the opening call.
659 * @param cfibril Fibril function that should be called upon opening the
660 * connection.
661 *
662 * @return New fibril id or NULL on failure.
[36c9234]663 *
[80649a91]664 */
[3c22f70]665fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
666 ipc_callid_t callid, ipc_call_t *call,
667 void (*cfibril)(ipc_callid_t, ipc_call_t *))
[80649a91]668{
[c07544d3]669 connection_t *conn = malloc(sizeof(*conn));
[80649a91]670 if (!conn) {
[6675c70]671 if (callid)
[b74959bd]672 ipc_answer_0(callid, ENOMEM);
[47b7006]673
[0b4a67a]674 return (uintptr_t) NULL;
[80649a91]675 }
[c07544d3]676
[3c22f70]677 conn->in_task_hash = in_task_hash;
[44c6d88d]678 conn->in_phone_hash = in_phone_hash;
[80649a91]679 list_initialize(&conn->msg_queue);
680 conn->callid = callid;
[c4702804]681 conn->close_callid = 0;
[c07544d3]682
[eaf34f7]683 if (call)
684 conn->call = *call;
[6b21292]685
[c07544d3]686 /* We will activate the fibril ASAP */
687 conn->wdata.active = true;
688 conn->cfibril = cfibril;
[bc1f1c2]689 conn->wdata.fid = fibril_create(connection_fibril, conn);
[c07544d3]690
[86d7bfa]691 if (conn->wdata.fid == 0) {
[80649a91]692 free(conn);
[86d7bfa]693
[6675c70]694 if (callid)
[b74959bd]695 ipc_answer_0(callid, ENOMEM);
[86d7bfa]696
[0b4a67a]697 return (uintptr_t) NULL;
[80649a91]698 }
[6b21292]699
[36c9234]700 /* Add connection to the connection hash table */
[9db9b10]701 unsigned long key = conn->in_phone_hash;
[c07544d3]702
[01ff41c]703 futex_down(&async_futex);
[80649a91]704 hash_table_insert(&conn_hash_table, &key, &conn->link);
[01ff41c]705 futex_up(&async_futex);
[6b21292]706
[bc1f1c2]707 fibril_add_ready(conn->wdata.fid);
[6b21292]708
[bc1f1c2]709 return conn->wdata.fid;
[80649a91]710}
711
[36c9234]712/** Handle a call that was received.
713 *
714 * If the call has the IPC_M_CONNECT_ME_TO method, a new connection is created.
715 * Otherwise the call is routed to its connection fibril.
716 *
[c07544d3]717 * @param callid Hash of the incoming call.
718 * @param call Data of the incoming call.
[6b21292]719 *
[36c9234]720 */
[80649a91]721static void handle_call(ipc_callid_t callid, ipc_call_t *call)
722{
[47b7006]723 /* Unrouted call - take some default action */
[15039b67]724 if ((callid & IPC_CALLID_NOTIFICATION)) {
[c07544d3]725 process_notification(callid, call);
[47b7006]726 return;
[6b21292]727 }
728
[228e490]729 switch (IPC_GET_IMETHOD(*call)) {
[2c0e5d2]730 case IPC_M_CONNECT_ME:
[80649a91]731 case IPC_M_CONNECT_ME_TO:
[47b7006]732 /* Open new connection with fibril, etc. */
[3c22f70]733 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
734 callid, call, client_connection);
[47b7006]735 return;
[80649a91]736 }
[6b21292]737
[36c9234]738 /* Try to route the call through the connection hash table */
[44c6d88d]739 if (route_call(callid, call))
[47b7006]740 return;
[6b21292]741
[44c6d88d]742 /* Unknown call from unknown phone - hang it up */
[b74959bd]743 ipc_answer_0(callid, EHANGUP);
[450cd3a]744}
745
[f2f0392]746/** Fire all timeouts that expired. */
[c042bdd]747static void handle_expired_timeouts(void)
748{
749 struct timeval tv;
[36c9234]750 gettimeofday(&tv, NULL);
[c07544d3]751
[c042bdd]752 futex_down(&async_futex);
[c07544d3]753
754 link_t *cur = timeout_list.next;
[c042bdd]755 while (cur != &timeout_list) {
[47b7006]756 awaiter_t *waiter =
757 list_get_instance(cur, awaiter_t, to_event.link);
[c07544d3]758
[f53cc81]759 if (tv_gt(&waiter->to_event.expires, &tv))
[c042bdd]760 break;
[47b7006]761
[c042bdd]762 cur = cur->next;
[47b7006]763
[f53cc81]764 list_remove(&waiter->to_event.link);
765 waiter->to_event.inlist = false;
766 waiter->to_event.occurred = true;
[c07544d3]767
[36c9234]768 /*
[c07544d3]769 * Redundant condition?
770 * The fibril should not be active when it gets here.
[c042bdd]771 */
[49d072e]772 if (!waiter->active) {
[c07544d3]773 waiter->active = true;
[bc1f1c2]774 fibril_add_ready(waiter->fid);
[c042bdd]775 }
776 }
[c07544d3]777
[c042bdd]778 futex_up(&async_futex);
779}
780
[36c9234]781/** Endless loop dispatching incoming calls and answers.
782 *
[c07544d3]783 * @return Never returns.
784 *
[36c9234]785 */
[085bd54]786static int async_manager_worker(void)
[80649a91]787{
[c07544d3]788 while (true) {
[116d3f6f]789 if (fibril_switch(FIBRIL_FROM_MANAGER)) {
[47b7006]790 futex_up(&async_futex);
[36c9234]791 /*
792 * async_futex is always held when entering a manager
793 * fibril.
[a46da63]794 */
[80649a91]795 continue;
796 }
[c07544d3]797
[c042bdd]798 futex_down(&async_futex);
[c07544d3]799
800 suseconds_t timeout;
[c042bdd]801 if (!list_empty(&timeout_list)) {
[cc27c8c5]802 awaiter_t *waiter = list_get_instance(timeout_list.next,
[f53cc81]803 awaiter_t, to_event.link);
[c07544d3]804
805 struct timeval tv;
[bc1f1c2]806 gettimeofday(&tv, NULL);
[c07544d3]807
[f53cc81]808 if (tv_gteq(&tv, &waiter->to_event.expires)) {
[6c46350]809 futex_up(&async_futex);
[c042bdd]810 handle_expired_timeouts();
811 continue;
812 } else
[47b7006]813 timeout = tv_sub(&waiter->to_event.expires, &tv);
[c042bdd]814 } else
[0b99e40]815 timeout = SYNCH_NO_TIMEOUT;
[c07544d3]816
[c042bdd]817 futex_up(&async_futex);
[47b7006]818
[8619f25]819 atomic_inc(&threads_in_ipc_wait);
[c07544d3]820
821 ipc_call_t call;
[cc27c8c5]822 ipc_callid_t callid = ipc_wait_cycle(&call, timeout,
823 SYNCH_FLAGS_NONE);
[c07544d3]824
[8619f25]825 atomic_dec(&threads_in_ipc_wait);
[47b7006]826
[0b99e40]827 if (!callid) {
[c042bdd]828 handle_expired_timeouts();
[0b99e40]829 continue;
830 }
[c07544d3]831
832 if (callid & IPC_CALLID_ANSWERED)
[80649a91]833 continue;
[c07544d3]834
[80649a91]835 handle_call(callid, &call);
836 }
[a46da63]837
838 return 0;
[80649a91]839}
840
[36c9234]841/** Function to start async_manager as a standalone fibril.
[c07544d3]842 *
[36c9234]843 * When more kernel threads are used, one async manager should exist per thread.
844 *
[c07544d3]845 * @param arg Unused.
846 * @return Never returns.
[36c9234]847 *
[a2cd194]848 */
[9591265]849static int async_manager_fibril(void *arg)
[80649a91]850{
[a46da63]851 futex_up(&async_futex);
[c07544d3]852
[36c9234]853 /*
854 * async_futex is always locked when entering manager
855 */
[085bd54]856 async_manager_worker();
[a46da63]857
858 return 0;
[80649a91]859}
[450cd3a]860
[36c9234]861/** Add one manager to manager list. */
[80649a91]862void async_create_manager(void)
[450cd3a]863{
[c07544d3]864 fid_t fid = fibril_create(async_manager_fibril, NULL);
[86d7bfa]865 if (fid != 0)
866 fibril_add_manager(fid);
[80649a91]867}
868
869/** Remove one manager from manager list */
870void async_destroy_manager(void)
871{
[bc1f1c2]872 fibril_remove_manager();
[80649a91]873}
874
[36c9234]875/** Initialize the async framework.
876 *
877 */
[47b7006]878void __async_init(void)
[80649a91]879{
[c80fdd0]880 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
[47b7006]881 &client_hash_table_ops))
882 abort();
[80649a91]883
[47b7006]884 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1,
885 &conn_hash_table_ops))
886 abort();
[450cd3a]887}
[01ff41c]888
[36c9234]889/** Reply received callback.
[01ff41c]890 *
[36c9234]891 * This function is called whenever a reply for an asynchronous message sent out
892 * by the asynchronous framework is received.
893 *
894 * Notify the fibril which is waiting for this message that it has arrived.
895 *
[c07544d3]896 * @param arg Pointer to the asynchronous message record.
897 * @param retval Value returned in the answer.
898 * @param data Call data of the answer.
[47b7006]899 *
[01ff41c]900 */
[c07544d3]901static void reply_received(void *arg, int retval, ipc_call_t *data)
[01ff41c]902{
[9db9b10]903 futex_down(&async_futex);
904
[c07544d3]905 amsg_t *msg = (amsg_t *) arg;
[01ff41c]906 msg->retval = retval;
[c07544d3]907
[36c9234]908 /* Copy data after futex_down, just in case the call was detached */
[9db9b10]909 if ((msg->dataptr) && (data))
[c07544d3]910 *msg->dataptr = *data;
911
[c042bdd]912 write_barrier();
[c07544d3]913
[c042bdd]914 /* Remove message from timeout list */
[f53cc81]915 if (msg->wdata.to_event.inlist)
916 list_remove(&msg->wdata.to_event.link);
[c07544d3]917
918 msg->done = true;
[36c9234]919 if (!msg->wdata.active) {
[c07544d3]920 msg->wdata.active = true;
[bc1f1c2]921 fibril_add_ready(msg->wdata.fid);
[01ff41c]922 }
[c07544d3]923
[01ff41c]924 futex_up(&async_futex);
925}
926
[36c9234]927/** Send message and return id of the sent message.
928 *
929 * The return value can be used as input for async_wait() to wait for
930 * completion.
[01ff41c]931 *
[c07544d3]932 * @param phoneid Handle of the phone that will be used for the send.
933 * @param method Service-defined method.
934 * @param arg1 Service-defined payload argument.
935 * @param arg2 Service-defined payload argument.
936 * @param arg3 Service-defined payload argument.
937 * @param arg4 Service-defined payload argument.
938 * @param dataptr If non-NULL, storage where the reply data will be
939 * stored.
940 *
941 * @return Hash of the sent message or 0 on error.
[36c9234]942 *
[01ff41c]943 */
[96b02eb9]944aid_t async_send_fast(int phoneid, sysarg_t method, sysarg_t arg1,
945 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
[01ff41c]946{
[47b7006]947 amsg_t *msg = malloc(sizeof(amsg_t));
[c07544d3]948
949 if (!msg)
950 return 0;
[6b21292]951
[c07544d3]952 msg->done = false;
[01ff41c]953 msg->dataptr = dataptr;
[6b21292]954
[f53cc81]955 msg->wdata.to_event.inlist = false;
[47b7006]956
957 /*
958 * We may sleep in the next method,
959 * but it will use its own means
960 */
[c07544d3]961 msg->wdata.active = true;
962
[0cc4313]963 ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, msg,
[c07544d3]964 reply_received, true);
[6b21292]965
[01ff41c]966 return (aid_t) msg;
967}
968
[90f5d64]969/** Send message and return id of the sent message
970 *
[36c9234]971 * The return value can be used as input for async_wait() to wait for
972 * completion.
973 *
[c07544d3]974 * @param phoneid Handle of the phone that will be used for the send.
975 * @param method Service-defined method.
976 * @param arg1 Service-defined payload argument.
977 * @param arg2 Service-defined payload argument.
978 * @param arg3 Service-defined payload argument.
979 * @param arg4 Service-defined payload argument.
980 * @param arg5 Service-defined payload argument.
981 * @param dataptr If non-NULL, storage where the reply data will be
982 * stored.
983 *
984 * @return Hash of the sent message or 0 on error.
[36c9234]985 *
[90f5d64]986 */
[96b02eb9]987aid_t async_send_slow(int phoneid, sysarg_t method, sysarg_t arg1,
988 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
[0cc4313]989 ipc_call_t *dataptr)
[90f5d64]990{
[47b7006]991 amsg_t *msg = malloc(sizeof(amsg_t));
[6b21292]992
[c07544d3]993 if (!msg)
994 return 0;
995
996 msg->done = false;
[90f5d64]997 msg->dataptr = dataptr;
[6b21292]998
[f53cc81]999 msg->wdata.to_event.inlist = false;
[47b7006]1000
1001 /*
1002 * We may sleep in the next method,
1003 * but it will use its own means
1004 */
[c07544d3]1005 msg->wdata.active = true;
[6b21292]1006
[0cc4313]1007 ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, msg,
[c07544d3]1008 reply_received, true);
[6b21292]1009
[90f5d64]1010 return (aid_t) msg;
1011}
1012
[36c9234]1013/** Wait for a message sent by the async framework.
[01ff41c]1014 *
[c07544d3]1015 * @param amsgid Hash of the message to wait for.
1016 * @param retval Pointer to storage where the retval of the answer will
1017 * be stored.
1018 *
[01ff41c]1019 */
[96b02eb9]1020void async_wait_for(aid_t amsgid, sysarg_t *retval)
[01ff41c]1021{
1022 amsg_t *msg = (amsg_t *) amsgid;
[c07544d3]1023
[01ff41c]1024 futex_down(&async_futex);
1025 if (msg->done) {
1026 futex_up(&async_futex);
1027 goto done;
1028 }
[c07544d3]1029
[bc1f1c2]1030 msg->wdata.fid = fibril_get_id();
[c07544d3]1031 msg->wdata.active = false;
[f53cc81]1032 msg->wdata.to_event.inlist = false;
[c07544d3]1033
[36c9234]1034 /* Leave the async_futex locked when entering this function */
[116d3f6f]1035 fibril_switch(FIBRIL_TO_MANAGER);
[c07544d3]1036
1037 /* Futex is up automatically after fibril_switch */
1038
[01ff41c]1039done:
1040 if (retval)
1041 *retval = msg->retval;
[c07544d3]1042
[01ff41c]1043 free(msg);
1044}
[0b99e40]1045
[36c9234]1046/** Wait for a message sent by the async framework, timeout variant.
[c042bdd]1047 *
[c07544d3]1048 * @param amsgid Hash of the message to wait for.
1049 * @param retval Pointer to storage where the retval of the answer will
1050 * be stored.
1051 * @param timeout Timeout in microseconds.
1052 *
1053 * @return Zero on success, ETIMEOUT if the timeout has expired.
[c042bdd]1054 *
1055 */
[96b02eb9]1056int async_wait_timeout(aid_t amsgid, sysarg_t *retval, suseconds_t timeout)
[c042bdd]1057{
1058 amsg_t *msg = (amsg_t *) amsgid;
[c07544d3]1059
[86029498]1060 /* TODO: Let it go through the event read at least once */
1061 if (timeout < 0)
1062 return ETIMEOUT;
[c07544d3]1063
[c042bdd]1064 futex_down(&async_futex);
1065 if (msg->done) {
1066 futex_up(&async_futex);
1067 goto done;
1068 }
[c07544d3]1069
[f53cc81]1070 gettimeofday(&msg->wdata.to_event.expires, NULL);
1071 tv_add(&msg->wdata.to_event.expires, timeout);
[c07544d3]1072
[bc1f1c2]1073 msg->wdata.fid = fibril_get_id();
[c07544d3]1074 msg->wdata.active = false;
[b6ee5b1]1075 async_insert_timeout(&msg->wdata);
[c07544d3]1076
[36c9234]1077 /* Leave the async_futex locked when entering this function */
[116d3f6f]1078 fibril_switch(FIBRIL_TO_MANAGER);
[c07544d3]1079
1080 /* Futex is up automatically after fibril_switch */
1081
[c042bdd]1082 if (!msg->done)
1083 return ETIMEOUT;
[c07544d3]1084
[c042bdd]1085done:
1086 if (retval)
1087 *retval = msg->retval;
[c07544d3]1088
[c042bdd]1089 free(msg);
[c07544d3]1090
[c042bdd]1091 return 0;
1092}
[0b99e40]1093
[36c9234]1094/** Wait for specified time.
[44c6d88d]1095 *
[36c9234]1096 * The current fibril is suspended but the thread continues to execute.
1097 *
[c07544d3]1098 * @param timeout Duration of the wait in microseconds.
1099 *
[44c6d88d]1100 */
1101void async_usleep(suseconds_t timeout)
1102{
[47b7006]1103 amsg_t *msg = malloc(sizeof(amsg_t));
[44c6d88d]1104
1105 if (!msg)
1106 return;
[6b21292]1107
[bc1f1c2]1108 msg->wdata.fid = fibril_get_id();
[c07544d3]1109 msg->wdata.active = false;
[6b21292]1110
[f53cc81]1111 gettimeofday(&msg->wdata.to_event.expires, NULL);
1112 tv_add(&msg->wdata.to_event.expires, timeout);
[6b21292]1113
[44c6d88d]1114 futex_down(&async_futex);
[c07544d3]1115
[b6ee5b1]1116 async_insert_timeout(&msg->wdata);
[c07544d3]1117
[36c9234]1118 /* Leave the async_futex locked when entering this function */
[116d3f6f]1119 fibril_switch(FIBRIL_TO_MANAGER);
[c07544d3]1120
1121 /* Futex is up automatically after fibril_switch() */
1122
[44c6d88d]1123 free(msg);
1124}
[da0c91e7]1125
[36c9234]1126/** Setter for client_connection function pointer.
[da0c91e7]1127 *
[c07544d3]1128 * @param conn Function that will implement a new connection fibril.
1129 *
[da0c91e7]1130 */
1131void async_set_client_connection(async_client_conn_t conn)
1132{
1133 client_connection = conn;
1134}
[36c9234]1135
1136/** Setter for interrupt_received function pointer.
1137 *
[c07544d3]1138 * @param intr Function that will implement a new interrupt
1139 * notification fibril.
[36c9234]1140 */
[c07544d3]1141void async_set_interrupt_received(async_client_conn_t intr)
[51dbadf3]1142{
[c07544d3]1143 interrupt_received = intr;
[51dbadf3]1144}
[085bd54]1145
[0cc4313]1146/** Pseudo-synchronous message sending - fast version.
1147 *
1148 * Send message asynchronously and return only after the reply arrives.
1149 *
1150 * This function can only transfer 4 register payload arguments. For
1151 * transferring more arguments, see the slower async_req_slow().
1152 *
[c07544d3]1153 * @param phoneid Hash of the phone through which to make the call.
1154 * @param method Method of the call.
1155 * @param arg1 Service-defined payload argument.
1156 * @param arg2 Service-defined payload argument.
1157 * @param arg3 Service-defined payload argument.
1158 * @param arg4 Service-defined payload argument.
1159 * @param r1 If non-NULL, storage for the 1st reply argument.
1160 * @param r2 If non-NULL, storage for the 2nd reply argument.
1161 * @param r3 If non-NULL, storage for the 3rd reply argument.
1162 * @param r4 If non-NULL, storage for the 4th reply argument.
1163 * @param r5 If non-NULL, storage for the 5th reply argument.
1164 *
1165 * @return Return code of the reply or a negative error code.
1166 *
[0cc4313]1167 */
[96b02eb9]1168sysarg_t async_req_fast(int phoneid, sysarg_t method, sysarg_t arg1,
1169 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2,
1170 sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
[085bd54]1171{
[0cc4313]1172 ipc_call_t result;
1173 aid_t eid = async_send_4(phoneid, method, arg1, arg2, arg3, arg4,
1174 &result);
[c07544d3]1175
[96b02eb9]1176 sysarg_t rc;
[0cc4313]1177 async_wait_for(eid, &rc);
[c07544d3]1178
1179 if (r1)
[0cc4313]1180 *r1 = IPC_GET_ARG1(result);
[c07544d3]1181
[0cc4313]1182 if (r2)
1183 *r2 = IPC_GET_ARG2(result);
[c07544d3]1184
[0cc4313]1185 if (r3)
1186 *r3 = IPC_GET_ARG3(result);
[c07544d3]1187
[0cc4313]1188 if (r4)
1189 *r4 = IPC_GET_ARG4(result);
[c07544d3]1190
[0cc4313]1191 if (r5)
1192 *r5 = IPC_GET_ARG5(result);
[c07544d3]1193
[0cc4313]1194 return rc;
[085bd54]1195}
1196
[0cc4313]1197/** Pseudo-synchronous message sending - slow version.
1198 *
1199 * Send message asynchronously and return only after the reply arrives.
1200 *
[c07544d3]1201 * @param phoneid Hash of the phone through which to make the call.
1202 * @param method Method of the call.
1203 * @param arg1 Service-defined payload argument.
1204 * @param arg2 Service-defined payload argument.
1205 * @param arg3 Service-defined payload argument.
1206 * @param arg4 Service-defined payload argument.
1207 * @param arg5 Service-defined payload argument.
1208 * @param r1 If non-NULL, storage for the 1st reply argument.
1209 * @param r2 If non-NULL, storage for the 2nd reply argument.
1210 * @param r3 If non-NULL, storage for the 3rd reply argument.
1211 * @param r4 If non-NULL, storage for the 4th reply argument.
1212 * @param r5 If non-NULL, storage for the 5th reply argument.
1213 *
1214 * @return Return code of the reply or a negative error code.
1215 *
[0cc4313]1216 */
[96b02eb9]1217sysarg_t async_req_slow(int phoneid, sysarg_t method, sysarg_t arg1,
1218 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1,
1219 sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
[085bd54]1220{
[0cc4313]1221 ipc_call_t result;
1222 aid_t eid = async_send_5(phoneid, method, arg1, arg2, arg3, arg4, arg5,
1223 &result);
[c07544d3]1224
[96b02eb9]1225 sysarg_t rc;
[0cc4313]1226 async_wait_for(eid, &rc);
[c07544d3]1227
1228 if (r1)
[0cc4313]1229 *r1 = IPC_GET_ARG1(result);
[c07544d3]1230
[0cc4313]1231 if (r2)
1232 *r2 = IPC_GET_ARG2(result);
[c07544d3]1233
[0cc4313]1234 if (r3)
1235 *r3 = IPC_GET_ARG3(result);
[c07544d3]1236
[0cc4313]1237 if (r4)
1238 *r4 = IPC_GET_ARG4(result);
[c07544d3]1239
[0cc4313]1240 if (r5)
1241 *r5 = IPC_GET_ARG5(result);
[c07544d3]1242
[0cc4313]1243 return rc;
[085bd54]1244}
[b2951e2]1245
[64d2b10]1246void async_msg_0(int phone, sysarg_t imethod)
1247{
1248 ipc_call_async_0(phone, imethod, NULL, NULL, true);
1249}
1250
1251void async_msg_1(int phone, sysarg_t imethod, sysarg_t arg1)
1252{
1253 ipc_call_async_1(phone, imethod, arg1, NULL, NULL, true);
1254}
1255
1256void async_msg_2(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2)
1257{
1258 ipc_call_async_2(phone, imethod, arg1, arg2, NULL, NULL, true);
1259}
1260
1261void async_msg_3(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
1262 sysarg_t arg3)
1263{
1264 ipc_call_async_3(phone, imethod, arg1, arg2, arg3, NULL, NULL, true);
1265}
1266
1267void async_msg_4(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
1268 sysarg_t arg3, sysarg_t arg4)
1269{
1270 ipc_call_async_4(phone, imethod, arg1, arg2, arg3, arg4, NULL, NULL,
1271 true);
1272}
1273
1274void async_msg_5(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
1275 sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
1276{
1277 ipc_call_async_5(phone, imethod, arg1, arg2, arg3, arg4, arg5, NULL,
1278 NULL, true);
1279}
1280
1281sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval)
1282{
1283 return ipc_answer_0(callid, retval);
1284}
1285
1286sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)
1287{
1288 return ipc_answer_1(callid, retval, arg1);
1289}
1290
1291sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
1292 sysarg_t arg2)
1293{
1294 return ipc_answer_2(callid, retval, arg1, arg2);
1295}
1296
1297sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
1298 sysarg_t arg2, sysarg_t arg3)
1299{
1300 return ipc_answer_3(callid, retval, arg1, arg2, arg3);
1301}
1302
1303sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
1304 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
1305{
1306 return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4);
1307}
1308
1309sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
1310 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
1311{
1312 return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5);
1313}
1314
[47b7006]1315int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
1316 sysarg_t arg1, sysarg_t arg2, unsigned int mode)
[64d2b10]1317{
1318 return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
1319}
1320
[47b7006]1321int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
[64d2b10]1322 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
[47b7006]1323 unsigned int mode)
[64d2b10]1324{
1325 return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
1326 arg5, mode);
1327}
1328
[007e6efa]1329/** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework.
1330 *
1331 * Ask through phone for a new connection to some service.
1332 *
1333 * @param phone Phone handle used for contacting the other side.
1334 * @param arg1 User defined argument.
1335 * @param arg2 User defined argument.
1336 * @param arg3 User defined argument.
1337 * @param client_receiver Connection handing routine.
1338 *
1339 * @return New phone handle on success or a negative error code.
1340 *
1341 */
1342int async_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2,
1343 sysarg_t arg3, async_client_conn_t client_receiver)
1344{
1345 sysarg_t task_hash;
1346 sysarg_t phone_hash;
1347 int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
1348 NULL, NULL, NULL, &task_hash, &phone_hash);
1349 if (rc != EOK)
1350 return rc;
1351
1352 if (client_receiver != NULL)
1353 async_new_connection(task_hash, phone_hash, 0, NULL,
1354 client_receiver);
1355
1356 return EOK;
1357}
1358
[f74392f]1359/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
[007e6efa]1360 *
[f74392f]1361 * Ask through phone for a new connection to some service.
1362 *
[007e6efa]1363 * @param phone Phone handle used for contacting the other side.
1364 * @param arg1 User defined argument.
1365 * @param arg2 User defined argument.
1366 * @param arg3 User defined argument.
1367 *
1368 * @return New phone handle on success or a negative error code.
[f74392f]1369 *
1370 */
[007e6efa]1371int async_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2,
1372 sysarg_t arg3)
[f74392f]1373{
[96b02eb9]1374 sysarg_t newphid;
[007e6efa]1375 int rc = async_req_3_5(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
1376 NULL, NULL, NULL, NULL, &newphid);
[f74392f]1377
[007e6efa]1378 if (rc != EOK)
[f74392f]1379 return rc;
[007e6efa]1380
[f74392f]1381 return newphid;
1382}
1383
1384/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
[007e6efa]1385 *
[f74392f]1386 * Ask through phone for a new connection to some service and block until
1387 * success.
1388 *
[007e6efa]1389 * @param phoneid Phone handle used for contacting the other side.
1390 * @param arg1 User defined argument.
1391 * @param arg2 User defined argument.
1392 * @param arg3 User defined argument.
1393 *
1394 * @return New phone handle on success or a negative error code.
[f74392f]1395 *
1396 */
[007e6efa]1397int async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
[96b02eb9]1398 sysarg_t arg3)
[f74392f]1399{
[96b02eb9]1400 sysarg_t newphid;
[007e6efa]1401 int rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
[f74392f]1402 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
1403
[007e6efa]1404 if (rc != EOK)
[f74392f]1405 return rc;
[007e6efa]1406
[f74392f]1407 return newphid;
1408}
1409
[64d2b10]1410/** Connect to a task specified by id.
1411 *
1412 */
1413int async_connect_kbox(task_id_t id)
1414{
1415 return ipc_connect_kbox(id);
1416}
1417
1418/** Wrapper for ipc_hangup.
1419 *
1420 * @param phone Phone handle to hung up.
1421 *
1422 * @return Zero on success or a negative error code.
1423 *
1424 */
1425int async_hangup(int phone)
1426{
1427 return ipc_hangup(phone);
1428}
1429
1430/** Interrupt one thread of this task from waiting for IPC. */
1431void async_poke(void)
1432{
1433 ipc_poke();
1434}
1435
[47b7006]1436/** Wrapper for IPC_M_SHARE_IN calls using the async framework.
1437 *
1438 * @param phoneid Phone that will be used to contact the receiving side.
1439 * @param dst Destination address space area base.
1440 * @param size Size of the destination address space area.
1441 * @param arg User defined argument.
1442 * @param flags Storage for the received flags. Can be NULL.
[0da4e41]1443 *
[47b7006]1444 * @return Zero on success or a negative error code from errno.h.
[0da4e41]1445 *
1446 */
[96b02eb9]1447int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
[47b7006]1448 unsigned int *flags)
[0da4e41]1449{
1450 sysarg_t tmp_flags;
[47b7006]1451 int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
[96b02eb9]1452 (sysarg_t) size, arg, NULL, &tmp_flags);
[47b7006]1453
[0da4e41]1454 if (flags)
[47b7006]1455 *flags = (unsigned int) tmp_flags;
1456
[0da4e41]1457 return res;
1458}
1459
1460/** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
1461 *
[47b7006]1462 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN
1463 * calls so that the user doesn't have to remember the meaning of each IPC
1464 * argument.
[0da4e41]1465 *
1466 * So far, this wrapper is to be used from within a connection fibril.
1467 *
[47b7006]1468 * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
1469 * @param size Destination address space area size.
1470 *
1471 * @return True on success, false on failure.
[0da4e41]1472 *
1473 */
[47b7006]1474bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
[0da4e41]1475{
1476 assert(callid);
1477 assert(size);
[47b7006]1478
1479 ipc_call_t data;
[0da4e41]1480 *callid = async_get_call(&data);
[47b7006]1481
[228e490]1482 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
[47b7006]1483 return false;
1484
[0da4e41]1485 *size = (size_t) IPC_GET_ARG2(data);
[47b7006]1486 return true;
[0da4e41]1487}
1488
1489/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
1490 *
[47b7006]1491 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
1492 * calls so that the user doesn't have to remember the meaning of each IPC
1493 * argument.
[0da4e41]1494 *
[47b7006]1495 * @param callid Hash of the IPC_M_DATA_READ call to answer.
1496 * @param src Source address space base.
1497 * @param flags Flags to be used for sharing. Bits can be only cleared.
1498 *
1499 * @return Zero on success or a value from @ref errno.h on failure.
[0da4e41]1500 *
1501 */
[47b7006]1502int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
[0da4e41]1503{
1504 return ipc_share_in_finalize(callid, src, flags);
1505}
1506
[47b7006]1507/** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
[0da4e41]1508 *
[47b7006]1509 * @param phoneid Phone that will be used to contact the receiving side.
1510 * @param src Source address space area base address.
1511 * @param flags Flags to be used for sharing. Bits can be only cleared.
1512 *
1513 * @return Zero on success or a negative error code from errno.h.
[0da4e41]1514 *
1515 */
[47b7006]1516int async_share_out_start(int phoneid, void *src, unsigned int flags)
[0da4e41]1517{
[96b02eb9]1518 return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
1519 (sysarg_t) flags);
[0da4e41]1520}
1521
1522/** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
1523 *
[47b7006]1524 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT
1525 * calls so that the user doesn't have to remember the meaning of each IPC
1526 * argument.
[0da4e41]1527 *
1528 * So far, this wrapper is to be used from within a connection fibril.
1529 *
[47b7006]1530 * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
1531 * @param size Storage for the source address space area size.
1532 * @param flags Storage for the sharing flags.
1533 *
1534 * @return True on success, false on failure.
[0da4e41]1535 *
1536 */
[47b7006]1537bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
[0da4e41]1538{
1539 assert(callid);
1540 assert(size);
1541 assert(flags);
[47b7006]1542
1543 ipc_call_t data;
[0da4e41]1544 *callid = async_get_call(&data);
[47b7006]1545
[228e490]1546 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
[47b7006]1547 return false;
1548
[0da4e41]1549 *size = (size_t) IPC_GET_ARG2(data);
[47b7006]1550 *flags = (unsigned int) IPC_GET_ARG3(data);
1551 return true;
[0da4e41]1552}
1553
1554/** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
1555 *
[47b7006]1556 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
1557 * calls so that the user doesn't have to remember the meaning of each IPC
1558 * argument.
[0da4e41]1559 *
[47b7006]1560 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
1561 * @param dst Destination address space area base address.
1562 *
1563 * @return Zero on success or a value from @ref errno.h on failure.
[0da4e41]1564 *
1565 */
1566int async_share_out_finalize(ipc_callid_t callid, void *dst)
1567{
1568 return ipc_share_out_finalize(callid, dst);
1569}
1570
[47b7006]1571/** Wrapper for IPC_M_DATA_READ calls using the async framework.
[0da4e41]1572 *
[47b7006]1573 * @param phoneid Phone that will be used to contact the receiving side.
1574 * @param dst Address of the beginning of the destination buffer.
1575 * @param size Size of the destination buffer.
[f6bffee]1576 * @param flags Flags to control the data transfer.
[47b7006]1577 *
1578 * @return Zero on success or a negative error code from errno.h.
[0da4e41]1579 *
1580 */
[f6bffee]1581int
[8e80d3f]1582async_data_read_start_generic(int phoneid, void *dst, size_t size, int flags)
[0da4e41]1583{
[f6bffee]1584 return async_req_3_0(phoneid, IPC_M_DATA_READ, (sysarg_t) dst,
1585 (sysarg_t) size, (sysarg_t) flags);
[0da4e41]1586}
1587
1588/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
1589 *
[47b7006]1590 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
1591 * calls so that the user doesn't have to remember the meaning of each IPC
1592 * argument.
[0da4e41]1593 *
1594 * So far, this wrapper is to be used from within a connection fibril.
1595 *
[47b7006]1596 * @param callid Storage for the hash of the IPC_M_DATA_READ.
1597 * @param size Storage for the maximum size. Can be NULL.
1598 *
1599 * @return True on success, false on failure.
[0da4e41]1600 *
1601 */
[47b7006]1602bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
[0da4e41]1603{
1604 assert(callid);
[47b7006]1605
1606 ipc_call_t data;
[0da4e41]1607 *callid = async_get_call(&data);
[47b7006]1608
[228e490]1609 if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
[47b7006]1610 return false;
1611
[0da4e41]1612 if (size)
1613 *size = (size_t) IPC_GET_ARG2(data);
[47b7006]1614
1615 return true;
[0da4e41]1616}
1617
1618/** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
1619 *
[47b7006]1620 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
1621 * calls so that the user doesn't have to remember the meaning of each IPC
1622 * argument.
[0da4e41]1623 *
[47b7006]1624 * @param callid Hash of the IPC_M_DATA_READ call to answer.
1625 * @param src Source address for the IPC_M_DATA_READ call.
1626 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than
1627 * the maximum size announced by the sender.
1628 *
1629 * @return Zero on success or a value from @ref errno.h on failure.
[0da4e41]1630 *
1631 */
1632int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
1633{
1634 return ipc_data_read_finalize(callid, src, size);
1635}
1636
[b4cbef1]1637/** Wrapper for forwarding any read request
1638 *
1639 */
[96b02eb9]1640int async_data_read_forward_fast(int phoneid, sysarg_t method, sysarg_t arg1,
1641 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
[b4cbef1]1642{
1643 ipc_callid_t callid;
1644 if (!async_data_read_receive(&callid, NULL)) {
1645 ipc_answer_0(callid, EINVAL);
1646 return EINVAL;
1647 }
1648
1649 aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
1650 dataptr);
1651 if (msg == 0) {
1652 ipc_answer_0(callid, EINVAL);
1653 return EINVAL;
1654 }
1655
1656 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
1657 IPC_FF_ROUTE_FROM_ME);
1658 if (retval != EOK) {
[a281fc82]1659 async_wait_for(msg, NULL);
[b4cbef1]1660 ipc_answer_0(callid, retval);
1661 return retval;
1662 }
1663
[96b02eb9]1664 sysarg_t rc;
[b4cbef1]1665 async_wait_for(msg, &rc);
1666
1667 return (int) rc;
1668}
1669
[47b7006]1670/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
[0da4e41]1671 *
[b4cbef1]1672 * @param phoneid Phone that will be used to contact the receiving side.
1673 * @param src Address of the beginning of the source buffer.
1674 * @param size Size of the source buffer.
[f6bffee]1675 * @param flags Flags to control the data transfer.
[b4cbef1]1676 *
1677 * @return Zero on success or a negative error code from errno.h.
[0da4e41]1678 *
1679 */
[f6bffee]1680int
[8e80d3f]1681async_data_write_start_generic(int phoneid, const void *src, size_t size,
[f6bffee]1682 int flags)
[0da4e41]1683{
[f6bffee]1684 return async_req_3_0(phoneid, IPC_M_DATA_WRITE, (sysarg_t) src,
1685 (sysarg_t) size, (sysarg_t) flags);
[0da4e41]1686}
1687
1688/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
1689 *
[47b7006]1690 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
1691 * calls so that the user doesn't have to remember the meaning of each IPC
1692 * argument.
[0da4e41]1693 *
1694 * So far, this wrapper is to be used from within a connection fibril.
1695 *
[47b7006]1696 * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
1697 * @param size Storage for the suggested size. May be NULL.
[b4cbef1]1698 *
[47b7006]1699 * @return True on success, false on failure.
[0da4e41]1700 *
1701 */
[47b7006]1702bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
[0da4e41]1703{
1704 assert(callid);
[b4cbef1]1705
[47b7006]1706 ipc_call_t data;
[0da4e41]1707 *callid = async_get_call(&data);
[47b7006]1708
[228e490]1709 if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
[47b7006]1710 return false;
[b4cbef1]1711
[0da4e41]1712 if (size)
1713 *size = (size_t) IPC_GET_ARG2(data);
[b4cbef1]1714
[47b7006]1715 return true;
[0da4e41]1716}
1717
1718/** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
1719 *
[47b7006]1720 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
1721 * calls so that the user doesn't have to remember the meaning of each IPC
1722 * argument.
[0da4e41]1723 *
[b4cbef1]1724 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
1725 * @param dst Final destination address for the IPC_M_DATA_WRITE call.
1726 * @param size Final size for the IPC_M_DATA_WRITE call.
1727 *
1728 * @return Zero on success or a value from @ref errno.h on failure.
[0da4e41]1729 *
1730 */
1731int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
1732{
1733 return ipc_data_write_finalize(callid, dst, size);
1734}
1735
[eda925a]1736/** Wrapper for receiving binary data or strings
[8aa42e3]1737 *
1738 * This wrapper only makes it more comfortable to use async_data_write_*
[eda925a]1739 * functions to receive binary data or strings.
[8aa42e3]1740 *
[472c09d]1741 * @param data Pointer to data pointer (which should be later disposed
1742 * by free()). If the operation fails, the pointer is not
1743 * touched.
[eda925a]1744 * @param nullterm If true then the received data is always zero terminated.
1745 * This also causes to allocate one extra byte beyond the
1746 * raw transmitted data.
[b4cbef1]1747 * @param min_size Minimum size (in bytes) of the data to receive.
[472c09d]1748 * @param max_size Maximum size (in bytes) of the data to receive. 0 means
1749 * no limit.
[eda925a]1750 * @param granulariy If non-zero then the size of the received data has to
[472c09d]1751 * be divisible by this value.
1752 * @param received If not NULL, the size of the received data is stored here.
[8aa42e3]1753 *
1754 * @return Zero on success or a value from @ref errno.h on failure.
1755 *
1756 */
[eda925a]1757int async_data_write_accept(void **data, const bool nullterm,
1758 const size_t min_size, const size_t max_size, const size_t granularity,
1759 size_t *received)
[8aa42e3]1760{
1761 ipc_callid_t callid;
1762 size_t size;
1763 if (!async_data_write_receive(&callid, &size)) {
1764 ipc_answer_0(callid, EINVAL);
1765 return EINVAL;
1766 }
1767
[b4cbef1]1768 if (size < min_size) {
1769 ipc_answer_0(callid, EINVAL);
1770 return EINVAL;
1771 }
1772
[8aa42e3]1773 if ((max_size > 0) && (size > max_size)) {
1774 ipc_answer_0(callid, EINVAL);
1775 return EINVAL;
1776 }
1777
[472c09d]1778 if ((granularity > 0) && ((size % granularity) != 0)) {
1779 ipc_answer_0(callid, EINVAL);
1780 return EINVAL;
1781 }
1782
[eda925a]1783 void *_data;
1784
1785 if (nullterm)
1786 _data = malloc(size + 1);
1787 else
1788 _data = malloc(size);
1789
[472c09d]1790 if (_data == NULL) {
[8aa42e3]1791 ipc_answer_0(callid, ENOMEM);
1792 return ENOMEM;
1793 }
1794
[472c09d]1795 int rc = async_data_write_finalize(callid, _data, size);
[8aa42e3]1796 if (rc != EOK) {
[472c09d]1797 free(_data);
[8aa42e3]1798 return rc;
1799 }
1800
[eda925a]1801 if (nullterm)
1802 ((char *) _data)[size] = 0;
[8aa42e3]1803
[eda925a]1804 *data = _data;
[472c09d]1805 if (received != NULL)
1806 *received = size;
1807
[8aa42e3]1808 return EOK;
1809}
1810
[b4cbef1]1811/** Wrapper for voiding any data that is about to be received
1812 *
1813 * This wrapper can be used to void any pending data
1814 *
1815 * @param retval Error value from @ref errno.h to be returned to the caller.
1816 *
1817 */
[47b7006]1818void async_data_write_void(sysarg_t retval)
[b4cbef1]1819{
1820 ipc_callid_t callid;
1821 async_data_write_receive(&callid, NULL);
1822 ipc_answer_0(callid, retval);
1823}
1824
1825/** Wrapper for forwarding any data that is about to be received
1826 *
1827 */
[96b02eb9]1828int async_data_write_forward_fast(int phoneid, sysarg_t method, sysarg_t arg1,
1829 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
[b4cbef1]1830{
1831 ipc_callid_t callid;
1832 if (!async_data_write_receive(&callid, NULL)) {
1833 ipc_answer_0(callid, EINVAL);
1834 return EINVAL;
1835 }
1836
1837 aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
1838 dataptr);
1839 if (msg == 0) {
1840 ipc_answer_0(callid, EINVAL);
1841 return EINVAL;
1842 }
1843
1844 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
1845 IPC_FF_ROUTE_FROM_ME);
1846 if (retval != EOK) {
[a281fc82]1847 async_wait_for(msg, NULL);
[b4cbef1]1848 ipc_answer_0(callid, retval);
1849 return retval;
1850 }
1851
[96b02eb9]1852 sysarg_t rc;
[b4cbef1]1853 async_wait_for(msg, &rc);
1854
1855 return (int) rc;
1856}
1857
[a46da63]1858/** @}
[b2951e2]1859 */
Note: See TracBrowser for help on using the repository browser.