27constexpr unsigned long align_to(
unsigned long bytes,
unsigned long align)
noexcept
28{
return (bytes + align - 1) & ~(align - 1); }
37constexpr unsigned long align_to(
unsigned long bytes)
noexcept
38{
return align_to(bytes, __alignof(T)); }
50constexpr bool check_size(
unsigned offset,
unsigned limit)
noexcept
52 return offset +
sizeof(T) <= limit;
67template<
typename T,
typename CTYPE>
68inline bool check_size(
unsigned offset,
unsigned limit, CTYPE cnt)
noexcept
70 if (
L4_UNLIKELY(
sizeof(CTYPE) <=
sizeof(
unsigned) &&
71 ~0U /
sizeof(T) <=
static_cast<unsigned>(cnt)))
75 static_cast<CTYPE
>(~0U /
sizeof(T)) <= cnt))
78 return sizeof(T) * cnt <= limit - offset;
111inline int msg_add(
char *msg,
unsigned offs,
unsigned limit, T v)
noexcept
116 *
reinterpret_cast<L4::Types::Remove_const_t<T> *
>(msg + offs) = v;
117 return offs +
sizeof(T);
132inline int msg_get(
char *msg,
unsigned offs,
unsigned limit, T &v)
noexcept
137 v = *
reinterpret_cast<T *
>(msg + offs);
138 return offs +
sizeof(T);
154template<
typename T>
struct _Plain
157 static T &deref(T &v)
noexcept {
return v; }
158 static T
const &deref(T
const &v)
noexcept {
return v; }
161template<
typename T>
struct _Plain<T *>
164 static T &deref(T *v)
noexcept {
return *v; }
167template<
typename T>
struct _Plain<T &>
170 static T &deref(T &v)
noexcept {
return v; }
174template<
typename T>
struct _Plain<T const &>
177 static T
const &deref(T
const &v)
noexcept {
return v; }
180template<
typename T>
struct _Plain<T const *>
183 static T
const &deref(T
const *v)
noexcept {
return *v; }
208 static constexpr int to_msg_data([[maybe_unused]]
char *msg,
unsigned offset,
209 [[maybe_unused]]
unsigned limit,
210 [[maybe_unused]] T
const &arg)
noexcept
226 static constexpr int to_msg_items([[maybe_unused]]
char *msg,
unsigned offset,
227 [[maybe_unused]]
unsigned limit,
228 [[maybe_unused]] T
const &arg)
noexcept
246 [[maybe_unused]]
unsigned limit,
247 [[maybe_unused]] T
const &arg)
noexcept
265 [[maybe_unused]]
unsigned limit,
266 [[maybe_unused]] T &arg)
noexcept
284 [[maybe_unused]]
unsigned limit,
285 [[maybe_unused]] T &arg)
noexcept
311 [[maybe_unused]]
unsigned limit,
312 [[maybe_unused]] T
const &arg)
noexcept
330 [[maybe_unused]]
unsigned limit,
331 [[maybe_unused]] T
const &arg)
noexcept
350 [[maybe_unused]]
unsigned limit,
351 [[maybe_unused]] T &arg)
noexcept
369 [[maybe_unused]]
unsigned limit,
370 [[maybe_unused]] T &arg)
noexcept
388 [[maybe_unused]]
unsigned limit,
389 [[maybe_unused]] T &arg)
noexcept
407template<
typename MTYPE>
410 static_assert(L4::Types::Is_trivially_copyable_v<MTYPE>,
411 "Only trivially copyable types can be used as IPC arguments");
414 static int to_msg_data(
char *msg,
unsigned offset,
unsigned limit,
415 MTYPE
const &arg)
noexcept
437template<
typename MTYPE>
440 static_assert(L4::Types::Is_trivially_copyable_v<MTYPE>,
441 "Only trivially copyable types can be used as IPC arguments");
444 static int to_svr_data(
char *msg,
unsigned offset,
unsigned limit,
455 return offs +
sizeof(MTYPE);
460 MTYPE
const &arg)
noexcept
471template<
typename T>
struct Elem
487template<
typename T>
struct Elem<T &>
489 using arg_type = T &;
492 using svr_arg_type = T &;
493 static constexpr bool Is_optional =
false;
494 static constexpr bool Is_input =
false;
495 static constexpr bool Is_output =
true;
498template<
typename T>
struct Elem<T const &>
500 using arg_type = T
const &;
504 using svr_arg_type = T
const &;
505 static constexpr bool Is_optional =
false;
506 static constexpr bool Is_input =
true;
507 static constexpr bool Is_output =
false;
510template<
typename T>
struct Elem<T *> : Elem<T &>
512 using arg_type = T *;
515template<
typename T>
struct Elem<T const *> : Elem<T const &>
517 using arg_type = T
const *;
524struct _Elem :
Elem<T>
526 static_assert(Is_valid_rpc_type<T>::value,
527 "L4::Ipc::Msg::_Elem<T>: type T is not a valid RPC parameter type.");
533struct _Clnt_val_ops :
534 Clnt_val_ops<typename Detail::_Plain<T>::type> {};
537 typename ELEM = _Elem<T>,
538 typename CLNT_OPS = _Clnt_val_ops<typename ELEM::arg_type>
540struct _Clnt_xmit : CLNT_OPS {};
543 typename ELEM = _Elem<T>,
544 typename SVR_OPS = Svr_val_ops<typename ELEM::svr_type>
546struct _Svr_xmit : SVR_OPS {};
553template<
typename T>
struct Clnt_xmit : Detail::_Clnt_xmit<T> {};
557template<
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.
IPC Message related functionality.
Phase
Phase during IPC argument mashalling.
@ Buffers
Second phase: place/read items into/from MRs.
@ Items
First phase: copy bytes to/from MRs.
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.
IPC related functionality.
L4 low-level kernel interface.
Empty client side marshalling code.
static constexpr int from_msg_items(char *msg, unsigned offset, unsigned limit, T &arg) noexcept
Read IPC return items for arg from UTCB.
static constexpr int to_msg_data(char *msg, unsigned offset, unsigned limit, T const &arg) noexcept
Write IPC data of arg into UTCB.
static constexpr int to_msg_buffers(char *brs, unsigned offset, unsigned limit, T const &arg) noexcept
Setup receive buffers for object capabilities in UTCB.
static constexpr int to_msg_items(char *msg, unsigned offset, unsigned limit, T const &arg) noexcept
Write IPC send items of arg into UTCB.
static constexpr int from_msg_data(char *msg, unsigned offset, unsigned limit, T &arg) noexcept
Read IPC data for arg from UTCB.
Defines client-side handling of 'MTYPE' as RPC argument.
static int to_msg_data(char *msg, unsigned offset, unsigned limit, MTYPE const &arg) noexcept
Copy a T into the message (arg must be either MTYPE or MTYPE const &).
static int from_msg_data(char *msg, unsigned offset, unsigned limit, MTYPE &arg) noexcept
Copy data from the message to a T client reference (arg must be MTYPE &).
Helper struct to describe various aspects of an IPC argument.
T svr_type
The data type used to store the T on the server-side.
static constexpr bool Is_output
Is the argument transferred from server to client?
T arg_type
The type used in client argument list.
static constexpr bool Is_optional
Is it an optional argument?
static constexpr bool Is_input
Is the argument transferred from client to server?
T svr_arg_type
The argument type for the server-side function.
Type trait defining a valid RPC parameter type.
Empty server side marshalling code.
static constexpr int from_svr_data(char *msg, unsigned offset, unsigned limit, T const &arg) noexcept
Write IPC data of arg into UTCB.
static constexpr int to_svr_items(char *msg, unsigned offset, unsigned limit, T &arg) noexcept
Read IPC return items for arg from UTCB.
static constexpr int to_svr_data(char *msg, unsigned offset, unsigned limit, T &arg) noexcept
Read IPC data for arg from UTCB.
static constexpr int from_svr_items(char *msg, unsigned offset, unsigned limit, T const &arg) noexcept
Write IPC send items of arg into UTCB.
static constexpr int reserve_data(char *msg, unsigned offset, unsigned limit, T &arg) noexcept
Reserve IPC data bytes in UTCB.
Defines server-side handling of 'MTYPE' as RPC argument.
static int to_svr_data(char *msg, unsigned offset, unsigned limit, MTYPE &arg) noexcept
Copy data from the message to a T server reference (arg must be MTYPE &).
static int from_svr_data(char *msg, unsigned offset, unsigned limit, MTYPE const &arg) noexcept
Copy a T into the message (arg must be either MTYPE or MTYPE const &).
static int reserve_data(char *, unsigned offs, unsigned limit, MTYPE &) noexcept
Prepare a T output operand (arg must be MTYPE &).