8#pragma GCC system_header
10#include <l4/sys/cxx/ipc_basics>
221namespace L4 {
namespace Ipc {
241 enum { Is_call =
true };
269template<
unsigned RIGHTS>
272 enum { Rights = RIGHTS };
289 enum { Is_call =
false };
306template<
typename OP,
typename CLASS,
typename SIG,
typename FLAGS = Call>
313template<
typename OP,
typename CLASS,
typename FLAGS,
typename R,
315struct L4_EXPORT Rpc_inline_call<OP, CLASS, R (ARGS...), FLAGS>
317 template<
typename T>
struct Result {
typedef T result_type; };
324 typedef Rpc_inline_call type;
328 typedef CLASS class_type;
330 typedef typename Result<R>::result_type result_type;
332 typedef R ipc_type (ARGS...);
334 typedef result_type func_type (
typename _Elem<ARGS>::arg_type...);
337 typedef FLAGS flags_type;
339 template<
typename RES>
340 static typename L4::Types::Enable_if< Return_tag, RES >::type
341 return_err(
long err)
noexcept {
return l4_msgtag(err, 0, 0, 0); }
343 template<
typename RES>
344 static typename L4::Types::Enable_if< Return_tag, RES >::type
347 template<
typename RES>
348 static typename L4::Types::Enable_if< Return_tag, RES >::type
349 return_code(
l4_msgtag_t tag)
noexcept {
return tag; }
351 template<
typename RES>
352 static typename L4::Types::Enable_if< !Return_tag, RES >::type
353 return_err(
long err)
noexcept {
return err; }
355 template<
typename RES>
356 static typename L4::Types::Enable_if< !Return_tag, RES >::type
360 template<
typename RES>
361 static typename L4::Types::Enable_if< !Return_tag, RES >::type
362 return_code(
l4_msgtag_t tag)
noexcept {
return tag.label(); }
365 typename _Elem<ARGS>::arg_type ...a,
373template<typename OP, typename CLASS, typename SIG, typename FLAGS = Call>
383template<typename IPC, typename SIG> struct _Call;
386template<typename IPC, typename R, typename ...ARGS>
387struct _Call<IPC, R (ARGS...)>
390 typedef typename IPC::class_type class_type;
391 typedef typename IPC::result_type result_type;
402 result_type operator () (ARGS ...a,
l4_utcb_t *utcb =
l4_utcb()) const noexcept
403 {
return IPC::call(cap(), a..., utcb); }
412template<
typename IPC>
struct Call : _Call<IPC, typename IPC::func_type> {};
423struct L4_EXPORT Rpc_call<OP, CLASS, R (ARGS...), FLAGS> :
424 Rpc_inline_call<OP, CLASS, R (ARGS...), FLAGS>
427 typename _Elem<ARGS>::arg_type ...a,
431#define L4_INLINE_RPC_SRV_FORWARD(name) \
432 template<typename OBJ> struct fwd \
435 fwd(OBJ *o) noexcept : o(o) {} \
436 template<typename ...ARGS> long call(ARGS ...a) noexcept(noexcept(o->op_##name(a...))) \
437 { return o->op_##name(a...); } \
453#define L4_INLINE_RPC_NF(res, name, args...) \
454 struct name##_t : L4::Ipc::Msg::Rpc_inline_call<name##_t, Class, res args> \
456 typedef L4::Ipc::Msg::Rpc_inline_call<name##_t, Class, res args> type; \
457 L4_INLINE_RPC_SRV_FORWARD(name); \
453#define L4_INLINE_RPC_NF(res, name, args...) \ …
466#define L4_INLINE_RPC_NF_OP(op, res, name, args...) \
467 struct name##_t : L4::Ipc::Msg::Rpc_inline_call<name##_t, Class, res args> \
469 typedef L4::Ipc::Msg::Rpc_inline_call<name##_t, Class, res args> type; \
470 enum { Opcode = (op) }; \
471 L4_INLINE_RPC_SRV_FORWARD(name); \
466#define L4_INLINE_RPC_NF_OP(op, res, name, args...) \ …
482#define L4_INLINE_RPC(res, name, args, attr...) res name args
484#define L4_INLINE_RPC(res, name, args...) \
485 L4_INLINE_RPC_NF(res, name, args); L4::Ipc::Msg::Call<name##_t> name
497#define L4_INLINE_RPC_OP(op, res, name, args, attr...) res name args
499#define L4_INLINE_RPC_OP(op, res, name, args...) \
500 L4_INLINE_RPC_NF_OP(op, res, name, args); L4::Ipc::Msg::Call<name##_t> name
510#define L4_RPC_NF(res, name, args...) \
511 struct name##_t : L4::Ipc::Msg::Rpc_call<name##_t, Class, res args> \
513 typedef L4::Ipc::Msg::Rpc_call<name##_t, Class, res args> type; \
514 L4_INLINE_RPC_SRV_FORWARD(name); \
510#define L4_RPC_NF(res, name, args...) \ …
525#define L4_RPC_NF_OP(op, res, name, args...) \
526 struct name##_t : L4::Ipc::Msg::Rpc_call<name##_t, Class, res args> \
528 typedef L4::Ipc::Msg::Rpc_call<name##_t, Class, res args> type; \
529 enum { Opcode = (op) }; \
530 L4_INLINE_RPC_SRV_FORWARD(name); \
525#define L4_RPC_NF_OP(op, res, name, args...) \ …
541#define L4_RPC(res, name, args, attr...) res name args
543#define L4_RPC(res, name, args...) \
544 L4_RPC_NF(res, name, args); L4::Ipc::Msg::Call<name##_t> name
556#define L4_RPC_OP(op, res, name, args, attr...) res name args
558#define L4_RPC_OP(op, res, name, args...) \
559 L4_RPC_NF_OP(op, res, name, args); L4::Ipc::Msg::Call<name##_t> name
572template<
typename ...ARGS>
576 template<
typename DIR>
577 static constexpr int write(
char *,
int offset,
int)
noexcept
580 template<
typename DIR>
581 static constexpr int read(
char *,
int offset,
int,
long)
noexcept
587template<
typename A,
typename ...M>
588struct Buf<A, M...> : Buf<M...>
590 typedef Buf<M...> Base;
592 typedef Clnt_xmit<A> xmit;
593 typedef typename _Elem<A>::arg_type arg_type;
594 typedef Detail::_Plain<arg_type> plain;
596 template<
typename DIR>
598 write(
char *base,
int offset,
int limit,
599 arg_type a,
typename _Elem<M>::arg_type ...m)
noexcept
601 offset = xmit::to_msg(base, offset, limit, plain::deref(a),
602 typename DIR::dir(),
typename DIR::cls());
603 return Base::template write<DIR>(base, offset, limit, m...);
606 template<
typename DIR>
608 read(
char *base,
int offset,
int limit,
long ret,
609 arg_type a,
typename _Elem<M>::arg_type ...m)
noexcept
611 int r = xmit::from_msg(base, offset, limit, ret, plain::deref(a),
612 typename DIR::dir(),
typename DIR::cls());
614 return Base::template read<DIR>(base, r, limit, ret, m...);
616 if (_Elem<A>::Is_optional)
617 return Base::template read<DIR>(base, offset, limit, ret, m...);
623template <
typename ...ARGS>
struct _Part
626 typedef Buf<ARGS...> Data;
628 template<
typename DIR>
629 static int write(
void *b,
int offset,
int limit,
630 typename _Elem<ARGS>::arg_type ...m)
noexcept
632 char *buf =
static_cast<char *
>(b);
633 int r = Data::template write<DIR>(buf, offset, limit, m...);
639 template<
typename DIR>
640 static int read(
void *b,
int offset,
int limit,
long ret,
641 typename _Elem<ARGS>::arg_type ...m)
noexcept
643 char *buf =
static_cast<char *
>(b);
644 int r = Data::template read<DIR>(buf, offset, limit, ret, m...);
657template<
typename IPC_TYPE,
typename OPCODE =
void>
661template<
typename R,
typename ...ARGS>
662struct Part<R (ARGS...), void> : _Part<ARGS...>
665 typedef Buf<ARGS...> Data;
668 template<
typename DIR>
669 static int write_op(
void *b,
int offset,
int limit,
671 typename _Elem<ARGS>::arg_type ...m)
noexcept
673 char *buf =
static_cast<char *
>(b);
674 int r = Data::template write<DIR>(buf, offset, limit, m...);
682template<
typename OPCODE,
typename R,
typename ...ARGS>
683struct Part<R (ARGS...), OPCODE> : _Part<ARGS...>
685 typedef OPCODE opcode_type;
687 typedef Buf<opcode_type, ARGS...> Data;
690 template<
typename DIR>
691 static int write_op(
void *b,
int offset,
int limit,
692 opcode_type op,
typename _Elem<ARGS>::arg_type ...m)
noexcept
694 char *buf =
static_cast<char *
>(b);
695 int r = Data::template write<DIR>(buf, offset, limit, op, m...);
710template<
typename OP,
typename CLASS,
typename FLAGS,
typename R,
713Rpc_inline_call<OP, CLASS, R (ARGS...), FLAGS>::
715 typename _Elem<ARGS>::arg_type ...a,
718 using namespace Ipc::Msg;
720 typedef typename Kobject_typeid<CLASS>::Iface::Rpcs Rpcs;
721 typedef typename Rpcs::template Rpc<OP> Opt;
722 typedef Detail::Part<ipc_type, typename Rpcs::opcode_type> Args;
728 Args::template write_op<Do_in_data>(mrs->
mr, 0, Mr_bytes,
732 return return_err<R>(send_bytes);
734 send_bytes = align_to<l4_umword_t>(send_bytes);
735 int const send_words = send_bytes /
Word_bytes;
738 Args::template write<Do_in_items>(&mrs->
mr[send_words], 0,
739 Mr_bytes - send_bytes, a...);
742 return return_err<R>(item_bytes);
755 Args::template write<Do_rcv_buffers>(brs->
br, 0, Br_bytes - Word_bytes,
759 return return_err<R>(bytes);
767 t =
l4_msgtag(CLASS::Protocol, send_words, send_items, 0);
769 if (flags_type::Is_call)
775 return return_ipc_err<R>(t, utcb);
784 return return_ipc_err<R>(t, utcb);
791 return return_err<R>(r);
796 int err = Args::template read<Do_out_data>(mrs->
mr, 0, rcv_bytes, r, a...);
804 err = Args::template read<Do_out_items>(&mrs->
mr[t.
words()], 0, item_limit,
810 return return_code<R>(t);
Type information handling.
l4_cap_idx_t cap() const noexcept
Return capability selector.
C++ interface for capabilities.
unsigned long l4_cap_idx_t
Capability selector type.
@ L4_CAP_MASK
Mask to get only the relevant bits of an l4_cap_idx_t.
@ L4_EMSGTOOSHORT
Message too short.
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).
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).
int l4_ipc_error_code(l4_utcb_t *utcb) L4_NOTHROW
Get the error condition of the last invocation from the TCR.
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
#define L4_IPC_SEND_TIMEOUT_0
0 send timeout
#define L4_IPC_NEVER
never timeout
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
#define L4_LIKELY(x)
Expression is likely to execute.
long l4_ipc_to_errno(unsigned long ipc_error_code) L4_NOTHROW
Get a negative error code for the given IPC error code.
@ Item_bytes
number of bytes for one message item
@ Word_bytes
number of bytes for one message word
L4 low-level kernel interface.
RPC attribute for an RPC call with required rights.
RPC attribute for an RPC call, with zero send timeout.
RPC attribute for a standard RPC call.
RPC attribute for a send-only RPC.
Compare two data types for equality.
Encapsulation of the buffer-registers block in the UTCB.
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
l4_umword_t bdr
Buffer descriptor.
Message tag data structure.
long label() const L4_NOTHROW
Get the protocol value.
bool has_error() const L4_NOTHROW
Test if flags indicate an error.
unsigned words() const L4_NOTHROW
Get the number of untyped words.
unsigned items() const L4_NOTHROW
Get the number of typed items.
unsigned flags() const L4_NOTHROW
Get the flags value.
Encapsulation of the message-register block in the UTCB.
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.