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

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

cstyle changes (improve comments, use unsigned types for bit flags, etc.)
no change in functionality

  • Property mode set to 100644
File size: 25.4 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 */
33
34/** @addtogroup libcipc IPC
35 * @brief HelenOS uspace IPC
36 * @{
37 * @ingroup libc
38 */
39/** @file
40 */
41
42#include <ipc/ipc.h>
43#include <libc.h>
44#include <malloc.h>
45#include <errno.h>
46#include <adt/list.h>
47#include <futex.h>
48#include <fibril.h>
49
50/**
51 * Structures of this type are used for keeping track
52 * of sent asynchronous calls and queing unsent calls.
53 */
54typedef struct {
55 link_t list;
56
57 ipc_async_callback_t callback;
58 void *private;
59
60 union {
61 ipc_callid_t callid;
62 struct {
63 ipc_call_t data;
64 int phoneid;
65 } msg;
66 } u;
67
68 /** Fibril waiting for sending this call. */
69 fid_t fid;
70} async_call_t;
71
72LIST_INITIALIZE(dispatched_calls);
73
74/** List of asynchronous calls that were not accepted by kernel.
75 *
76 * Protected by async_futex, because if the call is not accepted
77 * by the kernel, the async framework is used automatically.
78 *
79 */
80LIST_INITIALIZE(queued_calls);
81
82static atomic_t ipc_futex = FUTEX_INITIALIZER;
83
84/** Fast synchronous call.
85 *
86 * Only three payload arguments can be passed using this function. However,
87 * this function is faster than the generic ipc_call_sync_slow() because
88 * the payload is passed directly in registers.
89 *
90 * @param phoneid Phone handle for the call.
91 * @param method Requested method.
92 * @param arg1 Service-defined payload argument.
93 * @param arg2 Service-defined payload argument.
94 * @param arg3 Service-defined payload argument.
95 * @param result1 If non-NULL, the return ARG1 will be stored there.
96 * @param result2 If non-NULL, the return ARG2 will be stored there.
97 * @param result3 If non-NULL, the return ARG3 will be stored there.
98 * @param result4 If non-NULL, the return ARG4 will be stored there.
99 * @param result5 If non-NULL, the return ARG5 will be stored there.
100 *
101 * @return Negative values representing IPC errors.
102 * @return Otherwise the RETVAL of the answer.
103 *
104 */
105int ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1,
106 sysarg_t arg2, sysarg_t arg3, sysarg_t *result1, sysarg_t *result2,
107 sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
108{
109 ipc_call_t resdata;
110 int callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
111 arg2, arg3, (sysarg_t) &resdata);
112 if (callres)
113 return callres;
114
115 if (result1)
116 *result1 = IPC_GET_ARG1(resdata);
117 if (result2)
118 *result2 = IPC_GET_ARG2(resdata);
119 if (result3)
120 *result3 = IPC_GET_ARG3(resdata);
121 if (result4)
122 *result4 = IPC_GET_ARG4(resdata);
123 if (result5)
124 *result5 = IPC_GET_ARG5(resdata);
125
126 return IPC_GET_RETVAL(resdata);
127}
128
129/** Synchronous call transmitting 5 arguments of payload.
130 *
131 * @param phoneid Phone handle for the call.
132 * @param imethod Requested interface and method.
133 * @param arg1 Service-defined payload argument.
134 * @param arg2 Service-defined payload argument.
135 * @param arg3 Service-defined payload argument.
136 * @param arg4 Service-defined payload argument.
137 * @param arg5 Service-defined payload argument.
138 * @param result1 If non-NULL, storage for the first return argument.
139 * @param result2 If non-NULL, storage for the second return argument.
140 * @param result3 If non-NULL, storage for the third return argument.
141 * @param result4 If non-NULL, storage for the fourth return argument.
142 * @param result5 If non-NULL, storage for the fifth return argument.
143 *
144 * @return Negative values representing IPC errors.
145 * @return Otherwise the RETVAL of the answer.
146 *
147 */
148int ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
149 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
150 sysarg_t *result1, sysarg_t *result2, sysarg_t *result3, sysarg_t *result4,
151 sysarg_t *result5)
152{
153 ipc_call_t data;
154
155 IPC_SET_IMETHOD(data, imethod);
156 IPC_SET_ARG1(data, arg1);
157 IPC_SET_ARG2(data, arg2);
158 IPC_SET_ARG3(data, arg3);
159 IPC_SET_ARG4(data, arg4);
160 IPC_SET_ARG5(data, arg5);
161
162 int callres = __SYSCALL3(SYS_IPC_CALL_SYNC_SLOW, phoneid,
163 (sysarg_t) &data, (sysarg_t) &data);
164 if (callres)
165 return callres;
166
167 if (result1)
168 *result1 = IPC_GET_ARG1(data);
169 if (result2)
170 *result2 = IPC_GET_ARG2(data);
171 if (result3)
172 *result3 = IPC_GET_ARG3(data);
173 if (result4)
174 *result4 = IPC_GET_ARG4(data);
175 if (result5)
176 *result5 = IPC_GET_ARG5(data);
177
178 return IPC_GET_RETVAL(data);
179}
180
181/** Send asynchronous message via syscall.
182 *
183 * @param phoneid Phone handle for the call.
184 * @param data Call data with the request.
185 *
186 * @return Hash of the call or an error code.
187 *
188 */
189static ipc_callid_t ipc_call_async_internal(int phoneid, ipc_call_t *data)
190{
191 return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
192}
193
194/** Prolog for ipc_call_async_*() functions.
195 *
196 * @param private Argument for the answer/error callback.
197 * @param callback Answer/error callback.
198 *
199 * @return New, partially initialized async_call structure or NULL.
200 *
201 */
202static inline async_call_t *ipc_prepare_async(void *private,
203 ipc_async_callback_t callback)
204{
205 async_call_t *call =
206 (async_call_t *) malloc(sizeof(async_call_t));
207 if (!call) {
208 if (callback)
209 callback(private, ENOMEM, NULL);
210
211 return NULL;
212 }
213
214 call->callback = callback;
215 call->private = private;
216
217 return call;
218}
219
220/** Epilog for ipc_call_async_*() functions.
221 *
222 * @param callid Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
223 * @param phoneid Phone handle through which the call was made.
224 * @param call Structure returned by ipc_prepare_async().
225 * @param can_preempt If true, the current fibril can be preempted
226 * in this call.
227 *
228 */
229static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
230 async_call_t *call, bool can_preempt)
231{
232 if (!call) {
233 /* Nothing to do regardless if failed or not */
234 futex_up(&ipc_futex);
235 return;
236 }
237
238 if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
239 futex_up(&ipc_futex);
240
241 /* Call asynchronous handler with error code */
242 if (call->callback)
243 call->callback(call->private, ENOENT, NULL);
244
245 free(call);
246 return;
247 }
248
249 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
250 futex_up(&ipc_futex);
251
252 call->u.msg.phoneid = phoneid;
253
254 futex_down(&async_futex);
255 list_append(&call->list, &queued_calls);
256
257 if (can_preempt) {
258 call->fid = fibril_get_id();
259 fibril_switch(FIBRIL_TO_MANAGER);
260 /* Async futex unlocked by previous call */
261 } else {
262 call->fid = 0;
263 futex_up(&async_futex);
264 }
265
266 return;
267 }
268
269 call->u.callid = callid;
270
271 /* Add call to the list of dispatched calls */
272 list_append(&call->list, &dispatched_calls);
273 futex_up(&ipc_futex);
274}
275
276/** Fast asynchronous call.
277 *
278 * This function can only handle four arguments of payload. It is, however,
279 * faster than the more generic ipc_call_async_slow().
280 *
281 * Note that this function is a void function.
282 *
283 * During normal operation, answering this call will trigger the callback.
284 * In case of fatal error, the callback handler is called with the proper
285 * error code. If the call cannot be temporarily made, it is queued.
286 *
287 * @param phoneid Phone handle for the call.
288 * @param imethod Requested interface and method.
289 * @param arg1 Service-defined payload argument.
290 * @param arg2 Service-defined payload argument.
291 * @param arg3 Service-defined payload argument.
292 * @param arg4 Service-defined payload argument.
293 * @param private Argument to be passed to the answer/error callback.
294 * @param callback Answer or error callback.
295 * @param can_preempt If true, the current fibril will be preempted in
296 * case the kernel temporarily refuses to accept more
297 * asynchronous calls.
298 *
299 */
300void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
301 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private,
302 ipc_async_callback_t callback, bool can_preempt)
303{
304 async_call_t *call = NULL;
305
306 if (callback) {
307 call = ipc_prepare_async(private, callback);
308 if (!call)
309 return;
310 }
311
312 /*
313 * We need to make sure that we get callid
314 * before another thread accesses the queue again.
315 */
316
317 futex_down(&ipc_futex);
318 ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
319 imethod, arg1, arg2, arg3, arg4);
320
321 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
322 if (!call) {
323 call = ipc_prepare_async(private, callback);
324 if (!call)
325 return;
326 }
327
328 IPC_SET_IMETHOD(call->u.msg.data, imethod);
329 IPC_SET_ARG1(call->u.msg.data, arg1);
330 IPC_SET_ARG2(call->u.msg.data, arg2);
331 IPC_SET_ARG3(call->u.msg.data, arg3);
332 IPC_SET_ARG4(call->u.msg.data, arg4);
333
334 /*
335 * To achieve deterministic behavior, we always zero out the
336 * arguments that are beyond the limits of the fast version.
337 */
338
339 IPC_SET_ARG5(call->u.msg.data, 0);
340 }
341
342 ipc_finish_async(callid, phoneid, call, can_preempt);
343}
344
345/** Asynchronous call transmitting the entire payload.
346 *
347 * Note that this function is a void function.
348 *
349 * During normal operation, answering this call will trigger the callback.
350 * In case of fatal error, the callback handler is called with the proper
351 * error code. If the call cannot be temporarily made, it is queued.
352 *
353 * @param phoneid Phone handle for the call.
354 * @param imethod Requested interface and method.
355 * @param arg1 Service-defined payload argument.
356 * @param arg2 Service-defined payload argument.
357 * @param arg3 Service-defined payload argument.
358 * @param arg4 Service-defined payload argument.
359 * @param arg5 Service-defined payload argument.
360 * @param private Argument to be passed to the answer/error callback.
361 * @param callback Answer or error callback.
362 * @param can_preempt If true, the current fibril will be preempted in
363 * case the kernel temporarily refuses to accept more
364 * asynchronous calls.
365 *
366 */
367void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
368 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
369 ipc_async_callback_t callback, bool can_preempt)
370{
371 async_call_t *call = ipc_prepare_async(private, callback);
372 if (!call)
373 return;
374
375 IPC_SET_IMETHOD(call->u.msg.data, imethod);
376 IPC_SET_ARG1(call->u.msg.data, arg1);
377 IPC_SET_ARG2(call->u.msg.data, arg2);
378 IPC_SET_ARG3(call->u.msg.data, arg3);
379 IPC_SET_ARG4(call->u.msg.data, arg4);
380 IPC_SET_ARG5(call->u.msg.data, arg5);
381
382 /*
383 * We need to make sure that we get callid
384 * before another threadaccesses the queue again.
385 */
386
387 futex_down(&ipc_futex);
388 ipc_callid_t callid =
389 ipc_call_async_internal(phoneid, &call->u.msg.data);
390
391 ipc_finish_async(callid, phoneid, call, can_preempt);
392}
393
394/** Answer received call (fast version).
395 *
396 * The fast answer makes use of passing retval and first four arguments in
397 * registers. If you need to return more, use the ipc_answer_slow() instead.
398 *
399 * @param callid Hash of the call being answered.
400 * @param retval Return value.
401 * @param arg1 First return argument.
402 * @param arg2 Second return argument.
403 * @param arg3 Third return argument.
404 * @param arg4 Fourth return argument.
405 *
406 * @return Zero on success.
407 * @return Value from @ref errno.h on failure.
408 *
409 */
410sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
411 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
412{
413 return __SYSCALL6(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2, arg3,
414 arg4);
415}
416
417/** Answer received call (entire payload).
418 *
419 * @param callid Hash of the call being answered.
420 * @param retval Return value.
421 * @param arg1 First return argument.
422 * @param arg2 Second return argument.
423 * @param arg3 Third return argument.
424 * @param arg4 Fourth return argument.
425 * @param arg5 Fifth return argument.
426 *
427 * @return Zero on success.
428 * @return Value from @ref errno.h on failure.
429 *
430 */
431sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
432 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
433{
434 ipc_call_t data;
435
436 IPC_SET_RETVAL(data, retval);
437 IPC_SET_ARG1(data, arg1);
438 IPC_SET_ARG2(data, arg2);
439 IPC_SET_ARG3(data, arg3);
440 IPC_SET_ARG4(data, arg4);
441 IPC_SET_ARG5(data, arg5);
442
443 return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
444}
445
446/** Try to dispatch queued calls from the async queue.
447 *
448 */
449static void dispatch_queued_calls(void)
450{
451 /** @todo
452 * Integrate intelligently ipc_futex so that it is locked during
453 * ipc_call_async_*() until it is added to dispatched_calls.
454 */
455
456 futex_down(&async_futex);
457
458 while (!list_empty(&queued_calls)) {
459 async_call_t *call =
460 list_get_instance(queued_calls.next, async_call_t, list);
461 ipc_callid_t callid =
462 ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
463
464 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY)
465 break;
466
467 list_remove(&call->list);
468
469 futex_up(&async_futex);
470
471 if (call->fid)
472 fibril_add_ready(call->fid);
473
474 if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
475 if (call->callback)
476 call->callback(call->private, ENOENT, NULL);
477
478 free(call);
479 } else {
480 call->u.callid = callid;
481
482 futex_down(&ipc_futex);
483 list_append(&call->list, &dispatched_calls);
484 futex_up(&ipc_futex);
485 }
486
487 futex_down(&async_futex);
488 }
489
490 futex_up(&async_futex);
491}
492
493/** Handle received answer.
494 *
495 * Find the hash of the answer and call the answer callback.
496 *
497 * The answer has the same hash as the request OR'ed with
498 * the IPC_CALLID_ANSWERED bit.
499 *
500 * @todo Use hash table.
501 *
502 * @param callid Hash of the received answer.
503 * @param data Call data of the answer.
504 *
505 */
506static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
507{
508 callid &= ~IPC_CALLID_ANSWERED;
509
510 futex_down(&ipc_futex);
511
512 link_t *item;
513 for (item = dispatched_calls.next; item != &dispatched_calls;
514 item = item->next) {
515 async_call_t *call =
516 list_get_instance(item, async_call_t, list);
517
518 if (call->u.callid == callid) {
519 list_remove(&call->list);
520
521 futex_up(&ipc_futex);
522
523 if (call->callback)
524 call->callback(call->private,
525 IPC_GET_RETVAL(*data), data);
526
527 free(call);
528 return;
529 }
530 }
531
532 futex_up(&ipc_futex);
533}
534
535/** Wait for first IPC call to come.
536 *
537 * @param call Incoming call storage.
538 * @param usec Timeout in microseconds
539 * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
540 *
541 * @return Hash of the call. Note that certain bits have special
542 * meaning: IPC_CALLID_ANSWERED is set in an answer
543 * and IPC_CALLID_NOTIFICATION is used for notifications.
544 *
545 */
546ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec,
547 unsigned int flags)
548{
549 ipc_callid_t callid =
550 __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
551
552 /* Handle received answers */
553 if (callid & IPC_CALLID_ANSWERED) {
554 handle_answer(callid, call);
555 dispatch_queued_calls();
556 }
557
558 return callid;
559}
560
561/** Interrupt one thread of this task from waiting for IPC.
562 *
563 */
564void ipc_poke(void)
565{
566 __SYSCALL0(SYS_IPC_POKE);
567}
568
569/** Wait for first IPC call to come.
570 *
571 * Only requests are returned, answers are processed internally.
572 *
573 * @param call Incoming call storage.
574 * @param usec Timeout in microseconds
575 *
576 * @return Hash of the call.
577 *
578 */
579ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
580{
581 ipc_callid_t callid;
582
583 do {
584 callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
585 } while (callid & IPC_CALLID_ANSWERED);
586
587 return callid;
588}
589
590/** Check if there is an IPC call waiting to be picked up.
591 *
592 * Only requests are returned, answers are processed internally.
593 *
594 * @param call Incoming call storage.
595 *
596 * @return Hash of the call.
597 *
598 */
599ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
600{
601 ipc_callid_t callid;
602
603 do {
604 callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
605 SYNCH_FLAGS_NON_BLOCKING);
606 } while (callid & IPC_CALLID_ANSWERED);
607
608 return callid;
609}
610
611/** Request callback connection.
612 *
613 * The @a taskhash and @a phonehash identifiers returned
614 * by the kernel can be used for connection tracking.
615 *
616 * @param phoneid Phone handle used for contacting the other side.
617 * @param arg1 User defined argument.
618 * @param arg2 User defined argument.
619 * @param arg3 User defined argument.
620 * @param taskhash Opaque identifier of the client task.
621 * @param phonehash Opaque identifier of the phone that will
622 * be used for incoming calls.
623 *
624 * @return Zero on success or a negative error code.
625 *
626 */
627int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
628 sysarg_t *taskhash, sysarg_t *phonehash)
629{
630 return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
631 arg3, NULL, NULL, NULL, taskhash, phonehash);
632}
633
634/** Request new connection.
635 *
636 * @param phoneid Phone handle used for contacting the other side.
637 * @param arg1 User defined argument.
638 * @param arg2 User defined argument.
639 * @param arg3 User defined argument.
640 *
641 * @return New phone handle on success or a negative error code.
642 *
643 */
644int ipc_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
645{
646 sysarg_t newphid;
647 int res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
648 NULL, NULL, NULL, NULL, &newphid);
649 if (res)
650 return res;
651
652 return newphid;
653}
654
655/** Request new connection (blocking)
656 *
657 * If the connection is not available at the moment, the
658 * call should block. This has to be, however, implemented
659 * on the server side.
660 *
661 * @param phoneid Phone handle used for contacting the other side.
662 * @param arg1 User defined argument.
663 * @param arg2 User defined argument.
664 * @param arg3 User defined argument.
665 *
666 * @return New phone handle on success or a negative error code.
667 *
668 */
669int ipc_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
670 sysarg_t arg3)
671{
672 sysarg_t newphid;
673 int res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
674 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
675 if (res)
676 return res;
677
678 return newphid;
679}
680
681/** Hang up a phone.
682 *
683 * @param phoneid Handle of the phone to be hung up.
684 *
685 * @return Zero on success or a negative error code.
686 *
687 */
688int ipc_hangup(int phoneid)
689{
690 return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
691}
692
693/** Forward a received call to another destination.
694 *
695 * For non-system methods, the old method, arg1 and arg2 are rewritten
696 * by the new values. For system methods, the new method, arg1 and arg2
697 * are written to the old arg1, arg2 and arg3, respectivelly. Calls with
698 * immutable methods are forwarded verbatim.
699 *
700 * @param callid Hash of the call to forward.
701 * @param phoneid Phone handle to use for forwarding.
702 * @param imethod New interface and method for the forwarded call.
703 * @param arg1 New value of the first argument for the forwarded call.
704 * @param arg2 New value of the second argument for the forwarded call.
705 * @param mode Flags specifying mode of the forward operation.
706 *
707 * @return Zero on success or an error code.
708 *
709 */
710int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
711 sysarg_t arg1, sysarg_t arg2, unsigned int mode)
712{
713 return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
714 arg2, mode);
715}
716
717int ipc_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
718 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
719 unsigned int mode)
720{
721 ipc_call_t data;
722
723 IPC_SET_IMETHOD(data, imethod);
724 IPC_SET_ARG1(data, arg1);
725 IPC_SET_ARG2(data, arg2);
726 IPC_SET_ARG3(data, arg3);
727 IPC_SET_ARG4(data, arg4);
728 IPC_SET_ARG5(data, arg5);
729
730 return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
731 mode);
732}
733
734/** Wrapper for IPC_M_SHARE_IN calls.
735 *
736 * @param phoneid Phone that will be used to contact the receiving side.
737 * @param dst Destination address space area base.
738 * @param size Size of the destination address space area.
739 * @param arg User defined argument.
740 * @param flags Storage for received flags. Can be NULL.
741 *
742 * @return Zero on success or a negative error code from errno.h.
743 *
744 */
745int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
746 unsigned int *flags)
747{
748 sysarg_t tmp_flags = 0;
749 int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
750 (sysarg_t) size, arg, NULL, &tmp_flags);
751
752 if (flags)
753 *flags = (unsigned int) tmp_flags;
754
755 return res;
756}
757
758/** Wrapper for answering the IPC_M_SHARE_IN calls.
759 *
760 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
761 * calls so that the user doesn't have to remember the meaning of each
762 * IPC argument.
763 *
764 * @param callid Hash of the IPC_M_DATA_READ call to answer.
765 * @param src Source address space base.
766 * @param flags Flags to be used for sharing. Bits can be only cleared.
767 *
768 * @return Zero on success or a value from @ref errno.h on failure.
769 *
770 */
771int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
772{
773 return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
774}
775
776/** Wrapper for IPC_M_SHARE_OUT calls.
777 *
778 * @param phoneid Phone that will be used to contact the receiving side.
779 * @param src Source address space area base address.
780 * @param flags Flags to be used for sharing. Bits can be only cleared.
781 *
782 * @return Zero on success or a negative error code from errno.h.
783 *
784 */
785int ipc_share_out_start(int phoneid, void *src, unsigned int flags)
786{
787 return ipc_call_sync_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
788 (sysarg_t) flags);
789}
790
791/** Wrapper for answering the IPC_M_SHARE_OUT calls.
792 *
793 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
794 * calls so that the user doesn't have to remember the meaning of each
795 * IPC argument.
796 *
797 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
798 * @param dst Destination address space area base address.
799 *
800 * @return Zero on success or a value from @ref errno.h on failure.
801 *
802 */
803int ipc_share_out_finalize(ipc_callid_t callid, void *dst)
804{
805 return ipc_answer_1(callid, EOK, (sysarg_t) dst);
806}
807
808/** Wrapper for IPC_M_DATA_READ calls.
809 *
810 * @param phoneid Phone that will be used to contact the receiving side.
811 * @param dst Address of the beginning of the destination buffer.
812 * @param size Size of the destination buffer.
813 *
814 * @return Zero on success or a negative error code from errno.h.
815 *
816 */
817int ipc_data_read_start(int phoneid, void *dst, size_t size)
818{
819 return ipc_call_sync_2_0(phoneid, IPC_M_DATA_READ, (sysarg_t) dst,
820 (sysarg_t) size);
821}
822
823/** Wrapper for answering the IPC_M_DATA_READ calls.
824 *
825 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
826 * calls so that the user doesn't have to remember the meaning of each
827 * IPC argument.
828 *
829 * @param callid Hash of the IPC_M_DATA_READ call to answer.
830 * @param src Source address for the IPC_M_DATA_READ call.
831 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than
832 * the maximum size announced by the sender.
833 *
834 * @return Zero on success or a value from @ref errno.h on failure.
835 *
836 */
837int ipc_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
838{
839 return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
840}
841
842/** Wrapper for IPC_M_DATA_WRITE calls.
843 *
844 * @param phoneid Phone that will be used to contact the receiving side.
845 * @param src Address of the beginning of the source buffer.
846 * @param size Size of the source buffer.
847 *
848 * @return Zero on success or a negative error code from errno.h.
849 *
850 */
851int ipc_data_write_start(int phoneid, const void *src, size_t size)
852{
853 return ipc_call_sync_2_0(phoneid, IPC_M_DATA_WRITE, (sysarg_t) src,
854 (sysarg_t) size);
855}
856
857/** Wrapper for answering the IPC_M_DATA_WRITE calls.
858 *
859 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
860 * calls so that the user doesn't have to remember the meaning of each
861 * IPC argument.
862 *
863 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
864 * @param dst Final destination address for the IPC_M_DATA_WRITE call.
865 * @param size Final size for the IPC_M_DATA_WRITE call.
866 *
867 * @return Zero on success or a value from @ref errno.h on failure.
868 *
869 */
870int ipc_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
871{
872 return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
873}
874
875/** Connect to a task specified by id.
876 *
877 */
878int ipc_connect_kbox(task_id_t id)
879{
880#ifdef __32_BITS__
881 sysarg64_t arg = (sysarg64_t) id;
882 return __SYSCALL1(SYS_IPC_CONNECT_KBOX, (sysarg_t) &arg);
883#endif
884
885#ifdef __64_BITS__
886 return __SYSCALL1(SYS_IPC_CONNECT_KBOX, (sysarg_t) id);
887#endif
888}
889
890/** @}
891 */
Note: See TracBrowser for help on using the repository browser.