source: mainline/uspace/lib/c/generic/async.c@ b366a1bc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b366a1bc was 9c31643, checked in by Jakub Jermar <jakub@…>, 14 years ago

Do not free the connection_t when it is still in use.

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