Loading...
Searching...
No Matches
ipc.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>,
* Björn Döbel <doebel@os.inf.tu-dresden.de>,
* Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#ifndef __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__
#define __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__
#include <l4/sys/types.h>
#include <l4/sys/utcb.h>
#include <l4/sys/err.h>
/*****************************************************************************
*** IPC result checking
*****************************************************************************/
enum l4_ipc_tcr_error_t
{
L4_IPC_ERROR_MASK = 0x1F,
L4_IPC_SND_ERR_MASK = 0x01,
L4_IPC_ENOT_EXISTENT = 0x04,
L4_IPC_RETIMEOUT = 0x03,
L4_IPC_SETIMEOUT = 0x02,
L4_IPC_RECANCELED = 0x07,
L4_IPC_SECANCELED = 0x06,
L4_IPC_REMAPFAILED = 0x11,
L4_IPC_SEMAPFAILED = 0x10,
L4_IPC_RESNDPFTO = 0x0b,
L4_IPC_SESNDPFTO = 0x0a,
L4_IPC_RERCVPFTO = 0x0d,
L4_IPC_SERCVPFTO = 0x0c,
L4_IPC_REABORTED = 0x0f,
L4_IPC_SEABORTED = 0x0e,
L4_IPC_REMSGCUT = 0x09,
L4_IPC_SEMSGCUT = 0x08,
};
L4_INLINE l4_umword_t
l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE long
l4_error(l4_msgtag_t tag) L4_NOTHROW;
L4_INLINE long
l4_error_u(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
/*****************************************************************************
*** IPC results
*****************************************************************************/
L4_INLINE int l4_ipc_is_snd_error(l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int l4_ipc_is_rcv_error(l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int l4_ipc_error_code(l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW;
/*****************************************************************************
*** IPC calls
*****************************************************************************/
L4_INLINE 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;
L4_INLINE l4_msgtag_t
l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label,
l4_timeout_t timeout) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb,
l4_timeout_t timeout) L4_NOTHROW;
L4_INLINE 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;
L4_INLINE 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;
L4_INLINE 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;
#if 0
L4_INLINE l4_msgtag_t
l4_ipc_wait_next_period(l4_utcb_t *utcb,
l4_umword_t *label,
l4_timeout_t timeout);
#endif
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;
L4_INLINE l4_msgtag_t
l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_ipc_sleep_ms(l4_uint32_t ms) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_ipc_sleep_us(l4_uint64_t us) L4_NOTHROW;
L4_INLINE int
l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
l4_msgtag_t *tag) L4_NOTHROW;
/*
* \internal
* \ingroup l4_ipc_api
*/
L4_INLINE int
l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
/************************************************************************
* Implementations
**********************/
L4_INLINE long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW
{ return -(L4_EIPC_LO + ipc_error_code); }
L4_INLINE 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
{
return l4_ipc(object, utcb, L4_SYSF_CALL, 0, tag, 0, timeout);
}
L4_INLINE 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
{
return l4_ipc(L4_INVALID_CAP, utcb, L4_SYSF_REPLY_AND_WAIT, 0, tag, label, timeout);
}
L4_INLINE 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
{
return l4_ipc(dest, utcb, L4_SYSF_SEND_AND_WAIT, 0, tag, label, timeout);
}
L4_INLINE 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
{
return l4_ipc(dest, utcb, L4_SYSF_SEND, 0, tag, 0, timeout);
}
L4_INLINE l4_msgtag_t
l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label,
l4_timeout_t timeout) L4_NOTHROW
{
l4_msgtag_t t;
t.raw = 0;
return l4_ipc(L4_INVALID_CAP, utcb, L4_SYSF_WAIT, 0, t, label, timeout);
}
L4_INLINE l4_msgtag_t
l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb,
l4_timeout_t timeout) L4_NOTHROW
{
l4_msgtag_t t;
t.raw = 0;
return l4_ipc(object, utcb, L4_SYSF_RECV, 0, t, 0, timeout);
}
L4_INLINE l4_msgtag_t
l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW
{ return l4_ipc_receive(L4_INVALID_CAP, NULL, timeout); }
L4_INLINE l4_msgtag_t
l4_ipc_sleep_ms(l4_uint32_t ms) L4_NOTHROW
{
l4_uint64_t us = ms * 1000ULL; // cannot overflow because ms < 2^32
return l4_ipc_sleep(l4_timeout(L4_IPC_TIMEOUT_NEVER, l4_timeout_from_us(us)));
}
L4_INLINE l4_msgtag_t
l4_ipc_sleep_us(l4_uint64_t us) L4_NOTHROW
{
return l4_ipc_sleep(l4_timeout(L4_IPC_TIMEOUT_NEVER,
l4_timeout_from_us(us)));
}
L4_INLINE l4_umword_t
l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
{
if (L4_LIKELY(!l4_msgtag_has_error(tag)))
return 0;
return l4_utcb_tcr_u(utcb)->error & L4_IPC_ERROR_MASK;
}
L4_INLINE long
l4_error_u(l4_msgtag_t tag, l4_utcb_t *u) L4_NOTHROW
{
if (L4_UNLIKELY(l4_msgtag_has_error(tag)))
return l4_ipc_to_errno(l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK);
return l4_msgtag_label(tag);
}
L4_INLINE long
l4_error(l4_msgtag_t tag) L4_NOTHROW
{
return l4_error_u(tag, l4_utcb());
}
L4_INLINE int l4_ipc_is_snd_error(l4_utcb_t *u) L4_NOTHROW
{ return (l4_utcb_tcr_u(u)->error & 1) == 0; }
L4_INLINE int l4_ipc_is_rcv_error(l4_utcb_t *u) L4_NOTHROW
{ return l4_utcb_tcr_u(u)->error & 1; }
L4_INLINE int l4_ipc_error_code(l4_utcb_t *u) L4_NOTHROW
{ return l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK; }
/*
* \internal
* \ingroup l4_ipc_api
*/
L4_INLINE int
l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
int i = l4_msgtag_words(*tag) + 2 * l4_msgtag_items(*tag);
if (i >= L4_UTCB_GENERIC_DATA_SIZE - 1)
return -L4_ENOMEM;
v->mr[i] = snd_base | L4_ITEM_MAP | L4_ITEM_CONT;
v->mr[i + 1] = snd_fpage.raw;
*tag = l4_msgtag(l4_msgtag_label(*tag), l4_msgtag_words(*tag),
l4_msgtag_items(*tag) + 1, l4_msgtag_flags(*tag));
return 0;
}
L4_INLINE int
l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
l4_msgtag_t *tag) L4_NOTHROW
{
return l4_sndfpage_add_u(snd_fpage, snd_base, tag, l4_utcb());
}
#endif /* ! __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__ */
err.h
Error codes.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_uint32_t
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
l4_uint64_t
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:31
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
L4_INVALID_CAP
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:153
L4_EIPC_LO
@ L4_EIPC_LO
Communication error-range low.
Definition err.h:60
L4_ENOMEM
@ L4_ENOMEM
No memory.
Definition err.h:39
l4_ipc_reply_and_wait
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:572
l4_ipc
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:21
l4_ipc_receive
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:602
l4_ipc_sleep_us
l4_msgtag_t l4_ipc_sleep_us(l4_uint64_t us) L4_NOTHROW
Sleep for a certain amount of microseconds.
Definition ipc.h:622
l4_ipc_send_and_wait
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:579
l4_ipc_send
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:586
l4_ipc_call
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:565
l4_ipc_sleep
l4_msgtag_t l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW
Sleep for an amount of time.
Definition ipc.h:611
l4_sndfpage_add
int l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base, l4_msgtag_t *tag) L4_NOTHROW
Add a flexpage to be sent to the UTCB.
Definition ipc.h:685
l4_ipc_wait
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:593
l4_ipc_sleep_ms
l4_msgtag_t l4_ipc_sleep_ms(l4_uint32_t ms) L4_NOTHROW
Sleep for a certain amount of milliseconds.
Definition ipc.h:615
L4_SYSF_SEND_AND_WAIT
@ L4_SYSF_SEND_AND_WAIT
Send-and-wait flags.
Definition consts.h:124
L4_SYSF_WAIT
@ L4_SYSF_WAIT
Wait flags (combines receive and open wait).
Definition consts.h:116
L4_SYSF_CALL
@ L4_SYSF_CALL
Call flags (combines send and receive).
Definition consts.h:108
L4_SYSF_SEND
@ L4_SYSF_SEND
Send-phase flag.
Definition consts.h:69
L4_SYSF_REPLY_AND_WAIT
@ L4_SYSF_REPLY_AND_WAIT
Reply-and-wait flags.
Definition consts.h:132
L4_SYSF_RECV
@ L4_SYSF_RECV
Receive-phase flag.
Definition consts.h:80
l4_error
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
Definition ipc.h:646
l4_ipc_is_snd_error
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:652
l4_ipc_error_code
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:658
l4_ipc_tcr_error_t
l4_ipc_tcr_error_t
Error codes in the error TCR.
Definition ipc.h:82
l4_ipc_is_rcv_error
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:655
l4_ipc_error
l4_umword_t l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
Get the IPC error code for an IPC operation.
Definition ipc.h:629
L4_IPC_SEABORTED
@ L4_IPC_SEABORTED
Send operation aborted.
Definition ipc.h:127
L4_IPC_SND_ERR_MASK
@ L4_IPC_SND_ERR_MASK
Send error mask.
Definition ipc.h:84
L4_IPC_RECANCELED
@ L4_IPC_RECANCELED
Receive operation canceled.
Definition ipc.h:95
L4_IPC_SESNDPFTO
@ L4_IPC_SESNDPFTO
Send-pagefault timeout in send operation.
Definition ipc.h:112
L4_IPC_SETIMEOUT
@ L4_IPC_SETIMEOUT
Timeout during send operation.
Definition ipc.h:92
L4_IPC_ENOT_EXISTENT
@ L4_IPC_ENOT_EXISTENT
Non-existing destination or source.
Definition ipc.h:86
L4_IPC_ERROR_MASK
@ L4_IPC_ERROR_MASK
Mask for error bits.
Definition ipc.h:83
L4_IPC_REMAPFAILED
@ L4_IPC_REMAPFAILED
Map flexpage failed in receive operation.
Definition ipc.h:101
L4_IPC_SEMAPFAILED
@ L4_IPC_SEMAPFAILED
Map flexpage failed in send operation.
Definition ipc.h:105
L4_IPC_SECANCELED
@ L4_IPC_SECANCELED
Send operation canceled.
Definition ipc.h:98
L4_IPC_REABORTED
@ L4_IPC_REABORTED
Receive operation aborted.
Definition ipc.h:124
L4_IPC_SERCVPFTO
@ L4_IPC_SERCVPFTO
Receive-pagefault timeout in send operation.
Definition ipc.h:120
L4_IPC_SEMSGCUT
@ L4_IPC_SEMSGCUT
Sent message truncated.
Definition ipc.h:143
L4_IPC_REMSGCUT
@ L4_IPC_REMSGCUT
Received message truncated.
Definition ipc.h:136
L4_IPC_RETIMEOUT
@ L4_IPC_RETIMEOUT
Timeout during receive operation.
Definition ipc.h:89
L4_IPC_RESNDPFTO
@ L4_IPC_RESNDPFTO
Send-pagefault timeout in receive operation.
Definition ipc.h:108
L4_IPC_RERCVPFTO
@ L4_IPC_RERCVPFTO
Receive-pagefault timeout in receive operation.
Definition ipc.h:116
L4_ITEM_MAP
@ L4_ITEM_MAP
Identify a message item as map item.
Definition consts.h:214
L4_ITEM_CONT
@ L4_ITEM_CONT
Denote that the following item shall be put into the same receive item as this one.
Definition consts.h:220
l4_msgtag_items
unsigned l4_msgtag_items(l4_msgtag_t t) L4_NOTHROW
Get the number of typed items.
Definition types.h:431
l4_msgtag_has_error
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:440
l4_msgtag
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:405
l4_msgtag_words
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition types.h:427
l4_msgtag_flags
unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
Get the flags.
Definition types.h:435
l4_msgtag_label
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:417
L4_IPC_TIMEOUT_NEVER
#define L4_IPC_TIMEOUT_NEVER
never timeout
Definition __timeout.h:74
l4_timeout
L4_CONSTEXPR l4_timeout_t l4_timeout(l4_timeout_s snd, l4_timeout_s rcv) L4_NOTHROW
Combine send and receive timeout in a timeout.
Definition __timeout.h:213
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4_ALWAYS_INLINE
#define L4_ALWAYS_INLINE
Always inline a function.
Definition compiler.h:58
L4_NOTHROW
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:161
L4_UNLIKELY
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:284
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
L4_LIKELY
#define L4_LIKELY(x)
Expression is likely to execute.
Definition compiler.h:283
l4_ipc_to_errno
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:561
types.h
Common L4 ABI Data Types.
utcb.h
UTCB definitions.
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_msgtag_t::raw
l4_mword_t raw
raw value
Definition types.h:155
l4_fpage_t
L4 flexpage type.
Definition __l4_fpage.h:76
l4_msg_regs_t
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_msg_regs_t::mr
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69
l4_timeout_t
Timeout pair.
Definition __timeout.h:53