8#pragma GCC system_header
15template<
typename T,
template <
typename X>
class B >
16struct Generic_va_type : B<T>
18 enum { Id = B<T>::Id };
20 using Ret_value = T
const &;
23 static Ret_value value(
void const *d)
24 {
return *
reinterpret_cast<Value
const *
>(d); }
26 static void const *addr_of(Value
const &v) {
return &v; }
28 static unsigned size(
void const *) {
return sizeof(T); }
30 static L4_varg_type unsigned_id()
32 return static_cast<L4_varg_type
>(Id & ~L4_VARG_TYPE_SIGN);
35 static L4_varg_type signed_id()
37 return static_cast<L4_varg_type
>(Id | L4_VARG_TYPE_SIGN);
40 static L4_varg_type id()
42 return static_cast<L4_varg_type
>(Id);
46template<
typename T >
struct Va_type_id;
47template<>
struct Va_type_id<
l4_umword_t> {
enum { Id = L4_VARG_TYPE_UMWORD }; };
48template<>
struct Va_type_id<
l4_mword_t> {
enum { Id = L4_VARG_TYPE_MWORD }; };
49template<>
struct Va_type_id<l4_fpage_t> {
enum { Id = L4_VARG_TYPE_FPAGE }; };
50template<>
struct Va_type_id<void> {
enum { Id = L4_VARG_TYPE_NIL }; };
51template<>
struct Va_type_id<char const *> {
enum { Id = L4_VARG_TYPE_STRING }; };
53template<
typename T >
struct Va_type;
55template<>
struct Va_type<
l4_umword_t> : Generic_va_type<l4_umword_t, Va_type_id> {};
56template<>
struct Va_type<
l4_mword_t> : Generic_va_type<l4_mword_t, Va_type_id> {};
57template<>
struct Va_type<l4_fpage_t> : Generic_va_type<l4_fpage_t, Va_type_id> {};
59template<>
struct Va_type<void>
61 using Ret_value = void;
64 static void const *addr_of(
void) {
return 0; }
66 static void value(
void const *) {}
67 static L4_varg_type id() {
return L4_VARG_TYPE_NIL; }
68 static unsigned size(
void const *) {
return 0; }
71template<>
struct Va_type<char const *>
73 using Ret_value =
char const *;
74 using Value =
char const *;
76 static void const *addr_of(Value v) {
return v; }
78 static L4_varg_type id() {
return L4_VARG_TYPE_STRING; }
79 static unsigned size(
void const *s)
81 char const *_s =
reinterpret_cast<char const *
>(s);
90 static Ret_value value(
void const *d) {
return static_cast<char const *
>(d); }
103 enum { Direct_data = 0x8000 };
109 L4_varg_type
type()
const {
return static_cast<L4_varg_type
>(_tag & 0xff); }
114 unsigned length()
const {
return _tag >> 16; }
116 Tag tag()
const {
return _tag & ~static_cast<Tag>(Direct_data); }
123 _tag =
tag & ~static_cast<Tag>(Direct_data);
126 void data(
char const *d) { _d = d; }
131 if (_tag & Direct_data)
133 union T {
char const *d;
char v[
sizeof(
char const *)]; };
134 return reinterpret_cast<T
const *
>(&_d)->v;
140#if __cplusplus >= 201103L
147 Varg(L4_varg_type t,
void const *v,
int len)
148 : _tag(t | (static_cast<
l4_mword_t>(len) << 16)),
149 _d(static_cast<char const *>(v))
152 static Varg nil() {
return Varg(L4_VARG_TYPE_NIL, 0, 0); }
160 template<
typename V >
161 typename Va_type<V>::Ret_value
value()
const
163 if (_tag & Direct_data)
165 union X {
char const *d; V v; };
166 return reinterpret_cast<X
const &
>(_d).v;
169 return Va_type<V>::value(_d);
174 template<
typename T >
175 bool is_of()
const {
return Va_type<T>::id() ==
type(); }
182 {
return (
type() & ~L4_VARG_TYPE_SIGN) == L4_VARG_TYPE_UMWORD; }
190 template<
typename T >
201 template<
typename T >
204 using Vt = Va_type<T>;
205 _tag = Vt::id() | (Vt::size(d) << 16);
206 _d =
static_cast<char const *
>(d);
213 static_assert(
sizeof(T) <=
sizeof(
char const *),
"direct Varg value too big");
214 using Vt = Va_type<T>;
215 _tag = Vt::id() | (
sizeof(T) << 16) | Direct_data;
216 union X {
char const *d; T v; };
217 reinterpret_cast<X &
>(_d).v = val;
221 template<
typename T>
explicit
227 template<
typename T>
explicit
234class Varg_t :
public Varg
237 using Value =
typename Va_type<T>::Value;
238 explicit Varg_t(Value v) :
Varg()
239 { _data = v;
set_value<T>(Va_type<T>::addr_of(_data)); }
245template<
unsigned MAX = L4_UTCB_GENERIC_DATA_SIZE>
263 friend class Varg_list;
270 using Mp = M
const *;
275 Mp next_arg(
Varg const &a)
const
282 Iter_state() : _c(
nullptr), _e(
nullptr) {}
285 Iter_state(Mp c, Mp e) : _c(c), _e(e)
290 {
return _c && _c < _e; }
293 Mp
begin()
const {
return _c; }
296 Mp
end()
const {
return _e; }
309 a.
data(
reinterpret_cast<char const *
>(&_c[1]));
318 bool operator == (Iter_state
const &o)
const
319 {
return _c == o._c; }
322 bool operator != (Iter_state
const &o)
const
323 {
return _c != o._c; }
359 explicit operator bool ()
const
360 {
return !_a.is_nil(); }
378 if (_a.is_nil() && o._a.
is_nil())
384 bool operator == (
Iterator const &o)
const
387 bool operator != (
Iterator const &o)
const
420template<
unsigned MAX>
424 Varg_list(Varg_list
const &);
434 unsigned c = r._s.end() - rs;
440 for (
unsigned i = 0; i < c; ++i)
443 this->_s = Iter_state(data, data + c);
449template<>
struct Elem<Varg const *>
451 using arg_type = Varg
const *;
452 using svr_type = Varg_list_ref;
453 using svr_arg_type = Varg_list_ref;
454 static constexpr bool Is_optional =
false;
455 static constexpr bool Is_input =
true;
456 static constexpr bool Is_output =
false;
468 static int to_msg_data(
char *msg,
unsigned offs,
unsigned limit,
471 for (Varg
const *i = &a; i->tag(); ++i)
476 *
reinterpret_cast<l4_umword_t*
>(msg + offs) = i->tag();
480 char const *d = i->data();
481 for (
unsigned x = 0; x < i->length(); ++x)
493 static int to_svr_data(
char *msg,
unsigned offset,
unsigned limit,
498 for (offs = start; offs < limit;)
506 arg.tag(*
reinterpret_cast<l4_umword_t*
>(msg + offs));
515 offs += arg.length();
Iterator(Iter_state const &s)
Create a new iterator.
bool equals(Iterator const &o) const
check for equality
Iterator & operator++()
increment iterator to the next arg
Varg operator*() const
dereference the iterator, get Varg
Iterator begin() const
Returns an iterator to the first Varg.
Varg pop_front()
Get the next parameter in the list.
Varg next()
Get the next parameter in the list.
Varg_list_ref(void const *start, void const *end)
Create a parameter list over a given memory region.
Iterator end() const
Returns the end of the list.
Varg_list_ref()=default
Create an empty parameter list.
Self-contained list of variable-sized RPC parameters.
Varg_list(Varg_list_ref const &r)
Create a parameter list as a copy from a referencing list.
Variably sized RPC argument.
Varg(char const *data)
Make Varg from null-terminated string.
char const * data() const
Varg(L4_varg_type t, void const *v, int len)
Make an indirect varg.
Varg()=default
Make uninitialized Varg.
void set_direct_value(T val, L4::Types::Enable_if_t< sizeof(T)<=sizeof(char const *), bool >=true)
Set to directly stored value of type T.
Va_type< V >::Ret_value value() const
unsigned length() const
Get the size of the RPC argument.
void set_value(void const *d)
Set to indirect value of type T.
L4_varg_type type() const
void tag(Tag tag)
Set Varg tag (usually from message).
Varg(T const *data)
Make Varg from indirect value (pointer).
Varg(T data, L4::Types::Enable_if_t< sizeof(T)<=sizeof(char const *), bool >=true)
Make Varg from direct value.
l4_umword_t Tag
The data type for the tag.
void data(char const *d)
Set Varg to indirect data value (usually in UTCB).
bool get_value(typename Va_type< T >::Value *v) const
Get the value of the Varg as type T.
unsigned long l4_umword_t
Unsigned machine word.
signed long l4_mword_t
Signed machine word.
@ L4_EMSGTOOLONG
Message too long.
#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_DEPRECATED(s)
Mark symbol deprecated.
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).
IPC related functionality.
typename Enable_if< Condition, T >::type Enable_if_t
Helper type for Enable_if.
L4 low-level kernel interface.
Empty client side marshalling code.
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 &).
Type trait defining a valid RPC parameter type.
Empty server side marshalling code.
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 &).