L4Re - L4 Runtime Environment
ipc.h
Go to the documentation of this file.
1 
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Björn Döbel <doebel@os.inf.tu-dresden.de>,
10  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
11  * economic rights: Technische Universität Dresden (Germany)
12  *
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU General Public License 2.
15  * Please see the COPYING-GPL-2 file for details.
16  *
17  * As a special exception, you may use this file as part of a free software
18  * library without restriction. Specifically, if other files instantiate
19  * templates or use macros or inline functions from this file, or you compile
20  * this file and link it with other files to produce an executable, this
21  * file does not by itself cause the resulting executable to be covered by
22  * the GNU General Public License. This exception does not however
23  * invalidate any other reasons why the executable file might be covered by
24  * the GNU General Public License.
25  */
26 #ifndef __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__
27 #define __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__
28 
29 #include <l4/sys/types.h>
30 #include <l4/sys/utcb.h>
31 #include <l4/sys/err.h>
32 
56 /*****************************************************************************
57  *** IPC result checking
58  *****************************************************************************/
59 
76 {
132 };
133 
134 
145 L4_INLINE l4_umword_t
147 
148 
155 L4_INLINE long
157 
158 L4_INLINE long
159 l4_error_u(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
160 
161 /*****************************************************************************
162  *** IPC results
163  *****************************************************************************/
164 
174 L4_INLINE int l4_ipc_is_snd_error(l4_utcb_t *utcb) L4_NOTHROW;
175 
185 L4_INLINE int l4_ipc_is_rcv_error(l4_utcb_t *utcb) L4_NOTHROW;
186 
196 L4_INLINE int l4_ipc_error_code(l4_utcb_t *utcb) L4_NOTHROW;
197 
204 L4_INLINE long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW;
205 
206 
207 /*****************************************************************************
208  *** IPC calls
209  *****************************************************************************/
210 
228 L4_INLINE l4_msgtag_t
230  l4_timeout_t timeout) L4_NOTHROW;
231 
232 
253 L4_INLINE l4_msgtag_t
254 l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label,
255  l4_timeout_t timeout) L4_NOTHROW;
256 
257 
277 L4_INLINE l4_msgtag_t
279  l4_timeout_t timeout) L4_NOTHROW;
280 
297 L4_INLINE l4_msgtag_t
298 l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag,
299  l4_timeout_t timeout) L4_NOTHROW;
300 
301 
321 L4_INLINE l4_msgtag_t
323  l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW;
324 
344 L4_INLINE l4_msgtag_t
346  l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW;
347 
354 #if 0
355 
365 L4_INLINE l4_msgtag_t
366 l4_ipc_wait_next_period(l4_utcb_t *utcb,
367  l4_umword_t *label,
368  l4_timeout_t timeout);
369 
370 #endif
371 
387 l4_ipc(l4_cap_idx_t dest,
388  l4_utcb_t *utcb,
389  l4_umword_t flags,
390  l4_umword_t slabel,
391  l4_msgtag_t tag,
392  l4_umword_t *rlabel,
393  l4_timeout_t timeout) L4_NOTHROW;
394 
409 L4_INLINE l4_msgtag_t
411 
424 L4_INLINE int
425 l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
426  l4_msgtag_t *tag) L4_NOTHROW;
427 
428 /*
429  * \internal
430  * \ingroup l4_ipc_api
431  */
432 L4_INLINE int
433 l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
434  l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
435 
436 
437 /************************************************************************
438  * Implementations
439  **********************/
440 
441 L4_INLINE long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW
442 { return -(L4_EIPC_LO + ipc_error_code); }
443 
444 L4_INLINE l4_msgtag_t
446  l4_msgtag_t tag,
447  l4_timeout_t timeout) L4_NOTHROW
448 {
449  return l4_ipc(dest, utcb, L4_SYSF_CALL, 0, tag, 0, timeout);
450 }
451 
452 L4_INLINE l4_msgtag_t
454  l4_umword_t *label,
455  l4_timeout_t timeout) L4_NOTHROW
456 {
457  return l4_ipc(L4_INVALID_CAP, utcb, L4_SYSF_REPLY_AND_WAIT, 0, tag, label, timeout);
458 }
459 
460 L4_INLINE l4_msgtag_t
462  l4_msgtag_t tag,
463  l4_umword_t *src,
464  l4_timeout_t timeout) L4_NOTHROW
465 {
466  return l4_ipc(dest, utcb, L4_SYSF_SEND_AND_WAIT, 0, tag, src, timeout);
467 }
468 
469 L4_INLINE l4_msgtag_t
471  l4_msgtag_t tag,
472  l4_timeout_t timeout) L4_NOTHROW
473 {
474  return l4_ipc(dest, utcb, L4_SYSF_SEND, 0, tag, 0, timeout);
475 }
476 
477 L4_INLINE l4_msgtag_t
479  l4_timeout_t timeout) L4_NOTHROW
480 {
481  l4_msgtag_t t;
482  t.raw = 0;
483  return l4_ipc(L4_INVALID_CAP, utcb, L4_SYSF_WAIT, 0, t, src, timeout);
484 }
485 
486 L4_INLINE l4_msgtag_t
488  l4_timeout_t timeout) L4_NOTHROW
489 {
490  l4_msgtag_t t;
491  t.raw = 0;
492  return l4_ipc(src, utcb, L4_SYSF_RECV, 0, t, 0, timeout);
493 }
494 
495 L4_INLINE l4_msgtag_t
497 { return l4_ipc_receive(L4_INVALID_CAP, NULL, timeout); }
498 
499 L4_INLINE l4_umword_t
501 {
502  if (!l4_msgtag_has_error(tag))
503  return 0;
504  return l4_utcb_tcr_u(utcb)->error & L4_IPC_ERROR_MASK;
505 }
506 
507 L4_INLINE long
508 l4_error_u(l4_msgtag_t tag, l4_utcb_t *u) L4_NOTHROW
509 {
510  if (l4_msgtag_has_error(tag))
511  return l4_ipc_to_errno(l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK);
512 
513  return l4_msgtag_label(tag);
514 }
515 
516 L4_INLINE long
518 {
519  return l4_error_u(tag, l4_utcb());
520 }
521 
522 
524 { return (l4_utcb_tcr_u(u)->error & 1) != 0; }
525 
527 { return l4_utcb_tcr_u(u)->error & 1; }
528 
530 { return l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK; }
531 
532 
533 /*
534  * \internal
535  * \ingroup l4_ipc_api
536  */
537 L4_INLINE int
538 l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
539  l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
540 {
541  l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
542  int i = l4_msgtag_words(*tag) + 2 * l4_msgtag_items(*tag);
543 
544  if (i >= L4_UTCB_GENERIC_DATA_SIZE - 1)
545  return -L4_ENOMEM;
546 
547  v->mr[i] = snd_base | L4_ITEM_MAP | L4_ITEM_CONT;
548  v->mr[i + 1] = snd_fpage.raw;
549 
550  *tag = l4_msgtag(l4_msgtag_label(*tag), l4_msgtag_words(*tag),
551  l4_msgtag_items(*tag) + 1, l4_msgtag_flags(*tag));
552  return 0;
553 }
554 
555 L4_INLINE int
556 l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
557  l4_msgtag_t *tag) L4_NOTHROW
558 {
559  return l4_sndfpage_add_u(snd_fpage, snd_base, tag, l4_utcb());
560 }
561 
562 
563 #endif /* ! __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__ */
Identify a message item as map item.
Definition: consts.h:189
Timeout during receive operation.
Definition: ipc.h:83
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Timeout during send operation.
Definition: ipc.h:86
Send operation aborted.
Definition: ipc.h:121
int l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base, l4_msgtag_t *tag) L4_NOTHROW
Add a flex-page to be sent to the UTCB.
Definition: ipc.h:556
Total number of message register (MRs) available.
Definition: utcb.h:47
Receive operation aborted.
Definition: ipc.h:118
Invalid capability selector.
Definition: consts.h:141
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:435
l4_msgtag_t l4_ipc_send_and_wait(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Send a message and do an open wait.
Definition: ipc.h:461
l4_mword_t raw
raw value
Definition: types.h:160
int l4_ipc_is_snd_error(l4_utcb_t *utcb) L4_NOTHROW
Returns whether an error occurred in send phase of an invocation.
Definition: ipc.h:523
l4_umword_t l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
Get the error code for an object invocation.
Definition: ipc.h:500
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Common L4 ABI Data Types.
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition: ipc.h:445
long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW
Get a negative error code for the given IPC error code.
Definition: ipc.h:441
Receive-pagefault timeout in send operation.
Definition: ipc.h:114
#define L4_ALWAYS_INLINE
L4 Inline function attribute.
Definition: compiler.h:67
Wait flags (combines receive and open wait).
Definition: consts.h:105
Cut send message.
Definition: ipc.h:128
Send-pagefault timeout in send operation.
Definition: ipc.h:106
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:341
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
Reply-and-wait flags.
Definition: consts.h:121
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition: types.h:418
Timeout pair.
Definition: __timeout.h:57
Receive-pagefault timeout in receive operation.
Definition: ipc.h:110
l4_msgtag_flags
Flags for message tags.
Definition: types.h:94
L4_ALWAYS_INLINE l4_msgtag_t l4_ipc(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_umword_t flags, l4_umword_t slabel, l4_msgtag_t tag, l4_umword_t *rlabel, l4_timeout_t timeout) L4_NOTHROW
Generic L4 object invocation.
Definition: ipc.h:34
Map flexpage failed in receive operation.
Definition: ipc.h:95
unsigned l4_msgtag_items(l4_msgtag_t t) L4_NOTHROW
Get the number of typed items.
Definition: types.h:426
int l4_ipc_error_code(l4_utcb_t *utcb) L4_NOTHROW
Get the error condition of the last invocation from the TCR.
Definition: ipc.h:529
Call flags (combines send and receive).
Definition: consts.h:97
Error codes.
Receive-phase flag.
Definition: consts.h:69
Non-existing destination or source.
Definition: ipc.h:80
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
Mask for error bits.
Definition: ipc.h:77
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition: types.h:422
l4_umword_t raw
Raw value.
Definition: __l4_fpage.h:83
l4_msgtag_t l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW
Sleep for an amount of time.
Definition: ipc.h:496
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
No memory.
Definition: err.h:50
l4_msgtag_t l4_ipc_reply_and_wait(l4_utcb_t *utcb, l4_msgtag_t tag, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Reply and wait operation (uses the reply capability).
Definition: ipc.h:453
Communication error-range low.
Definition: err.h:70
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:407
Cut receive message, due to message buffer is too small.
Definition: ipc.h:124
l4_msgtag_t l4_ipc_send(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Send a message to an object (do not wait for a reply).
Definition: ipc.h:470
l4_ipc_tcr_error_t
Error codes in the error TCR.
Definition: ipc.h:75
L4 flexpage type.
Definition: __l4_fpage.h:81
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag.
Definition: ipc.h:517
Send-and-wait flags.
Definition: consts.h:113
l4_msgtag_t l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb, l4_timeout_t timeout) L4_NOTHROW
Wait for a message from a specific source.
Definition: ipc.h:487
Denote that the following item shall be put into the same receive item as this one.
Definition: consts.h:195
l4_msgtag_t l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW
Wait for an incoming message from any possible sender.
Definition: ipc.h:478
l4_umword_t error
System call error codes.
Definition: utcb.h:113
Message tag data structure.
Definition: types.h:158
Receive operation canceled.
Definition: ipc.h:89
int l4_ipc_is_rcv_error(l4_utcb_t *utcb) L4_NOTHROW
Returns whether an error occurred in receive phase of an invocation.
Definition: ipc.h:526
Send error mask.
Definition: ipc.h:78
Map flexpage failed in send operation.
Definition: ipc.h:99
Send-phase flag.
Definition: consts.h:58
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185
Send operation canceled.
Definition: ipc.h:92
Send-pagefault timeout in receive operation.
Definition: ipc.h:102