source: mainline/uspace/lib/c/generic/async/client.c@ b55f62a

Last change on this file since b55f62a was 012dd8e, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

taskman: Handle INIT_TASKS as tasks spawned by loader

  • everyone is connected to its spawner, except for INIT_TASKS, they are connected to taskman (first binary)
  • taskman is now aware even of INIT_TASKS and taskman itself
  • refactored taskman handshake — NS session is created lazily
  • refactored async.c with usage of create_session
  • changed EINVAL to EINTR on lost waits
  • removed TODOs from taskman and related libc TODOs

Conflicts:

abi/include/abi/ipc/methods.h
boot/Makefile.common
uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/loader.c
uspace/lib/c/generic/ns.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/generic/private/taskman.h
uspace/lib/c/generic/task.c
uspace/lib/c/include/async.h
uspace/lib/c/include/task.h
uspace/srv/loader/main.c
uspace/srv/ns/ns.c

  • Property mode set to 100644
File size: 36.1 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
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.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35/**
36 * Asynchronous library
37 *
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.
41 *
42 * You should be able to write very simple multithreaded programs. The async
43 * framework will automatically take care of most of the synchronization
44 * problems.
45 *
46 * Example of use (pseudo C):
47 *
48 * 1) Multithreaded client application
49 *
50 * fibril_create(fibril1, ...);
51 * fibril_create(fibril2, ...);
52 * ...
53 *
54 * int fibril1(void *arg)
55 * {
56 * conn = async_connect_me_to(...);
57 *
58 * exch = async_exchange_begin(conn);
59 * c1 = async_send(exch);
60 * async_exchange_end(exch);
61 *
62 * exch = async_exchange_begin(conn);
63 * c2 = async_send(exch);
64 * async_exchange_end(exch);
65 *
66 * async_wait_for(c1);
67 * async_wait_for(c2);
68 * ...
69 * }
70 *
71 *
72 * 2) Multithreaded server application
73 *
74 * main()
75 * {
76 * async_manager();
77 * }
78 *
79 * port_handler(ichandle, *icall)
80 * {
81 * if (want_refuse) {
82 * async_answer_0(ichandle, ELIMIT);
83 * return;
84 * }
85 * async_answer_0(ichandle, EOK);
86 *
87 * chandle = async_get_call(&call);
88 * somehow_handle_the_call(chandle, call);
89 * async_answer_2(chandle, 1, 2, 3);
90 *
91 * chandle = async_get_call(&call);
92 * ...
93 * }
94 *
95 */
96
97#define _LIBC_ASYNC_C_
98#include <ipc/ipc.h>
99#include <async.h>
100#include "../private/async.h"
101#include "../private/ns.h"
102#undef _LIBC_ASYNC_C_
103
104#include <ipc/irq.h>
105#include <ipc/event.h>
106#include <fibril.h>
107#include <adt/hash_table.h>
108#include <adt/hash.h>
109#include <adt/list.h>
110#include <assert.h>
111#include <errno.h>
112#include <time.h>
113#include <barrier.h>
114#include <stdbool.h>
115#include <stdlib.h>
116#include <mem.h>
117#include <stdlib.h>
118#include <macros.h>
119#include <as.h>
120#include <abi/mm/as.h>
121#include "../private/libc.h"
122#include "../private/fibril.h"
123
124static fibril_rmutex_t message_mutex;
125
126/** Message data */
127typedef struct {
128 fibril_event_t received;
129
130 /** If reply was received. */
131 bool done;
132
133 /** If the message / reply should be discarded on arrival. */
134 bool forget;
135
136 /** Pointer to where the answer data is stored. */
137 ipc_call_t *dataptr;
138
139 errno_t retval;
140} amsg_t;
141
142static amsg_t *amsg_create(void)
143{
144 return calloc(1, sizeof(amsg_t));
145}
146
147static void amsg_destroy(amsg_t *msg)
148{
149 free(msg);
150}
151
152/** Mutex protecting inactive_exch_list and avail_phone_cv.
153 *
154 */
155static FIBRIL_MUTEX_INITIALIZE(async_sess_mutex);
156
157/** List of all currently inactive exchanges.
158 *
159 */
160static LIST_INITIALIZE(inactive_exch_list);
161
162/** Condition variable to wait for a phone to become available.
163 *
164 */
165static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv);
166
167
168/** Create session for existing phone
169 *
170 * @return session on success, NULL on error
171 */
172
173async_sess_t *create_session(cap_phone_handle_t phone, exch_mgmt_t mgmt,
174 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
175{
176 async_sess_t *session = (async_sess_t *) malloc(sizeof(async_sess_t));
177
178 if (session != NULL) {
179 session->iface = 0;
180 session->mgmt = mgmt;
181 session->phone = phone;
182 session->arg1 = arg1;
183 session->arg2 = arg2;
184 session->arg3 = arg3;
185
186 fibril_mutex_initialize(&session->remote_state_mtx);
187 session->remote_state_data = NULL;
188
189 list_initialize(&session->exch_list);
190 fibril_mutex_initialize(&session->mutex);
191 atomic_set(&session->refcnt, 0);
192 &session.exchanges = 0;
193 } else {
194 errno = ENOMEM;
195 }
196
197 return session;
198}
199
200
201/** Initialize the async framework.
202 *
203 */
204void __async_client_init(void)
205{
206 if (fibril_rmutex_initialize(&message_mutex) != EOK)
207 abort();
208}
209
210void __async_client_fini(void)
211{
212 fibril_rmutex_destroy(&message_mutex);
213}
214
215/** Reply received callback.
216 *
217 * This function is called whenever a reply for an asynchronous message sent out
218 * by the asynchronous framework is received.
219 *
220 * Notify the fibril which is waiting for this message that it has arrived.
221 *
222 * @param arg Pointer to the asynchronous message record.
223 * @param retval Value returned in the answer.
224 * @param data Call data of the answer.
225 *
226 */
227void async_reply_received(ipc_call_t *data)
228{
229 amsg_t *msg = (amsg_t *) data->answer_label;
230 if (!msg)
231 return;
232
233 fibril_rmutex_lock(&message_mutex);
234
235 msg->retval = ipc_get_retval(data);
236
237 /* Copy data inside lock, just in case the call was detached */
238 if ((msg->dataptr) && (data))
239 *msg->dataptr = *data;
240
241 msg->done = true;
242
243 if (msg->forget) {
244 amsg_destroy(msg);
245 } else {
246 fibril_notify(&msg->received);
247 }
248
249 fibril_rmutex_unlock(&message_mutex);
250}
251
252/** Send message and return id of the sent message.
253 *
254 * The return value can be used as input for async_wait() to wait for
255 * completion.
256 *
257 * @param exch Exchange for sending the message.
258 * @param imethod Service-defined interface and method.
259 * @param arg1 Service-defined payload argument.
260 * @param arg2 Service-defined payload argument.
261 * @param arg3 Service-defined payload argument.
262 * @param arg4 Service-defined payload argument.
263 * @param dataptr If non-NULL, storage where the reply data will be stored.
264 *
265 * @return Hash of the sent message or 0 on error.
266 *
267 */
268static aid_t async_send_fast(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
269 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
270{
271 if (exch == NULL)
272 return 0;
273
274 amsg_t *msg = amsg_create();
275 if (msg == NULL)
276 return 0;
277
278 msg->dataptr = dataptr;
279
280 errno_t rc = ipc_call_async_4(exch->phone, imethod, arg1, arg2, arg3,
281 arg4, msg);
282 if (rc != EOK) {
283 msg->retval = rc;
284 msg->done = true;
285 }
286
287 return (aid_t) msg;
288}
289
290/** Send message and return id of the sent message
291 *
292 * The return value can be used as input for async_wait() to wait for
293 * completion.
294 *
295 * @param exch Exchange for sending the message.
296 * @param imethod Service-defined interface and method.
297 * @param arg1 Service-defined payload argument.
298 * @param arg2 Service-defined payload argument.
299 * @param arg3 Service-defined payload argument.
300 * @param arg4 Service-defined payload argument.
301 * @param arg5 Service-defined payload argument.
302 * @param dataptr If non-NULL, storage where the reply data will be
303 * stored.
304 *
305 * @return Hash of the sent message or 0 on error.
306 *
307 */
308static aid_t async_send_slow(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
309 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
310 ipc_call_t *dataptr)
311{
312 if (exch == NULL)
313 return 0;
314
315 amsg_t *msg = amsg_create();
316 if (msg == NULL)
317 return 0;
318
319 msg->dataptr = dataptr;
320
321 errno_t rc = ipc_call_async_5(exch->phone, imethod, arg1, arg2, arg3,
322 arg4, arg5, msg);
323 if (rc != EOK) {
324 msg->retval = rc;
325 msg->done = true;
326 }
327
328 return (aid_t) msg;
329}
330
331aid_t async_send_0(async_exch_t *exch, sysarg_t imethod, ipc_call_t *dataptr)
332{
333 return async_send_fast(exch, imethod, 0, 0, 0, 0, dataptr);
334}
335
336aid_t async_send_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
337 ipc_call_t *dataptr)
338{
339 return async_send_fast(exch, imethod, arg1, 0, 0, 0, dataptr);
340}
341
342aid_t async_send_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
343 sysarg_t arg2, ipc_call_t *dataptr)
344{
345 return async_send_fast(exch, imethod, arg1, arg2, 0, 0, dataptr);
346}
347
348aid_t async_send_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
349 sysarg_t arg2, sysarg_t arg3, ipc_call_t *dataptr)
350{
351 return async_send_fast(exch, imethod, arg1, arg2, arg3, 0, dataptr);
352}
353
354aid_t async_send_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
355 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
356{
357 return async_send_fast(exch, imethod, arg1, arg2, arg3, arg4, dataptr);
358}
359
360aid_t async_send_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
361 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
362 ipc_call_t *dataptr)
363{
364 return async_send_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5,
365 dataptr);
366}
367
368/** Wait for a message sent by the async framework.
369 *
370 * @param amsgid Hash of the message to wait for.
371 * @param retval Pointer to storage where the retval of the answer will
372 * be stored.
373 *
374 */
375void async_wait_for(aid_t amsgid, errno_t *retval)
376{
377 if (amsgid == 0) {
378 if (retval)
379 *retval = ENOMEM;
380 return;
381 }
382
383 amsg_t *msg = (amsg_t *) amsgid;
384 fibril_wait_for(&msg->received);
385
386 if (retval)
387 *retval = msg->retval;
388
389 amsg_destroy(msg);
390}
391
392/** Wait for a message sent by the async framework, timeout variant.
393 *
394 * If the wait times out, the caller may choose to either wait again by calling
395 * async_wait_for() or async_wait_timeout(), or forget the message via
396 * async_forget().
397 *
398 * @param amsgid Hash of the message to wait for.
399 * @param retval Pointer to storage where the retval of the answer will
400 * be stored.
401 * @param timeout Timeout in microseconds.
402 *
403 * @return Zero on success, ETIMEOUT if the timeout has expired.
404 *
405 */
406errno_t async_wait_timeout(aid_t amsgid, errno_t *retval, usec_t timeout)
407{
408 if (amsgid == 0) {
409 if (retval)
410 *retval = ENOMEM;
411 return EOK;
412 }
413
414 amsg_t *msg = (amsg_t *) amsgid;
415
416 /*
417 * Negative timeout is converted to zero timeout to avoid
418 * using tv_add with negative augmenter.
419 */
420 if (timeout < 0)
421 timeout = 0;
422
423 struct timespec expires;
424 getuptime(&expires);
425 ts_add_diff(&expires, USEC2NSEC(timeout));
426
427 errno_t rc = fibril_wait_timeout(&msg->received, &expires);
428 if (rc != EOK)
429 return rc;
430
431 if (retval)
432 *retval = msg->retval;
433
434 amsg_destroy(msg);
435
436 return EOK;
437}
438
439/** Discard the message / reply on arrival.
440 *
441 * The message will be marked to be discarded once the reply arrives in
442 * reply_received(). It is not allowed to call async_wait_for() or
443 * async_wait_timeout() on this message after a call to this function.
444 *
445 * @param amsgid Hash of the message to forget.
446 */
447void async_forget(aid_t amsgid)
448{
449 if (amsgid == 0)
450 return;
451
452 amsg_t *msg = (amsg_t *) amsgid;
453
454 assert(!msg->forget);
455
456 fibril_rmutex_lock(&message_mutex);
457
458 if (msg->done) {
459 amsg_destroy(msg);
460 } else {
461 msg->dataptr = NULL;
462 msg->forget = true;
463 }
464
465 fibril_rmutex_unlock(&message_mutex);
466}
467
468/** Pseudo-synchronous message sending - fast version.
469 *
470 * Send message asynchronously and return only after the reply arrives.
471 *
472 * This function can only transfer 4 register payload arguments. For
473 * transferring more arguments, see the slower async_req_slow().
474 *
475 * @param exch Exchange for sending the message.
476 * @param imethod Interface and method of the call.
477 * @param arg1 Service-defined payload argument.
478 * @param arg2 Service-defined payload argument.
479 * @param arg3 Service-defined payload argument.
480 * @param arg4 Service-defined payload argument.
481 * @param r1 If non-NULL, storage for the 1st reply argument.
482 * @param r2 If non-NULL, storage for the 2nd reply argument.
483 * @param r3 If non-NULL, storage for the 3rd reply argument.
484 * @param r4 If non-NULL, storage for the 4th reply argument.
485 * @param r5 If non-NULL, storage for the 5th reply argument.
486 *
487 * @return Return code of the reply or an error code.
488 *
489 */
490static errno_t async_req_fast(async_exch_t *exch, sysarg_t imethod,
491 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4,
492 sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
493{
494 if (exch == NULL)
495 return ENOENT;
496
497 ipc_call_t result;
498 aid_t aid = async_send_4(exch, imethod, arg1, arg2, arg3, arg4,
499 &result);
500
501 errno_t rc;
502 async_wait_for(aid, &rc);
503
504 if (r1)
505 *r1 = ipc_get_arg1(&result);
506
507 if (r2)
508 *r2 = ipc_get_arg2(&result);
509
510 if (r3)
511 *r3 = ipc_get_arg3(&result);
512
513 if (r4)
514 *r4 = ipc_get_arg4(&result);
515
516 if (r5)
517 *r5 = ipc_get_arg5(&result);
518
519 return rc;
520}
521
522/** Pseudo-synchronous message sending - slow version.
523 *
524 * Send message asynchronously and return only after the reply arrives.
525 *
526 * @param exch Exchange for sending the message.
527 * @param imethod Interface and method of the call.
528 * @param arg1 Service-defined payload argument.
529 * @param arg2 Service-defined payload argument.
530 * @param arg3 Service-defined payload argument.
531 * @param arg4 Service-defined payload argument.
532 * @param arg5 Service-defined payload argument.
533 * @param r1 If non-NULL, storage for the 1st reply argument.
534 * @param r2 If non-NULL, storage for the 2nd reply argument.
535 * @param r3 If non-NULL, storage for the 3rd reply argument.
536 * @param r4 If non-NULL, storage for the 4th reply argument.
537 * @param r5 If non-NULL, storage for the 5th reply argument.
538 *
539 * @return Return code of the reply or an error code.
540 *
541 */
542static errno_t async_req_slow(async_exch_t *exch, sysarg_t imethod,
543 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
544 sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
545{
546 if (exch == NULL)
547 return ENOENT;
548
549 ipc_call_t result;
550 aid_t aid = async_send_5(exch, imethod, arg1, arg2, arg3, arg4, arg5,
551 &result);
552
553 errno_t rc;
554 async_wait_for(aid, &rc);
555
556 if (r1)
557 *r1 = ipc_get_arg1(&result);
558
559 if (r2)
560 *r2 = ipc_get_arg2(&result);
561
562 if (r3)
563 *r3 = ipc_get_arg3(&result);
564
565 if (r4)
566 *r4 = ipc_get_arg4(&result);
567
568 if (r5)
569 *r5 = ipc_get_arg5(&result);
570
571 return rc;
572}
573
574errno_t async_req_0_0(async_exch_t *exch, sysarg_t imethod)
575{
576 return async_req_fast(exch, imethod, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
577}
578
579errno_t async_req_0_1(async_exch_t *exch, sysarg_t imethod, sysarg_t *r1)
580{
581 return async_req_fast(exch, imethod, 0, 0, 0, 0, r1, NULL, NULL, NULL, NULL);
582}
583
584errno_t async_req_0_2(async_exch_t *exch, sysarg_t imethod, sysarg_t *r1, sysarg_t *r2)
585{
586 return async_req_fast(exch, imethod, 0, 0, 0, 0, r1, r2, NULL, NULL, NULL);
587}
588
589errno_t async_req_0_3(async_exch_t *exch, sysarg_t imethod, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3)
590{
591 return async_req_fast(exch, imethod, 0, 0, 0, 0, r1, r2, r3, NULL, NULL);
592}
593
594errno_t async_req_0_4(async_exch_t *exch, sysarg_t imethod, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4)
595{
596 return async_req_fast(exch, imethod, 0, 0, 0, 0, r1, r2, r3, r4, NULL);
597}
598
599errno_t async_req_0_5(async_exch_t *exch, sysarg_t imethod, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
600{
601 return async_req_fast(exch, imethod, 0, 0, 0, 0, r1, r2, r3, r4, r5);
602}
603
604errno_t async_req_1_0(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1)
605{
606 return async_req_fast(exch, imethod, arg1, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
607}
608
609errno_t async_req_1_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t *r1)
610{
611 return async_req_fast(exch, imethod, arg1, 0, 0, 0, r1, NULL, NULL, NULL, NULL);
612}
613
614errno_t async_req_1_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t *r1, sysarg_t *r2)
615{
616 return async_req_fast(exch, imethod, arg1, 0, 0, 0, r1, r2, NULL, NULL, NULL);
617}
618
619errno_t async_req_1_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3)
620{
621 return async_req_fast(exch, imethod, arg1, 0, 0, 0, r1, r2, r3, NULL, NULL);
622}
623
624errno_t async_req_1_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4)
625{
626 return async_req_fast(exch, imethod, arg1, 0, 0, 0, r1, r2, r3, r4, NULL);
627}
628
629errno_t async_req_1_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
630{
631 return async_req_fast(exch, imethod, arg1, 0, 0, 0, r1, r2, r3, r4, r5);
632}
633
634errno_t async_req_2_0(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2)
635{
636 return async_req_fast(exch, imethod, arg1, arg2, 0, 0, NULL, NULL, NULL, NULL, NULL);
637}
638
639errno_t async_req_2_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t *r1)
640{
641 return async_req_fast(exch, imethod, arg1, arg2, 0, 0, r1, NULL, NULL, NULL, NULL);
642}
643
644errno_t async_req_2_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t *r1, sysarg_t *r2)
645{
646 return async_req_fast(exch, imethod, arg1, arg2, 0, 0, r1, r2, NULL, NULL, NULL);
647}
648
649errno_t async_req_2_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3)
650{
651 return async_req_fast(exch, imethod, arg1, arg2, 0, 0, r1, r2, r3, NULL, NULL);
652}
653
654errno_t async_req_2_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4)
655{
656 return async_req_fast(exch, imethod, arg1, arg2, 0, 0, r1, r2, r3, r4, NULL);
657}
658
659errno_t async_req_2_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
660{
661 return async_req_fast(exch, imethod, arg1, arg2, 0, 0, r1, r2, r3, r4, r5);
662}
663
664errno_t async_req_3_0(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
665{
666 return async_req_fast(exch, imethod, arg1, arg2, arg3, 0, NULL, NULL, NULL, NULL, NULL);
667}
668
669errno_t async_req_3_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t *r1)
670{
671 return async_req_fast(exch, imethod, arg1, arg2, arg3, 0, r1, NULL, NULL, NULL, NULL);
672}
673
674errno_t async_req_3_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t *r1, sysarg_t *r2)
675{
676 return async_req_fast(exch, imethod, arg1, arg2, arg3, 0, r1, r2, NULL, NULL, NULL);
677}
678
679errno_t async_req_3_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3)
680{
681 return async_req_fast(exch, imethod, arg1, arg2, arg3, 0, r1, r2, r3, NULL, NULL);
682}
683
684errno_t async_req_3_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4)
685{
686 return async_req_fast(exch, imethod, arg1, arg2, arg3, 0, r1, r2, r3, r4, NULL);
687}
688
689errno_t async_req_3_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
690{
691 return async_req_fast(exch, imethod, arg1, arg2, arg3, 0, r1, r2, r3, r4, r5);
692}
693
694errno_t async_req_4_0(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
695{
696 return async_req_fast(exch, imethod, arg1, arg2, arg3, arg4, NULL, NULL, NULL, NULL, NULL);
697}
698
699errno_t async_req_4_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1)
700{
701 return async_req_fast(exch, imethod, arg1, arg2, arg3, arg4, r1, NULL, NULL, NULL, NULL);
702}
703
704errno_t async_req_4_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2)
705{
706 return async_req_fast(exch, imethod, arg1, arg2, arg3, arg4, r1, r2, NULL, NULL, NULL);
707}
708
709errno_t async_req_4_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3)
710{
711 return async_req_fast(exch, imethod, arg1, arg2, arg3, arg4, r1, r2, r3, NULL, NULL);
712}
713
714errno_t async_req_4_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4)
715{
716 return async_req_fast(exch, imethod, arg1, arg2, arg3, arg4, r1, r2, r3, r4, NULL);
717}
718
719errno_t async_req_4_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
720{
721 return async_req_fast(exch, imethod, arg1, arg2, arg3, arg4, r1, r2, r3, r4, r5);
722}
723
724errno_t async_req_5_0(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
725{
726 return async_req_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5, NULL, NULL, NULL, NULL, NULL);
727}
728
729errno_t async_req_5_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1)
730{
731 return async_req_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5, r1, NULL, NULL, NULL, NULL);
732}
733
734errno_t async_req_5_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1, sysarg_t *r2)
735{
736 return async_req_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5, r1, r2, NULL, NULL, NULL);
737}
738
739errno_t async_req_5_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3)
740{
741 return async_req_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5, r1, r2, r3, NULL, NULL);
742}
743
744errno_t async_req_5_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4)
745{
746 return async_req_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5, r1, r2, r3, r4, NULL);
747}
748
749errno_t async_req_5_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1, sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
750{
751 return async_req_slow(exch, imethod, arg1, arg2, arg3, arg4, arg5, r1, r2, r3, r4, r5);
752}
753
754void async_msg_0(async_exch_t *exch, sysarg_t imethod)
755{
756 if (exch != NULL)
757 ipc_call_async_0(exch->phone, imethod, NULL);
758}
759
760void async_msg_1(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1)
761{
762 if (exch != NULL)
763 ipc_call_async_1(exch->phone, imethod, arg1, NULL);
764}
765
766void async_msg_2(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
767 sysarg_t arg2)
768{
769 if (exch != NULL)
770 ipc_call_async_2(exch->phone, imethod, arg1, arg2, NULL);
771}
772
773void async_msg_3(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
774 sysarg_t arg2, sysarg_t arg3)
775{
776 if (exch != NULL)
777 ipc_call_async_3(exch->phone, imethod, arg1, arg2, arg3, NULL);
778}
779
780void async_msg_4(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
781 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
782{
783 if (exch != NULL)
784 ipc_call_async_4(exch->phone, imethod, arg1, arg2, arg3, arg4,
785 NULL);
786}
787
788void async_msg_5(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
789 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
790{
791 if (exch != NULL)
792 ipc_call_async_5(exch->phone, imethod, arg1, arg2, arg3, arg4,
793 arg5, NULL);
794}
795
796static errno_t async_connect_me_to_internal(cap_phone_handle_t phone,
797 iface_t iface, sysarg_t arg2, sysarg_t arg3, sysarg_t flags,
798 cap_phone_handle_t *out_phone)
799{
800 ipc_call_t result;
801
802 // XXX: Workaround for GCC's inability to infer association between
803 // rc == EOK and *out_phone being assigned.
804 *out_phone = CAP_NIL;
805
806 amsg_t *msg = amsg_create();
807 if (!msg)
808 return ENOENT;
809
810 msg->dataptr = &result;
811
812 errno_t rc = ipc_call_async_4(phone, IPC_M_CONNECT_ME_TO,
813 (sysarg_t) iface, arg2, arg3, flags, msg);
814 if (rc != EOK) {
815 msg->retval = rc;
816 msg->done = true;
817 }
818
819 async_wait_for((aid_t) msg, &rc);
820
821 if (rc != EOK)
822 return rc;
823
824 *out_phone = (cap_phone_handle_t) ipc_get_arg5(&result);
825 return EOK;
826}
827
828/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
829 *
830 * Ask through phone for a new connection to some service and block until
831 * success.
832 *
833 * @param exch Exchange for sending the message.
834 * @param iface Connection interface.
835 * @param arg2 User defined argument.
836 * @param arg3 User defined argument.
837 *
838 * @return New session on success or NULL on error.
839 *
840 */
841async_sess_t *async_connect_me_to(async_exch_t *exch, iface_t iface,
842 sysarg_t arg2, sysarg_t arg3)
843{
844 if (exch == NULL) {
845 errno = ENOENT;
846 return NULL;
847 }
848
849 cap_phone_handle_t phone;
850 errno_t rc = async_connect_me_to_internal(exch->phone, iface, arg2,
851 arg3, 0, &phone);
852 if (rc != EOK) {
853 errno = rc;
854 return NULL;
855 }
856
857 async_sess_t *sess = create_session(phone, mgmt, iface, arg2, arg3);
858 if (sess == NULL) {
859 ipc_hangup(phone);
860 }
861
862 return sess;
863}
864
865/** Set arguments for new connections.
866 *
867 * FIXME This is an ugly hack to work around the problem that parallel
868 * exchanges are implemented using parallel connections. When we create
869 * a callback session, the framework does not know arguments for the new
870 * connections.
871 *
872 * The proper solution seems to be to implement parallel exchanges using
873 * tagging.
874 *
875 */
876void async_sess_args_set(async_sess_t *sess, iface_t iface, sysarg_t arg2,
877 sysarg_t arg3)
878{
879 sess->arg1 = iface;
880 sess->arg2 = arg2;
881 sess->arg3 = arg3;
882}
883
884/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
885 *
886 * Ask through phone for a new connection to some service and block until
887 * success.
888 *
889 * @param exch Exchange for sending the message.
890 * @param iface Connection interface.
891 * @param arg2 User defined argument.
892 * @param arg3 User defined argument.
893 *
894 * @return New session on success or NULL on error.
895 *
896 */
897async_sess_t *async_connect_me_to_blocking(async_exch_t *exch, iface_t iface,
898 sysarg_t arg2, sysarg_t arg3)
899{
900 if (exch == NULL) {
901 errno = ENOENT;
902 return NULL;
903 }
904
905 cap_phone_handle_t phone;
906 errno_t rc = async_connect_me_to_internal(exch->phone, iface, arg2,
907 arg3, IPC_FLAG_BLOCKING, &phone);
908 if (rc != EOK) {
909 errno = rc;
910 free(sess);
911 return NULL;
912 }
913
914 async_sess_t *sess = create_session(phone, mgmt, iface, arg2, arg3);
915 if (sess == NULL) {
916 ipc_hangup(phone);
917 }
918
919 return sess;
920}
921
922/** Connect to a task specified by id.
923 *
924 */
925async_sess_t *async_connect_kbox(task_id_t id)
926{
927 cap_phone_handle_t phone;
928 errno_t rc = ipc_connect_kbox(id, &phone);
929 if (rc != EOK) {
930 errno = rc;
931 return NULL;
932 }
933
934 async_sess_t *sess = create_session(phone, EXCHANGE_ATOMIC, 0, 0, 0);
935 if (sess == NULL) {
936 ipc_hangup(phone);
937 }
938
939 return sess;
940}
941
942static errno_t async_hangup_internal(cap_phone_handle_t phone)
943{
944 return ipc_hangup(phone);
945}
946
947/** Wrapper for ipc_hangup.
948 *
949 * @param sess Session to hung up.
950 *
951 * @return Zero on success or an error code.
952 *
953 */
954errno_t async_hangup(async_sess_t *sess)
955{
956 async_exch_t *exch;
957
958 assert(sess);
959
960 fibril_mutex_lock(&async_sess_mutex);
961
962 if (sess->exchanges > 0) {
963 fibril_mutex_unlock(&async_sess_mutex);
964 return EBUSY;
965 }
966
967 errno_t rc = async_hangup_internal(sess->phone);
968
969 while (!list_empty(&sess->exch_list)) {
970 exch = (async_exch_t *)
971 list_get_instance(list_first(&sess->exch_list),
972 async_exch_t, sess_link);
973
974 list_remove(&exch->sess_link);
975 list_remove(&exch->global_link);
976 async_hangup_internal(exch->phone);
977 free(exch);
978 }
979
980 free(sess);
981
982 fibril_mutex_unlock(&async_sess_mutex);
983
984 return rc;
985}
986
987/** Start new exchange in a session.
988 *
989 * @param session Session.
990 *
991 * @return New exchange or NULL on error.
992 *
993 */
994async_exch_t *async_exchange_begin(async_sess_t *sess)
995{
996 if (sess == NULL)
997 return NULL;
998
999 exch_mgmt_t mgmt = sess->mgmt;
1000 if (sess->iface != 0)
1001 mgmt = sess->iface & IFACE_EXCHANGE_MASK;
1002
1003 async_exch_t *exch = NULL;
1004
1005 fibril_mutex_lock(&async_sess_mutex);
1006
1007 if (!list_empty(&sess->exch_list)) {
1008 /*
1009 * There are inactive exchanges in the session.
1010 */
1011 exch = (async_exch_t *)
1012 list_get_instance(list_first(&sess->exch_list),
1013 async_exch_t, sess_link);
1014
1015 list_remove(&exch->sess_link);
1016 list_remove(&exch->global_link);
1017 } else {
1018 /*
1019 * There are no available exchanges in the session.
1020 */
1021
1022 if ((mgmt == EXCHANGE_ATOMIC) ||
1023 (mgmt == EXCHANGE_SERIALIZE)) {
1024 exch = (async_exch_t *) malloc(sizeof(async_exch_t));
1025 if (exch != NULL) {
1026 link_initialize(&exch->sess_link);
1027 link_initialize(&exch->global_link);
1028 exch->sess = sess;
1029 exch->phone = sess->phone;
1030 }
1031 } else if (mgmt == EXCHANGE_PARALLEL) {
1032 cap_phone_handle_t phone;
1033 errno_t rc;
1034
1035 retry:
1036 /*
1037 * Make a one-time attempt to connect a new data phone.
1038 */
1039 rc = async_connect_me_to_internal(sess->phone, sess->arg1,
1040 sess->arg2, sess->arg3, 0, &phone);
1041 if (rc == EOK) {
1042 exch = (async_exch_t *) malloc(sizeof(async_exch_t));
1043 if (exch != NULL) {
1044 link_initialize(&exch->sess_link);
1045 link_initialize(&exch->global_link);
1046 exch->sess = sess;
1047 exch->phone = phone;
1048 } else
1049 async_hangup_internal(phone);
1050 } else if (!list_empty(&inactive_exch_list)) {
1051 /*
1052 * We did not manage to connect a new phone. But we
1053 * can try to close some of the currently inactive
1054 * connections in other sessions and try again.
1055 */
1056 exch = (async_exch_t *)
1057 list_get_instance(list_first(&inactive_exch_list),
1058 async_exch_t, global_link);
1059
1060 list_remove(&exch->sess_link);
1061 list_remove(&exch->global_link);
1062 async_hangup_internal(exch->phone);
1063 free(exch);
1064 goto retry;
1065 } else {
1066 /*
1067 * Wait for a phone to become available.
1068 */
1069 fibril_condvar_wait(&avail_phone_cv, &async_sess_mutex);
1070 goto retry;
1071 }
1072 }
1073 }
1074
1075 if (exch != NULL)
1076 sess->exchanges++;
1077
1078 fibril_mutex_unlock(&async_sess_mutex);
1079
1080 if (exch != NULL && mgmt == EXCHANGE_SERIALIZE)
1081 fibril_mutex_lock(&sess->mutex);
1082
1083 return exch;
1084}
1085
1086/** Finish an exchange.
1087 *
1088 * @param exch Exchange to finish.
1089 *
1090 */
1091void async_exchange_end(async_exch_t *exch)
1092{
1093 if (exch == NULL)
1094 return;
1095
1096 async_sess_t *sess = exch->sess;
1097 assert(sess != NULL);
1098
1099 exch_mgmt_t mgmt = sess->mgmt;
1100 if (sess->iface != 0)
1101 mgmt = sess->iface & IFACE_EXCHANGE_MASK;
1102
1103 if (mgmt == EXCHANGE_SERIALIZE)
1104 fibril_mutex_unlock(&sess->mutex);
1105
1106 fibril_mutex_lock(&async_sess_mutex);
1107
1108 sess->exchanges--;
1109
1110 list_append(&exch->sess_link, &sess->exch_list);
1111 list_append(&exch->global_link, &inactive_exch_list);
1112 fibril_condvar_signal(&avail_phone_cv);
1113
1114 fibril_mutex_unlock(&async_sess_mutex);
1115}
1116
1117/** Wrapper for IPC_M_SHARE_IN calls using the async framework.
1118 *
1119 * @param exch Exchange for sending the message.
1120 * @param size Size of the destination address space area.
1121 * @param arg User defined argument.
1122 * @param flags Storage for the received flags. Can be NULL.
1123 * @param dst Address of the storage for the destination address space area
1124 * base address. Cannot be NULL.
1125 *
1126 * @return Zero on success or an error code from errno.h.
1127 *
1128 */
1129static errno_t async_share_in_start(async_exch_t *exch, size_t size,
1130 sysarg_t arg, unsigned int *flags, void **dst)
1131{
1132 if (exch == NULL)
1133 return ENOENT;
1134
1135 sysarg_t _flags = 0;
1136 sysarg_t _dst = (sysarg_t) -1;
1137 errno_t res = async_req_3_5(exch, IPC_M_SHARE_IN, (sysarg_t) size,
1138 (sysarg_t) __progsymbols.end, arg, NULL, &_flags, NULL, NULL,
1139 &_dst);
1140
1141 if (flags)
1142 *flags = (unsigned int) _flags;
1143
1144 *dst = (void *) _dst;
1145 return res;
1146}
1147
1148errno_t async_share_in_start_0_0(async_exch_t *exch, size_t size, void **dst)
1149{
1150 return async_share_in_start(exch, size, 0, NULL, dst);
1151}
1152
1153errno_t async_share_in_start_0_1(async_exch_t *exch, size_t size,
1154 unsigned int *flags, void **dst)
1155{
1156 return async_share_in_start(exch, size, 0, flags, dst);
1157}
1158
1159errno_t async_share_in_start_1_0(async_exch_t *exch, size_t size, sysarg_t arg,
1160 void **dst)
1161{
1162 return async_share_in_start(exch, size, arg, NULL, dst);
1163}
1164
1165errno_t async_share_in_start_1_1(async_exch_t *exch, size_t size, sysarg_t arg,
1166 unsigned int *flags, void **dst)
1167{
1168 return async_share_in_start(exch, size, arg, flags, dst);
1169}
1170
1171/** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
1172 *
1173 * @param exch Exchange for sending the message.
1174 * @param src Source address space area base address.
1175 * @param flags Flags to be used for sharing. Bits can be only cleared.
1176 *
1177 * @return Zero on success or an error code from errno.h.
1178 *
1179 */
1180errno_t async_share_out_start(async_exch_t *exch, void *src, unsigned int flags)
1181{
1182 if (exch == NULL)
1183 return ENOENT;
1184
1185 return async_req_3_0(exch, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
1186 (sysarg_t) flags);
1187}
1188
1189/** Start IPC_M_DATA_READ using the async framework.
1190 *
1191 * @param exch Exchange for sending the message.
1192 * @param dst Address of the beginning of the destination buffer.
1193 * @param size Size of the destination buffer (in bytes).
1194 * @param dataptr Storage of call data (arg 2 holds actual data size).
1195 *
1196 * @return Hash of the sent message or 0 on error.
1197 *
1198 */
1199aid_t async_data_read(async_exch_t *exch, void *dst, size_t size,
1200 ipc_call_t *dataptr)
1201{
1202 return async_send_2(exch, IPC_M_DATA_READ, (sysarg_t) dst,
1203 (sysarg_t) size, dataptr);
1204}
1205
1206/** Wrapper for IPC_M_DATA_READ calls using the async framework.
1207 *
1208 * @param exch Exchange for sending the message.
1209 * @param dst Address of the beginning of the destination buffer.
1210 * @param size Size of the destination buffer.
1211 *
1212 * @return Zero on success or an error code from errno.h.
1213 *
1214 */
1215errno_t async_data_read_start(async_exch_t *exch, void *dst, size_t size)
1216{
1217 if (exch == NULL)
1218 return ENOENT;
1219
1220 return async_req_2_0(exch, IPC_M_DATA_READ, (sysarg_t) dst,
1221 (sysarg_t) size);
1222}
1223
1224/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
1225 *
1226 * @param exch Exchange for sending the message.
1227 * @param src Address of the beginning of the source buffer.
1228 * @param size Size of the source buffer.
1229 *
1230 * @return Zero on success or an error code from errno.h.
1231 *
1232 */
1233errno_t async_data_write_start(async_exch_t *exch, const void *src, size_t size)
1234{
1235 if (exch == NULL)
1236 return ENOENT;
1237
1238 return async_req_2_0(exch, IPC_M_DATA_WRITE, (sysarg_t) src,
1239 (sysarg_t) size);
1240}
1241
1242errno_t async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
1243 sysarg_t arg3, async_exch_t *other_exch)
1244{
1245 return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE,
1246 arg1, arg2, arg3, 0, cap_handle_raw(other_exch->phone));
1247}
1248
1249/** Lock and get session remote state
1250 *
1251 * Lock and get the local replica of the remote state
1252 * in stateful sessions. The call should be paired
1253 * with async_remote_state_release*().
1254 *
1255 * @param[in] sess Stateful session.
1256 *
1257 * @return Local replica of the remote state.
1258 *
1259 */
1260void *async_remote_state_acquire(async_sess_t *sess)
1261{
1262 fibril_mutex_lock(&sess->remote_state_mtx);
1263 return sess->remote_state_data;
1264}
1265
1266/** Update the session remote state
1267 *
1268 * Update the local replica of the remote state
1269 * in stateful sessions. The remote state must
1270 * be already locked.
1271 *
1272 * @param[in] sess Stateful session.
1273 * @param[in] state New local replica of the remote state.
1274 *
1275 */
1276void async_remote_state_update(async_sess_t *sess, void *state)
1277{
1278 assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
1279 sess->remote_state_data = state;
1280}
1281
1282/** Release the session remote state
1283 *
1284 * Unlock the local replica of the remote state
1285 * in stateful sessions.
1286 *
1287 * @param[in] sess Stateful session.
1288 *
1289 */
1290void async_remote_state_release(async_sess_t *sess)
1291{
1292 assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
1293
1294 fibril_mutex_unlock(&sess->remote_state_mtx);
1295}
1296
1297/** Release the session remote state and end an exchange
1298 *
1299 * Unlock the local replica of the remote state
1300 * in stateful sessions. This is convenience function
1301 * which gets the session pointer from the exchange
1302 * and also ends the exchange.
1303 *
1304 * @param[in] exch Stateful session's exchange.
1305 *
1306 */
1307void async_remote_state_release_exchange(async_exch_t *exch)
1308{
1309 if (exch == NULL)
1310 return;
1311
1312 async_sess_t *sess = exch->sess;
1313 assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
1314
1315 async_exchange_end(exch);
1316 fibril_mutex_unlock(&sess->remote_state_mtx);
1317}
1318
1319void *async_as_area_create(void *base, size_t size, unsigned int flags,
1320 async_sess_t *pager, sysarg_t id1, sysarg_t id2, sysarg_t id3)
1321{
1322 as_area_pager_info_t pager_info = {
1323 .pager = pager->phone,
1324 .id1 = id1,
1325 .id2 = id2,
1326 .id3 = id3
1327 };
1328 return as_area_create(base, size, flags, &pager_info);
1329}
1330
1331/** @}
1332 */
Note: See TracBrowser for help on using the repository browser.