20#include "capability.h"
57 operator T ()
const {
return v; }
58 operator T & () {
return v; }
62template<
typename A>
struct Elem<
In_out<A *> > : Elem<A *> {};
65struct Svr_xmit< In_out<A *> > : Svr_xmit<A *>, Svr_xmit<A const *>
67 using Svr_xmit<A *>::from_svr;
68 using Svr_xmit<A
const *>::to_svr;
72struct Clnt_xmit< In_out<A *> > : Clnt_xmit<A *>, Clnt_xmit<A const *>
74 using Clnt_xmit<A *>::from_msg;
75 using Clnt_xmit<A
const *>::to_msg;
79struct Is_valid_rpc_type< In_out<A *> > : Is_valid_rpc_type<A *> {};
83#ifdef CONFIG_ALLOW_REFS
84template<
typename A>
struct Elem< In_out<A &> > : Elem<A &> {};
87struct Svr_xmit< In_out<A &> > : Svr_xmit<A &>, Svr_xmit<A const &>
89 using Svr_xmit<A &>::from_svr;
90 using Svr_xmit<A
const &>::to_svr;
94struct Clnt_xmit< In_out<A &> > : Clnt_xmit<A &>, Clnt_xmit<A const &>
96 using Clnt_xmit<A &>::from_msg;
97 using Clnt_xmit<A
const &>::to_msg;
101struct Is_valid_rpc_type< In_out<A &> > : Is_valid_rpc_type<A &> {};
129 typedef T value_type;
133 operator T ()
const noexcept {
return v; }
134 operator T & ()
noexcept {
return v; }
138template<
typename T>
struct Class<
As_value<T> > : Cls_data {};
139template<
typename T>
struct Elem< As_value<T> > : Elem<T> {};
140template<
typename T>
struct Elem< As_value<T> *> : Elem<T *> {};
153 Opt() noexcept : _valid(false) {}
156 Opt(T value) noexcept : _value(value), _valid(
true) {}
159 Opt &operator = (T value)
noexcept
161 this->_value = value;
167 void set_valid(
bool valid =
true) noexcept { _valid = valid; }
170 T *operator -> () noexcept {
return &this->_value; }
172 T
const *operator -> () const noexcept {
return &this->_value; }
174 T
value() const noexcept {
return this->_value; }
176 T &
value() noexcept {
return this->_value; }
178 bool is_valid() const noexcept {
return this->_valid; }
182template<
typename T>
struct Elem< Opt<T &> > : Elem<T &>
184 enum { Is_optional =
true };
185 typedef Opt<typename Elem<T &>::svr_type> &svr_arg_type;
186 typedef Opt<typename Elem<T &>::svr_type> svr_type;
189template<
typename T>
struct Elem< Opt<T *> > : Elem<T *>
191 enum { Is_optional =
true };
192 typedef Opt<typename Elem<T *>::svr_type> &svr_arg_type;
193 typedef Opt<typename Elem<T *>::svr_type> svr_type;
198template<
typename T,
typename CLASS>
199struct Svr_val_ops<Opt<T>, Dir_out, CLASS> : Svr_noops< Opt<T> >
201 typedef Opt<T> svr_type;
202 typedef Svr_val_ops<T, Dir_out, CLASS> Native;
204 using Svr_noops< Opt<T> >::to_svr;
205 static int to_svr(
char *msg,
unsigned offset,
unsigned limit,
206 Opt<T> &arg, Dir_out, CLASS)
noexcept
208 return Native::to_svr(msg, offset, limit, arg.value(), Dir_out(), CLASS());
211 using Svr_noops< Opt<T> >::from_svr;
212 static int from_svr(
char *msg,
unsigned offset,
unsigned limit,
long ret,
213 svr_type &arg, Dir_out, CLASS)
noexcept
216 return Native::from_svr(msg, offset, limit, ret, arg.value(),
222template<
typename T>
struct Elem< Opt<T> > : Elem<T>
224 enum { Is_optional =
true };
225 typedef Opt<T> arg_type;
228template<
typename T>
struct Elem< Opt<T const *> > : Elem<T const *>
230 enum { Is_optional =
true };
231 typedef Opt<T const *> arg_type;
237template<
typename T,
typename CLASS>
238struct Clnt_val_ops<Opt<T>, Dir_in, CLASS> : Clnt_noops< Opt<T> >
240 typedef Opt<T> arg_type;
241 typedef Detail::_Clnt_val_ops<typename Elem<T>::arg_type, Dir_in, CLASS> Native;
243 using Clnt_noops< Opt<T> >::to_msg;
244 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
245 arg_type arg, Dir_in, CLASS)
noexcept
248 return Native::to_msg(msg, offset, limit,
249 Detail::_Plain<T>::deref(arg.value()),
255template<
typename T>
struct Class< Opt<T> > :
256 Class< typename Detail::_Plain<T>::type > {};
257template<
typename T>
struct Direction< Opt<T> > : Direction<T> {};
320template<
typename T >
360 Gen_fpage(Type type,
l4_addr_t base,
int order,
361 unsigned char rights,
364 Cacheopt cache, Continue cont) noexcept
371 Gen_fpage() noexcept : T(0, 0) {}
373 Map_type map_type = Map,
374 Cacheopt cache = None, Continue cont = Last) noexcept
380 Gen_fpage(
L4::Cap<void> cap,
unsigned rights, Map_type map_type = Map) noexcept
382 cap.fpage(rights).raw)
385 static Gen_fpage<T> obj(
l4_addr_t base,
int order,
386 unsigned char rights,
388 Map_type map_type = Map,
389 Continue cont = Last)
noexcept
391 return Gen_fpage<T>(Obj, base << 12, order, rights, snd_base, map_type, None, cont);
394 static Gen_fpage<T> mem(
l4_addr_t base,
int order,
395 unsigned char rights,
397 Map_type map_type = Map,
398 Cacheopt cache = None, Continue cont = Last)
noexcept
400 return Gen_fpage<T>(Memory, base, order, rights, snd_base,
401 map_type, cache, cont);
405 unsigned char rights,
unsigned cap_br)
noexcept
414 static Gen_fpage<T> io(
l4_addr_t base,
int order,
415 unsigned char rights,
417 Map_type map_type = Map,
418 Continue cont = Last)
noexcept
420 return Gen_fpage<T>(Io, base << 12, order, rights, snd_base, map_type, None, cont);
423 unsigned order() const noexcept {
return (T::_data >> 6) & 0x3f; }
424 unsigned snd_order() const noexcept {
return (T::_data >> 6) & 0x3f; }
425 unsigned rcv_order() const noexcept {
return (T::_base >> 6) & 0x3f; }
426 l4_addr_t base() const noexcept {
return T::_data & (~0UL << 12); }
427 l4_addr_t snd_base() const noexcept {
return T::_base & (~0UL << 10); }
428 void snd_base(
l4_addr_t b)
noexcept { T::_base = (T::_base & ~(~0UL << 10)) | (b & (~0UL << 10)); }
442 bool cap_received() const noexcept {
return (T::_base & 0x3e) == 0x38; }
454 bool id_received() const noexcept {
return (T::_base & 0x3e) == 0x3c; }
485#ifdef L4_CXX_IPC_SUPPORT_STRINGS
486template <
typename T,
typename B>
487class Gen_string :
public T
490 Gen_string() noexcept : T(0, 0) {}
491 Gen_string(B buf,
unsigned long size) noexcept
495 unsigned long len()
const noexcept {
return T::_base >> 10; }
498typedef Gen_string<Snd_item, void const *> Snd_string;
499typedef Gen_string<Buf_item, void *> Rcv_string;
515 typedef void svr_type;
516 typedef void svr_arg_type;
517 enum { Is_optional =
false };
521template<>
struct Class<
L4::Ipc::Small_buf> : Cls_buffer {};
524template<>
struct Elem<
L4::Ipc::Small_buf>
527 typedef void svr_type;
528 typedef void svr_arg_type;
529 enum { Is_optional =
false };
545template<
typename T>
class Cap
547 template<
typename O>
friend class Cap;
569 Cap(
Cap<O> const &o) noexcept : _cap_n_rights(o._cap_n_rights)
570 { T *x = (O*)1; (void)x; }
581 { T *x = (O*)1; (void)x; }
618 {
return !(_cap_n_rights & L4_INVALID_CAP_BIT); }
629{
return Cap<T>(cap, rights); }
674 Opt(Cap<T> value) noexcept : _value(value) {}
675 Opt(
L4::Cap<T> value) noexcept : _value(value) {}
676 Opt &operator = (Cap<T> value)
noexcept
677 { this->_value = value; }
679 { this->_value = value; }
681 Cap<T> value() const noexcept {
return this->_value; }
682 bool is_valid() const noexcept {
return this->_value.
is_valid(); }
691template<
typename A>
struct Class< Cap<A> > : Cls_item {};
692template<
typename A>
struct Elem< Cap<A> >
694 enum { Is_optional =
false };
695 typedef Cap<A> arg_type;
701template<
typename A,
typename CLASS>
702struct Svr_val_ops<Cap<A>, Dir_in, CLASS> :
703 Svr_val_ops<L4::Ipc::Snd_fpage, Dir_in, CLASS>
706template<
typename A,
typename CLASS>
707struct Clnt_val_ops<Cap<A>, Dir_in, CLASS> :
710 using Clnt_noops< Cap<A> >::to_msg;
712 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
713 Cap<A> arg, Dir_in, Cls_item)
noexcept
722 return msg_add(msg, offset, limit, arg.fpage());
727struct Elem<Out<
L4::Cap<A> > >
729 enum { Is_optional =
false };
731 typedef Ipc::Cap<A> svr_type;
732 typedef svr_type &svr_arg_type;
735template<
typename A>
struct Direction< Out<
L4::Cap<A> > > : Dir_out {};
736template<
typename A>
struct Class< Out<
L4::Cap<A> > > : Cls_item {};
739struct Clnt_val_ops<
L4::Cap<A>, Dir_out, Cls_item > :
740 Clnt_noops< L4::Cap<A> >
743 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
748 return msg_add(msg, offset, limit, Small_buf(arg));
753struct Svr_val_ops<
L4::Ipc::Cap<A>, Dir_out, Cls_item > :
756 using Svr_noops<Cap<A> &>::from_svr;
757 static int from_svr(
char *msg,
unsigned offset,
unsigned limit,
long,
758 Cap<A> arg, Dir_out, Cls_item)
noexcept
764 return msg_add(msg, offset, limit, arg.fpage());
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
C++ interface for capabilities.
RPC warpper for a receive item.
Capability type for RPC interfaces (see L4::Cap<T>).
Cap(L4::Cap< T > cap) noexcept
Make a Cap from L4::Cap<T>, with minimal rights.
Cap(L4::Cap< T > cap, unsigned char rights) noexcept
Make a Cap from L4::Cap<T> with the given rights.
static Cap from_ci(l4_cap_idx_t c) noexcept
Create an IPC capability from a C capability index plus rights.
L4::Ipc::Snd_fpage fpage() const noexcept
Return the send flexpage for this Cap (see l4_fpage_t)
Cap(L4::Cap< O > cap) noexcept
Make IPC Cap from L4::Cap with conversion (and minimal rights).
Cap() noexcept
Make an invalid cap.
L4::Cap< T > cap() const noexcept
Return the L4::Cap<T> of this Cap.
unsigned rights() const noexcept
Return the rights bits stored in this IPC cap.
bool is_valid() const noexcept
Return true if this Cap is valid.
Cap(Cap< O > const &o) noexcept
Make copy with conversion.
@ Rights_mask
Mask for rights bits stored internally.
@ Cap_mask
Mask for significant capability bits.
Generic RPC wrapper for L4 flex-pages.
bool is_valid() const noexcept
Check if the capability is valid.
l4_umword_t base_x() const noexcept
Return the raw base descriptor.
Cacheopt
Caching options, see l4_fpage_cacheability_opt_t.
bool id_received() const noexcept
Check if a label was received instead of a mapping.
Type
Type of mapping object, see L4_fpage_type.
bool cap_received() const noexcept
Check if at least one capability has been mapped.
bool is_compound() const noexcept
Check if the received item has the compound bit set.
l4_umword_t data() const noexcept
Return the raw flex page descriptor.
bool local_id_received() const noexcept
Check if a local capability id has been received.
A receive item for receiving a single object capability.
Small_buf(l4_cap_idx_t cap, unsigned long flags=0) noexcept
Create a receive item from a C cap.
Small_buf(L4::Cap< void > cap, unsigned long flags=0) noexcept
Create a receive item from a C++ cap.
RPC wrapper for a send item.
unsigned long l4_umword_t
Unsigned machine word.
unsigned long l4_addr_t
Address type.
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_INVALID_CAP
Invalid capability selector.
@ L4_EMSGMISSARG
Message has invalid capability.
@ L4_FPAGE_CACHEABLE
Cacheability option to enable caches for the mapping.
@ L4_FPAGE_UNCACHEABLE
Cacheability option to disable caching for the mapping.
@ L4_FPAGE_BUFFERABLE
Cacheability option to enable buffered writes for the mapping.
@ L4_FPAGE_MEMORY
Memory flex page.
@ L4_FPAGE_IO
IO-port flex page.
@ L4_FPAGE_OBJ
Object flex page (capabilities).
@ L4_FPAGE_SPECIAL
Special flex page, either invalid or all spaces.
@ L4_FPAGE_C_OBJ_RIGHTS
All Object-type specific right bits.
@ L4_CAP_FPAGE_R
Read right for capability flex-pages.
@ L4_CAP_FPAGE_RW
Read and interface specific 'W' right for capability flex-pages.
@ L4_CAP_FPAGE_RWSD
Full rights for capability flex-pages.
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flex-pages.
@ L4_MAP_ITEM_GRANT
Flag as grant instead of map operation.
@ L4_ITEM_MAP
Identify a message item as map item.
@ L4_ITEM_CONT
Denote that the following item shall be put into the same receive item as this one.
@ L4_MAP_ITEM_MAP
Flag as usual map operation.
@ L4_RCV_ITEM_SINGLE_CAP
Mark the receive buffer to be a small receive item that describes a buffer for a single object capabi...
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
#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.
int msg_add(char *msg, unsigned offs, unsigned limit, T v) noexcept
Add some data to a message at offs.
Cap< T > make_cap(L4::Cap< T > cap, unsigned rights) noexcept
Make an L4::Ipc::Cap<T> for the given capability and rights.
Cap< T > make_cap_full(L4::Cap< T > cap) noexcept
Make an L4::IPC::Cap<T> for the given capability with full fpage and object-specific rights.
Gen_fpage< Snd_item > Snd_fpage
Send flex-page.
Gen_fpage< Buf_item > Rcv_fpage
Rcv flex-page.
Cap< T > make_cap_rw(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
Cap< T > make_cap_rws(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RWS rights.
L4 low-level kernel interface.
int Opcode
Data type for RPC opcodes.
Pass the argument as plain data value.
Mark an argument as in-out argument.
Attribute for defining an optional RPC argument.
void set_valid(bool valid=true) noexcept
Set the argument to present or absent.
Opt(T value) noexcept
Make a present optional argument with the given value.
bool is_valid() const noexcept
Get true if present, false if not.
T value() const noexcept
Get the value.
Opt() noexcept
Make an absent optional argument.
T & value() noexcept
Get the value.
bool _valid
True if the optional argument is present, false else.
Mark an argument as a output value in an RPC signature.