8#pragma GCC system_header
10#include <l4/sys/cxx/ipc_basics>
12#include <l4/sys/cxx/limits>
23template<
typename T>
struct Sizeof {
enum { size =
sizeof(T) }; };
24template<>
struct Sizeof<void> {
enum { size = 0 }; };
29template<
typename ...>
struct Arg_pack
31 template<
typename DIR>
32 unsigned get(
char *,
unsigned offset,
unsigned)
35 template<
typename DIR>
36 unsigned set(
char *,
unsigned offset,
unsigned,
l4_ret_t)
39 template<
typename F,
typename ...ARGS>
40 decltype(
auto) call(F f, ARGS ...args)
41 {
return f(args...); }
43 template<
typename O,
typename FUNC,
typename ...ARGS>
44 auto obj_call(O *o, ARGS ...args)
45 ->
decltype(
typename FUNC::template fwd<O>(o).template call<ARGS...>(args...))
47 typedef typename FUNC::template fwd<O> Fwd;
48 using Idl_ret =
typename FUNC::result_type;
49 using Svr_ret =
decltype(Fwd(o).template call<ARGS...>(args...));
50 auto ret = Fwd(o).template call<ARGS...>(args...);
52 using L4::Types::numeric_limits;
55 if constexpr (numeric_limits<Svr_ret>::min() < numeric_limits<Idl_ret>::min())
57 if (
L4_UNLIKELY(ret < numeric_limits<Idl_ret>::min()))
64 if constexpr (numeric_limits<Svr_ret>::max() > numeric_limits<Idl_ret>::max())
66 l4_assert(ret <= numeric_limits<Idl_ret>::max());
67 if (
L4_UNLIKELY(ret > numeric_limits<Idl_ret>::max()))
72 if constexpr (numeric_limits<Svr_ret>::min() < numeric_limits<l4_msgtag_t>::min())
74 if (
L4_UNLIKELY(ret < numeric_limits<l4_msgtag_t>::min()))
77 if constexpr (numeric_limits<Svr_ret>::max() > numeric_limits<l4_msgtag_t>::max())
79 l4_assert(ret <= numeric_limits<l4_msgtag_t>::max());
80 if (
L4_UNLIKELY(ret > numeric_limits<l4_msgtag_t>::max()))
91template<
typename T,
typename SVR_TYPE,
typename ...M>
92struct Svr_arg : Svr_xmit<T>, Arg_pack<M...>
94 typedef Arg_pack<M...> Base;
96 typedef SVR_TYPE svr_type;
97 typedef typename _Elem<T>::svr_arg_type svr_arg_type;
101 template<
typename DIR>
102 int get(
char *msg,
unsigned offset,
unsigned limit)
104 typedef Svr_xmit<T> ct;
105 int r = ct::to_svr(msg, offset, limit, this->v,
106 typename DIR::dir(),
typename DIR::cls());
108 return Base::template get<DIR>(msg, r, limit);
110 if (_Elem<T>::Is_optional)
113 return Base::template get<DIR>(msg, offset, limit);
118 template<
typename DIR>
119 int set(
char *msg,
unsigned offset,
unsigned limit,
l4_ret_t ret)
121 typedef Svr_xmit<T> ct;
122 int r = ct::from_svr(msg, offset, limit, ret, this->v,
123 typename DIR::dir(),
typename DIR::cls());
126 return Base::template set<DIR>(msg, r, limit, ret);
129 template<
typename F,
typename ...ARGS>
130 decltype(
auto) call(F f, ARGS ...args)
133 return Base::template
134 call<F, ARGS..., svr_arg_type>(f, args..., this->v);
137 template<
typename O,
typename FUNC,
typename ...ARGS>
138 decltype(
auto) obj_call(O *o, ARGS ...args)
141 return Base::template
142 obj_call<O, FUNC, ARGS..., svr_arg_type>(o, args..., this->v);
146template<
typename T,
typename ...M>
147struct Svr_arg<T, void, M...> : Arg_pack<M...>
149 typedef Arg_pack<M...> Base;
151 template<
typename DIR>
152 int get(
char *msg,
unsigned offset,
unsigned limit)
153 {
return Base::template get<DIR>(msg, offset, limit); }
155 template<
typename DIR>
156 int set(
char *msg,
unsigned offset,
unsigned limit,
l4_ret_t ret)
157 {
return Base::template set<DIR>(msg, offset, limit, ret); }
159 template<
typename F,
typename ...ARGS>
160 decltype(
auto) call(F f, ARGS ...args)
162 return Base::template call<F, ARGS...>(f, args...);
165 template<
typename O,
typename FUNC,
typename ...ARGS>
166 decltype(
auto) obj_call(O *o, ARGS ...args)
168 return Base::template obj_call<O, FUNC, ARGS...>(o, args...);
172template<
typename A,
typename ...M>
173struct Arg_pack<A, M...> : Svr_arg<A, typename _Elem<A>::svr_type, M...>
185template<
typename R,
typename ...ARGS>
186struct Svr_arg_pack<R (ARGS...)> : Detail::Arg_pack<ARGS...>
188 typedef Detail::Arg_pack<ARGS...> Base;
189 template<
typename DIR>
190 int get(
void *msg,
unsigned offset,
unsigned limit)
192 char *buf =
static_cast<char *
>(msg);
193 return Base::template get<DIR>(buf, offset, limit);
196 template<
typename DIR>
197 int set(
void *msg,
unsigned offset,
unsigned limit,
l4_ret_t ret)
199 char *buf =
static_cast<char *
>(msg);
200 return Base::template set<DIR>(buf, offset, limit, ret);
207template<
typename IPC_TYPE,
typename O,
typename ...ARGS>
211 typedef Svr_arg_pack<typename IPC_TYPE::rpc::ipc_type> Pack;
214 Do_reply = IPC_TYPE::rpc::flags_type::Is_call,
226 int in_pos = Detail::Sizeof<typename IPC_TYPE::opcode_type>::size;
230 in_pos = pack.template get<Do_in_data>(&mrs->
mr[0], in_pos, in_bytes);
239 in_pos = pack.template get<Do_in_items>(&mrs->
mr[tag.
words()], 0,
245 asm volatile (
"" :
"=m" (mrs->
mr));
248 auto ret = pack.template obj_call<O,
typename IPC_TYPE::rpc, ARGS...>(o, args...);
259 int bytes = pack.template set<Do_out_data>(mrs->
mr, 0,
Mr_bytes, ret);
264 bytes = pack.template set<Do_out_items>(&mrs->
mr[words], 0,
276template<
typename RPCS,
typename OPCODE_TYPE>
279template<
typename CLASS>
280struct Dispatch_call<L4::Typeid::Raw_ipc<CLASS>, void>
282 template<
typename OBJ,
typename ...ARGS>
284 call(OBJ *o,
l4_utcb_t *utcb, l4_msgtag_t tag, ARGS ...a)
286 return o->op_dispatch(utcb, tag, a...);
290template<
typename RPCS>
291struct Dispatch_call<RPCS, void>
293 constexpr static unsigned rmask()
294 {
return RPCS::rpc::flags_type::Rights & 3UL; }
296 template<
typename OBJ,
typename ...ARGS>
298 call(OBJ *o,
l4_utcb_t *utcb, l4_msgtag_t tag,
unsigned rights, ARGS ...a)
300 if ((rights & rmask()) != rmask())
303 typedef L4::Typeid::Rights<typename RPCS::rpc::class_type> Rights;
304 return handle_svr_obj_call<RPCS>(o, utcb, tag,
305 Rights(rights), a...);
310template<
typename RPCS,
typename OPCODE_TYPE>
313 constexpr static unsigned rmask()
314 {
return RPCS::rpc::flags_type::Rights & 3UL; }
316 template<
typename OBJ,
typename ...ARGS>
318 _call(OBJ *o,
l4_utcb_t *utcb, l4_msgtag_t tag,
unsigned rights, OPCODE_TYPE op, ARGS ...a)
320 if (L4::Types::Same<typename RPCS::opcode_type, void>::value
321 || RPCS::Opcode == op)
323 if ((rights & rmask()) != rmask())
326 typedef L4::Typeid::Rights<typename RPCS::rpc::class_type> Rights;
327 return handle_svr_obj_call<RPCS>(o, utcb, tag,
328 Rights(rights), a...);
330 return Dispatch_call<typename RPCS::next, OPCODE_TYPE>::template
331 _call<OBJ, ARGS...>(o, utcb, tag, rights, op, a...);
334 template<
typename OBJ,
typename ...ARGS>
336 call(OBJ *o,
l4_utcb_t *utcb, l4_msgtag_t tag,
unsigned rights, ARGS ...a)
340 typedef Svr_xmit<OPCODE_TYPE> S;
341 l4_ret_t err = S::to_svr(
reinterpret_cast<char *
>(l4_utcb_mr_u(utcb)->mr), 0,
342 limit, op, Dir_in(), Cls_data());
346 return _call<OBJ, ARGS...>(o, utcb, tag, rights, op, a...);
351struct Dispatch_call<Typeid::Detail::Rpcs_end, void>
353 template<
typename OBJ,
typename ...ARGS>
355 _call(OBJ *,
l4_utcb_t *, l4_msgtag_t,
unsigned,
int, ARGS ...)
358 template<
typename OBJ,
typename ...ARGS>
360 call(OBJ *,
l4_utcb_t *, l4_msgtag_t,
unsigned, ARGS ...)
364template<
typename OPCODE_TYPE>
365struct Dispatch_call<Typeid::Detail::Rpcs_end, OPCODE_TYPE> :
366 Dispatch_call<Typeid::Detail::Rpcs_end, void> {};
368template<
typename RPCS,
typename OBJ,
typename ...ARGS>
370dispatch_call(OBJ *o,
l4_utcb_t *utcb, l4_msgtag_t tag,
unsigned rights, ARGS ...a)
372 return Dispatch_call<typename RPCS::type, typename RPCS::opcode_type>::template
373 call<OBJ, ARGS...>(o, utcb, tag, rights, a...);
Type information handling.
@ L4_EMSGTOOLONG
Message too long.
@ L4_EMSGERRRANGE
Error code range error.
@ L4_EMSGTOOSHORT
Message too short.
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
#define L4_LIKELY(x)
Expression is likely to execute.
Interface Definition Language.
l4_int16_t l4_ret_t
Return value of an IPC call as well as an RPC call.
IPC Message related functionality.
@ Item_words
number of message words for one message item
@ Mr_bytes
number of bytes available in the UTCB message registers
@ Item_bytes
number of bytes for one message item
@ Word_bytes
number of bytes for one message word
@ Mr_words
number of message words available in the UTCB
IPC related functionality.
L4 low-level kernel interface.
Server-side RPC arguments data structure used to provide arguments to the server-side implementation ...
Message tag data structure.
unsigned words() const L4_NOTHROW
Get the number of untyped words.
unsigned items() const L4_NOTHROW
Get the number of typed items.
Low-level assert implementation.
#define l4_assert(expr)
Low-level assert.
Encapsulation of the message-register block in the UTCB.
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.