10#include <l4/sys/utcb.h>
30constexpr unsigned long align_to(
unsigned long bytes,
unsigned long align)
noexcept
31{
return (bytes + align - 1) & ~(align - 1); }
30constexpr unsigned long align_to(
unsigned long bytes,
unsigned long align)
noexcept {
…}
40constexpr unsigned long align_to(
unsigned long bytes)
noexcept
41{
return align_to(bytes, __alignof(T)); }
40constexpr unsigned long align_to(
unsigned long bytes)
noexcept {
…}
53constexpr bool check_size(
unsigned offset,
unsigned limit)
noexcept
55 return offset +
sizeof(T) <= limit;
53constexpr bool check_size(
unsigned offset,
unsigned limit)
noexcept {
…}
70template<
typename T,
typename CTYPE>
71inline bool check_size(
unsigned offset,
unsigned limit, CTYPE cnt)
noexcept
73 if (
L4_UNLIKELY(
sizeof(CTYPE) <=
sizeof(
unsigned) &&
74 ~0U /
sizeof(T) <=
static_cast<unsigned>(cnt)))
78 static_cast<CTYPE
>(~0U /
sizeof(T)) <= cnt))
81 return sizeof(T) * cnt <= limit - offset;
71inline bool check_size(
unsigned offset,
unsigned limit, CTYPE cnt)
noexcept {
…}
114inline int msg_add(
char *msg,
unsigned offs,
unsigned limit, T v)
noexcept
116 offs = align_to<T>(offs);
119 *
reinterpret_cast<typename L4::Types::Remove_const<T>::type *
>(msg + offs) = v;
120 return offs +
sizeof(T);
114inline int msg_add(
char *msg,
unsigned offs,
unsigned limit, T v)
noexcept {
…}
135inline int msg_get(
char *msg,
unsigned offs,
unsigned limit, T &v)
noexcept
137 offs = align_to<T>(offs);
140 v = *
reinterpret_cast<T *
>(msg + offs);
141 return offs +
sizeof(T);
135inline int msg_get(
char *msg,
unsigned offs,
unsigned limit, T &v)
noexcept {
…}
171template<
typename T>
struct _Plain
174 static T deref(T v)
noexcept {
return v; }
177template<
typename T>
struct _Plain<T *>
180 static T &deref(T *v)
noexcept {
return *v; }
183template<
typename T>
struct _Plain<T &>
186 static T &deref(T &v)
noexcept {
return v; }
190template<
typename T>
struct _Plain<T const &>
193 static T
const &deref(T
const &v)
noexcept {
return v; }
196template<
typename T>
struct _Plain<T const *>
199 static T
const &deref(T
const *v)
noexcept {
return *v; }
210template<
typename MTYPE,
typename DIR,
typename CLASS>
struct Clnt_val_ops;
212template<
typename T>
struct Clnt_noops
214 template<
typename A,
typename B>
215 static constexpr int to_msg(
char *,
unsigned offset,
unsigned, T, A, B)
noexcept
219 template<
typename A,
typename B>
220 static constexpr int from_msg(
char *,
unsigned offset,
unsigned,
long, T
const &, A, B)
noexcept
224template<
typename T>
struct Svr_noops
226 template<
typename A,
typename B>
227 static constexpr int from_svr(
char *,
unsigned offset,
unsigned,
long, T, A, B)
noexcept
231 template<
typename A,
typename B>
232 static constexpr int to_svr(
char *,
unsigned offset,
unsigned, T, A, B)
noexcept
236template<
typename MTYPE,
typename CLASS>
237struct Clnt_val_ops<MTYPE, Dir_in, CLASS> : Clnt_noops<MTYPE>
239 using Clnt_noops<MTYPE>::to_msg;
241 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
242 MTYPE arg, Dir_in, CLASS)
noexcept
243 {
return msg_add<MTYPE>(msg, offset, limit, arg); }
247template<
typename MTYPE,
typename CLASS>
248struct Clnt_val_ops<MTYPE, Dir_out, CLASS> : Clnt_noops<MTYPE>
250 using Clnt_noops<MTYPE>::from_msg;
252 static int from_msg(
char *msg,
unsigned offset,
unsigned limit,
long,
253 MTYPE &arg, Dir_out, CLASS)
noexcept
254 {
return msg_get<MTYPE>(msg, offset, limit, arg); }
264template<
typename MTYPE,
typename DIR,
typename CLASS>
struct Svr_val_ops;
266template<
typename MTYPE,
typename CLASS>
269 using Svr_noops<MTYPE>::to_svr;
271 static int to_svr(
char *msg,
unsigned offset,
unsigned limit,
272 MTYPE &arg,
Dir_in, CLASS)
noexcept
273 {
return msg_get<MTYPE>(msg, offset, limit, arg); }
276template<
typename MTYPE,
typename CLASS>
277struct Svr_val_ops<MTYPE, Dir_out, CLASS> : Svr_noops<MTYPE>
279 using Svr_noops<MTYPE>::to_svr;
280 static int to_svr(
char *,
unsigned offs,
unsigned limit,
281 MTYPE &, Dir_out, CLASS)
noexcept
283 offs = align_to<MTYPE>(offs);
286 return offs +
sizeof(MTYPE);
289 using Svr_noops<MTYPE>::from_svr;
291 static int from_svr(
char *msg,
unsigned offset,
unsigned limit,
long,
292 MTYPE arg, Dir_out, CLASS)
noexcept
293 {
return msg_add<MTYPE>(msg, offset, limit, arg); }
296template<
typename T>
struct Elem
303 typedef T svr_arg_type;
305 enum { Is_optional =
false };
309template<
typename T>
struct Elem<T &>
314 typedef T &svr_arg_type;
315 enum { Is_optional =
false };
318template<
typename T>
struct Elem<T const &>
320 typedef T
const &arg_type;
324 typedef T
const &svr_arg_type;
325 enum { Is_optional =
false };
328template<
typename T>
struct Elem<T *> : Elem<T &>
333template<
typename T>
struct Elem<T const *> : Elem<T const &>
335 typedef T
const *arg_type;
344template<
typename T,
bool B>
struct Error_invalid_rpc_parameter_used;
345template<
typename T>
struct Error_invalid_rpc_parameter_used<T, true> {};
347#if __cplusplus >= 201103L
349struct _Elem : Elem<T>
351 static_assert(Is_valid_rpc_type<T>::value,
352 "L4::Ipc::Msg::_Elem<T>: type T is not a valid RPC parameter type.");
356struct _Elem : Elem<T>,
357 Error_invalid_rpc_parameter_used<T, Is_valid_rpc_type<T>::value>
362template<
typename T>
struct Class : Cls_data {};
363template<
typename T>
struct Direction : Dir_in {};
364template<
typename T>
struct Direction<T const &> : Dir_in {};
365template<
typename T>
struct Direction<T const *> : Dir_in {};
366template<
typename T>
struct Direction<T &> : Dir_out {};
367template<
typename T>
struct Direction<T *> : Dir_out {};
369template<
typename T>
struct _Clnt_noops :
370 Clnt_noops<typename Detail::_Plain<typename _Elem<T>::arg_type>::type>
375template<
typename T,
typename DIR,
typename CLASS>
376struct _Clnt_val_ops :
377 Clnt_val_ops<typename Detail::_Plain<T>::type, DIR, CLASS> {};
380 typename ELEM = _Elem<T>,
381 typename CLNT_OPS = _Clnt_val_ops<
typename ELEM::arg_type,
382 typename Direction<T>::type,
383 typename Class<typename Detail::_Plain<T>::type>::type>
385struct _Clnt_xmit : CLNT_OPS {};
388 typename ELEM = _Elem<T>,
389 typename SVR_OPS = Svr_val_ops<
typename ELEM::svr_type,
390 typename Direction<T>::type,
391 typename Class<typename Detail::_Plain<T>::type>::type>
393struct _Svr_xmit : SVR_OPS {};
396template<
typename T>
struct Clnt_xmit : Detail::_Clnt_xmit<T> {};
397template<
typename T>
struct Svr_xmit : Detail::_Svr_xmit<T> {};
unsigned long l4_umword_t
Unsigned machine word.
@ L4_EMSGTOOLONG
Message too long.
@ L4_EMSGTOOSHORT
Message too short.
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
constexpr bool check_size(unsigned offset, unsigned limit) noexcept
Check if there is enough space for T from offset to limit.
constexpr unsigned long align_to(unsigned long bytes, unsigned long align) noexcept
Pad bytes to the given alignment align (in bytes)
@ Br_bytes
number of bytes available in the UTCB buffer registers
@ 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
int msg_add(char *msg, unsigned offs, unsigned limit, T v) noexcept
Add some data to a message at offs.
int msg_get(char *msg, unsigned offs, unsigned limit, T &v) noexcept
Get some data from a message at offs.
L4 low-level kernel interface.
Defines client-side handling of ‘MTYPE’ as RPC argument.
Marker type for receive buffer values.
Marker type for data values.
Marker type for item values.
Marker type for input values.
Marker type for output values.
Marker for receive buffers.
Type trait defining a valid RPC parameter type.
Defines server-side handling for MTYPE server arguments.