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 {
80  L4_IPC_ENOT_EXISTENT = 0x04,
83  L4_IPC_RETIMEOUT = 0x03,
86  L4_IPC_SETIMEOUT = 0x02,
89  L4_IPC_RECANCELED = 0x07,
92  L4_IPC_SECANCELED = 0x06,
95  L4_IPC_REMAPFAILED = 0x11,
99  L4_IPC_SEMAPFAILED = 0x10,
102  L4_IPC_RESNDPFTO = 0x0b,
106  L4_IPC_SESNDPFTO = 0x0a,
110  L4_IPC_RERCVPFTO = 0x0d,
114  L4_IPC_SERCVPFTO = 0x0c,
118  L4_IPC_REABORTED = 0x0f,
121  L4_IPC_SEABORTED = 0x0e,
124  L4_IPC_REMSGCUT = 0x09,
128  L4_IPC_SEMSGCUT = 0x08,
132 };
133 
134 
145 L4_INLINE l4_umword_t
147 
148 
158 L4_INLINE long
160 
161 L4_INLINE long
162 l4_error_u(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
163 
164 /*****************************************************************************
165  *** IPC results
166  *****************************************************************************/
167 
177 L4_INLINE int l4_ipc_is_snd_error(l4_utcb_t *utcb) L4_NOTHROW;
178 
188 L4_INLINE int l4_ipc_is_rcv_error(l4_utcb_t *utcb) L4_NOTHROW;
189 
199 L4_INLINE int l4_ipc_error_code(l4_utcb_t *utcb) L4_NOTHROW;
200 
207 L4_INLINE long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW;
208 
209 
210 /*****************************************************************************
211  *** IPC calls
212  *****************************************************************************/
213 
234 L4_INLINE l4_msgtag_t
236  l4_timeout_t timeout) L4_NOTHROW;
237 
238 
259 L4_INLINE l4_msgtag_t
260 l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label,
261  l4_timeout_t timeout) L4_NOTHROW;
262 
263 
286 L4_INLINE l4_msgtag_t
288  l4_timeout_t timeout) L4_NOTHROW;
289 
309 L4_INLINE l4_msgtag_t
310 l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag,
311  l4_timeout_t timeout) L4_NOTHROW;
312 
313 
333 L4_INLINE l4_msgtag_t
335  l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW;
336 
359 L4_INLINE l4_msgtag_t
361  l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW;
362 
369 #if 0
380 L4_INLINE l4_msgtag_t
381 l4_ipc_wait_next_period(l4_utcb_t *utcb,
382  l4_umword_t *label,
383  l4_timeout_t timeout);
384 
385 #endif
386 
405 l4_ipc(l4_cap_idx_t dest,
406  l4_utcb_t *utcb,
407  l4_umword_t flags,
408  l4_umword_t slabel,
409  l4_msgtag_t tag,
410  l4_umword_t *rlabel,
411  l4_timeout_t timeout) L4_NOTHROW;
412 
427 L4_INLINE l4_msgtag_t
429 
442 L4_INLINE int
443 l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
444  l4_msgtag_t *tag) L4_NOTHROW;
445 
446 /*
447  * \internal
448  * \ingroup l4_ipc_api
449  */
450 L4_INLINE int
451 l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
452  l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
453 
454 
455 /************************************************************************
456  * Implementations
457  **********************/
458 
459 L4_INLINE long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW
460 { return -(L4_EIPC_LO + ipc_error_code); }
461 
462 L4_INLINE l4_msgtag_t
464  l4_msgtag_t tag,
465  l4_timeout_t timeout) L4_NOTHROW
466 {
467  return l4_ipc(dest, utcb, L4_SYSF_CALL, 0, tag, 0, timeout);
468 }
469 
470 L4_INLINE l4_msgtag_t
472  l4_umword_t *label,
473  l4_timeout_t timeout) L4_NOTHROW
474 {
475  return l4_ipc(L4_INVALID_CAP, utcb, L4_SYSF_REPLY_AND_WAIT, 0, tag, label, timeout);
476 }
477 
478 L4_INLINE l4_msgtag_t
480  l4_msgtag_t tag,
481  l4_umword_t *src,
482  l4_timeout_t timeout) L4_NOTHROW
483 {
484  return l4_ipc(dest, utcb, L4_SYSF_SEND_AND_WAIT, 0, tag, src, timeout);
485 }
486 
487 L4_INLINE l4_msgtag_t
489  l4_msgtag_t tag,
490  l4_timeout_t timeout) L4_NOTHROW
491 {
492  return l4_ipc(dest, utcb, L4_SYSF_SEND, 0, tag, 0, timeout);
493 }
494 
495 L4_INLINE l4_msgtag_t
497  l4_timeout_t timeout) L4_NOTHROW
498 {
499  l4_msgtag_t t;
500  t.raw = 0;
501  return l4_ipc(L4_INVALID_CAP, utcb, L4_SYSF_WAIT, 0, t, src, timeout);
502 }
503 
504 L4_INLINE l4_msgtag_t
506  l4_timeout_t timeout) L4_NOTHROW
507 {
508  l4_msgtag_t t;
509  t.raw = 0;
510  return l4_ipc(src, utcb, L4_SYSF_RECV, 0, t, 0, timeout);
511 }
512 
513 L4_INLINE l4_msgtag_t
515 { return l4_ipc_receive(L4_INVALID_CAP, NULL, timeout); }
516 
517 L4_INLINE l4_umword_t
519 {
520  if (!l4_msgtag_has_error(tag))
521  return 0;
522  return l4_utcb_tcr_u(utcb)->error & L4_IPC_ERROR_MASK;
523 }
524 
525 L4_INLINE long
526 l4_error_u(l4_msgtag_t tag, l4_utcb_t *u) L4_NOTHROW
527 {
528  if (l4_msgtag_has_error(tag))
529  return l4_ipc_to_errno(l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK);
530 
531  return l4_msgtag_label(tag);
532 }
533 
534 L4_INLINE long
536 {
537  return l4_error_u(tag, l4_utcb());
538 }
539 
540 
542 { return (l4_utcb_tcr_u(u)->error & 1) == 0; }
543 
545 { return l4_utcb_tcr_u(u)->error & 1; }
546 
548 { return l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK; }
549 
550 
551 /*
552  * \internal
553  * \ingroup l4_ipc_api
554  */
555 L4_INLINE int
556 l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
557  l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
558 {
559  l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
560  int i = l4_msgtag_words(*tag) + 2 * l4_msgtag_items(*tag);
561 
562  if (i >= L4_UTCB_GENERIC_DATA_SIZE - 1)
563  return -L4_ENOMEM;
564 
565  v->mr[i] = snd_base | L4_ITEM_MAP | L4_ITEM_CONT;
566  v->mr[i + 1] = snd_fpage.raw;
567 
568  *tag = l4_msgtag(l4_msgtag_label(*tag), l4_msgtag_words(*tag),
569  l4_msgtag_items(*tag) + 1, l4_msgtag_flags(*tag));
570  return 0;
571 }
572 
573 L4_INLINE int
574 l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
575  l4_msgtag_t *tag) L4_NOTHROW
576 {
577  return l4_sndfpage_add_u(snd_fpage, snd_base, tag, l4_utcb());
578 }
579 
580 
581 #endif /* ! __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__ */
#define L4_ALWAYS_INLINE
L4 Inline function attribute.
Definition: compiler.h:67
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:186
Error codes.
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:51
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
@ L4_INVALID_CAP
Invalid capability selector.
Definition: consts.h:141
@ L4_EIPC_LO
Communication error-range low.
Definition: err.h:70
@ L4_ENOMEM
No memory.
Definition: err.h:50
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
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:471
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:505
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:479
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:488
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:463
l4_msgtag_t l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW
Sleep for an amount of time.
Definition: ipc.h:514
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:574
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:496
@ L4_SYSF_SEND_AND_WAIT
Send-and-wait flags.
Definition: consts.h:113
@ L4_SYSF_WAIT
Wait flags (combines receive and open wait).
Definition: consts.h:105
@ L4_SYSF_CALL
Call flags (combines send and receive).
Definition: consts.h:97
@ L4_SYSF_SEND
Send-phase flag.
Definition: consts.h:58
@ L4_SYSF_REPLY_AND_WAIT
Reply-and-wait flags.
Definition: consts.h:121
@ L4_SYSF_RECV
Receive-phase flag.
Definition: consts.h:69
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag or the tag label.
Definition: ipc.h:535
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:541
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:547
l4_ipc_tcr_error_t
Error codes in the error TCR.
Definition: ipc.h:76
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:544
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:518
@ L4_IPC_SEABORTED
Send operation aborted.
Definition: ipc.h:121
@ L4_IPC_SND_ERR_MASK
Send error mask.
Definition: ipc.h:78
@ L4_IPC_RECANCELED
Receive operation canceled.
Definition: ipc.h:89
@ L4_IPC_SESNDPFTO
Send-pagefault timeout in send operation.
Definition: ipc.h:106
@ L4_IPC_SETIMEOUT
Timeout during send operation.
Definition: ipc.h:86
@ L4_IPC_ENOT_EXISTENT
Non-existing destination or source.
Definition: ipc.h:80
@ L4_IPC_ERROR_MASK
Mask for error bits.
Definition: ipc.h:77
@ L4_IPC_REMAPFAILED
Map flexpage failed in receive operation.
Definition: ipc.h:95
@ L4_IPC_SEMAPFAILED
Map flexpage failed in send operation.
Definition: ipc.h:99
@ L4_IPC_SECANCELED
Send operation canceled.
Definition: ipc.h:92
@ L4_IPC_REABORTED
Receive operation aborted.
Definition: ipc.h:118
@ L4_IPC_SERCVPFTO
Receive-pagefault timeout in send operation.
Definition: ipc.h:114
@ L4_IPC_SEMSGCUT
Cut send message.
Definition: ipc.h:128
@ L4_IPC_REMSGCUT
Cut receive message, due to message buffer is too small.
Definition: ipc.h:124
@ L4_IPC_RETIMEOUT
Timeout during receive operation.
Definition: ipc.h:83
@ L4_IPC_RESNDPFTO
Send-pagefault timeout in receive operation.
Definition: ipc.h:102
@ L4_IPC_RERCVPFTO
Receive-pagefault timeout in receive operation.
Definition: ipc.h:110
@ L4_ITEM_MAP
Identify a message item as map item.
Definition: consts.h:189
@ L4_ITEM_CONT
Denote that the following item shall be put into the same receive item as this one.
Definition: consts.h:195
unsigned l4_msgtag_items(l4_msgtag_t t) L4_NOTHROW
Get the number of typed items.
Definition: types.h:428
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:437
l4_msgtag_flags
Flags for message tags.
Definition: types.h:96
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:408
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition: types.h:424
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition: types.h:420
@ L4_UTCB_GENERIC_DATA_SIZE
Total number of message register (MRs) available.
Definition: utcb.h:47
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
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:459
Common L4 ABI Data Types.
Message tag data structure.
Definition: types.h:160
l4_mword_t raw
raw value
Definition: types.h:161
l4_umword_t error
System call error codes.
Definition: utcb.h:113
L4 flexpage type.
Definition: __l4_fpage.h:83
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Timeout pair.
Definition: __timeout.h:59