20 #include "capability.h" 42 template<
typename T>
struct L4_EXPORT
Out;
52 template<
typename T>
struct L4_EXPORT
In_out 57 operator T ()
const {
return v; }
58 operator T & () {
return v; }
62 template<
typename A>
struct Elem< In_out<A *> > : Elem<A *> {};
65 struct 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;
72 struct 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;
79 struct Is_valid_rpc_type< In_out<A *> > : Is_valid_rpc_type<A *> {};
83 #ifdef CONFIG_ALLOW_REFS 84 template<
typename A>
struct Elem< In_out<A &> > : Elem<A &> {};
87 struct 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;
94 struct 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;
101 struct Is_valid_rpc_type< In_out<A &> > : Is_valid_rpc_type<A &> {};
129 typedef T value_type;
133 operator T ()
const {
return v; }
134 operator T & () {
return v; }
138 template<
typename T>
struct Class< As_value<T> > : Cls_data {};
139 template<
typename T>
struct Elem< As_value<T> > : Elem<T> {};
140 template<
typename T>
struct Elem< As_value<T> *> : Elem<T *> {};
147 template<
typename T>
struct L4_EXPORT
Opt 156 Opt(T value) : _value(value), _valid(true) {}
161 this->_value = value;
170 T *operator -> () {
return &this->_value; }
172 T
const *operator -> ()
const {
return &this->_value; }
174 T
value()
const {
return this->_value; }
182 template<
typename T>
struct Elem< Opt<T &> > : Elem<T &>
184 enum { Is_optional =
true };
189 template<
typename T>
struct Elem< Opt<T *> > : Elem<T *>
191 enum { Is_optional =
true };
198 template<
typename T,
typename CLASS>
199 struct Svr_val_ops<Opt<T>, Dir_out, CLASS> : Svr_noops< Opt<T> >
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)
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)
216 return Native::from_svr(msg, offset, limit, ret, arg.value(),
222 template<
typename T>
struct Elem< Opt<T> > : Elem<T>
224 enum { Is_optional =
true };
228 template<
typename T>
struct Elem< Opt<T const *> > : Elem<T const *>
230 enum { Is_optional =
true };
237 template<
typename T,
typename CLASS>
238 struct Clnt_val_ops<Opt<T>, Dir_in, CLASS> : Clnt_noops< Opt<T> >
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)
248 return Native::to_msg(msg, offset, limit,
249 Detail::_Plain<T>::deref(arg.value()),
255 template<
typename T>
struct Class< Opt<T> > :
256 Class< typename Detail::_Plain<T>::type > {};
257 template<
typename T>
struct Direction< Opt<T> > : Direction<T> {};
320 template<
typename T >
327 Special = L4_FPAGE_SPECIAL << 4,
328 Memory = L4_FPAGE_MEMORY << 4,
329 Io = L4_FPAGE_IO << 4,
330 Obj = L4_FPAGE_OBJ << 4
361 unsigned char rights,
374 Cacheopt cache = None, Continue cont = Last)
386 unsigned char rights,
389 Continue cont = Last)
391 return Gen_fpage<T>(Obj, base << 12, order, rights, snd_base, map_type, None, cont);
395 unsigned char rights,
398 Cacheopt cache = None, Continue cont = Last)
400 return Gen_fpage<T>(Memory, base, order, rights, snd_base,
401 map_type, cache, cont);
405 unsigned char rights,
unsigned cap_br)
415 unsigned char rights,
418 Continue cont = Last)
420 return Gen_fpage<T>(Io, base << 12, order, rights, snd_base, map_type, None, cont);
423 unsigned order()
const {
return (T::_data >> 6) & 0x3f; }
424 unsigned snd_order()
const {
return (T::_data >> 6) & 0x3f; }
425 unsigned rcv_order()
const {
return (T::_base >> 6) & 0x3f; }
426 l4_addr_t base()
const {
return T::_data & (~0UL << 12); }
427 l4_addr_t snd_base()
const {
return T::_base & (~0UL << 10); }
428 void snd_base(
l4_addr_t b) { T::_base = (T::_base & ~(~0UL << 10)) | (b & (~0UL << 10)); }
481 #ifdef L4_CXX_IPC_SUPPORT_STRINGS 482 template <
typename T,
typename B>
483 class Gen_string :
public T
486 Gen_string() : T(0, 0) {}
487 Gen_string(B buf,
unsigned long size)
491 unsigned long len()
const {
return T::_base >> 10; }
494 typedef Gen_string<Snd_item, void const *> Snd_string;
495 typedef Gen_string<Buf_item, void *> Rcv_string;
511 typedef void svr_type;
512 typedef void svr_arg_type;
513 enum { Is_optional =
false };
523 typedef void svr_type;
524 typedef void svr_arg_type;
525 enum { Is_optional =
false };
541 template<
typename T>
class Cap 543 template<
typename O>
friend class Cap;
566 { T *x = (O*)1; (void)x; }
570 : _cap_n_rights((cap.cap() & Cap_mask) | (cap ?
L4_CAP_FPAGE_R : 0))
576 : _cap_n_rights((cap.cap() & Cap_mask) | (cap ?
L4_CAP_FPAGE_R : 0))
577 { T *x = (O*)1; (void)x; }
590 : _cap_n_rights((cap.cap() & Cap_mask) | (rights & Rights_mask)) {}
602 {
return L4::Cap<T>(_cap_n_rights & Cap_mask); }
606 {
return _cap_n_rights & Rights_mask; }
614 {
return !(_cap_n_rights & L4_INVALID_CAP_BIT); }
625 {
return Cap<T>(cap, rights); }
666 template<
typename T>
struct L4_EXPORT Opt< Cap<T> >
670 Opt(
Cap<T> value) : _value(value) {}
672 Opt &operator = (
Cap<T> value)
673 { this->_value = value; }
675 { this->_value = value; }
677 Cap<T> value()
const {
return this->_value; }
678 bool is_valid()
const {
return this->_value.
is_valid(); }
687 template<
typename A>
struct Class< Cap<A> > : Cls_item {};
688 template<
typename A>
struct Elem< Cap<A> >
690 enum { Is_optional =
false };
697 template<
typename A,
typename CLASS>
698 struct Svr_val_ops<Cap<A>, Dir_in, CLASS> :
699 Svr_val_ops<L4::Ipc::Snd_fpage, Dir_in, CLASS>
702 template<
typename A,
typename CLASS>
703 struct Clnt_val_ops<Cap<A>, Dir_in, CLASS> :
706 using Clnt_noops< Cap<A> >::to_msg;
708 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
709 Cap<A> arg, Dir_in, Cls_item)
718 return msg_add(msg, offset, limit, arg.
fpage());
723 struct Elem<Out<L4::Cap<A> > >
725 enum { Is_optional =
false };
728 typedef svr_type &svr_arg_type;
731 template<
typename A>
struct Direction< Out< L4::Cap<A> > > : Dir_out {};
732 template<
typename A>
struct Class< Out< L4::Cap<A> > > : Cls_item {};
735 struct Clnt_val_ops< L4::Cap<A>, Dir_out, Cls_item > :
736 Clnt_noops< L4::Cap<A> >
738 using Clnt_noops< L4::Cap<A> >::to_msg;
739 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
744 return msg_add(msg, offset, limit,
Small_buf(arg));
749 struct Svr_val_ops< L4::
Ipc::Cap<A>, Dir_out, Cls_item > :
752 using Svr_noops<Cap<A> &>::from_svr;
753 static int from_svr(
char *msg,
unsigned offset,
unsigned limit,
long,
754 Cap<A> arg, Dir_out, Cls_item)
760 return msg_add(msg, offset, limit, arg.
fpage());
Identify a message item as map item.
Capability type for RPC interfaces (see L4::Cap<T>).
bool _valid
True if the optional argument is present, false else.
Read and interface specific 'W' right for capability flex-pages.
Cap(L4::Cap< T > cap)
Make a Cap from L4::Cap<T>, with minimal rights.
Invalid capability selector.
bool is_valid() const
Check if the capability is valid.
Small_buf(L4::Cap< void > cap, unsigned long flags=0)
Create a receive item from a C++ cap.
Cap< T > make_cap_full(L4::Cap< T > cap)
Make an L4::IPC::Cap<T> for the given capability with full fpage and object-specific rights...
bool cap_received() const
Check if the capability has been mapped.
L4::Cap< T > cap() const
Return the L4::Cap<T> of this Cap.
Pass the argument as plain data value.
L4 low-level kernel interface.
Cap< T > make_cap(L4::Cap< T > cap, unsigned rights)
Make an L4::Ipc::Cap<T> for the given capability and rights.
A receive item for receiving a single capability.
unsigned long l4_cap_idx_t
L4 Capability selector Type.
unsigned rights() const
Return the rights bits stored in this IPC cap.
RPC wrapper for a send item.
Cacheability option to enable caches for the mapping.
void set_valid(bool valid=true)
Set the argument to present or absent.
Mark an argument as a output value in an RPC signature.
Cacheopt
Caching options, see l4_fpage_cacheability_opt_t.
RPC warpper for a receive item.
Cap< T > make_cap_rws(L4::Cap< T > cap)
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RWS rights.
Cap(L4::Cap< T > cap, unsigned char rights)
Make a Cap from L4::Cap<T> with the given rights.
L4::Ipc::Snd_fpage fpage() const
Return the send flexpage for this Cap (see l4_fpage_t)
T & value()
Get the value.
Cap()
Make an invalid cap.
int Opcode
Data type for RPC opcodes.
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
l4_umword_t data() const
Return the raw flex page descriptor.
l4_umword_t base_x() const
Return the raw base descriptor.
Cap< T > make_cap_rw(L4::Cap< T > cap)
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
unsigned long l4_umword_t
Unsigned machine word.
Mark an argument as in-out argument.
Attribute for defining an optional RPC argument.
bool is_valid() const
Get true if present, false if not.
bool local_id_received() const
Check if a local capability id has been received.
Cacheability option to disable caching for the mapping.
l4_umword_t raw
Raw value.
Mask to get only the relevant bits of an l4_cap_idx_t.
Gen_fpage< Snd_item > Snd_fpage
Send flex-page.
Type
Type of mapping object, see L4_fpage_type.
All Object-type specific right bits.
l4_fpage_t fpage(unsigned rights=L4_FPAGE_RWX) const
Return flex-page for the capability.
Message has invalid capability.
Gen_fpage< Buf_item > Rcv_fpage
Rcv flex-page.
bool is_compound() const
Check if the received item has the compound bit set.
bool is_valid() const
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Opt()
Make an absent optional argument.
T value() const
Get the value.
Flag as grant instead of map operation.
Denote that the following item shall be put into the same receive item as this one.
Mark the receive buffer to be a small receive item that describes a buffer for a single capability...
Read, interface specific 'W', and 'S' rights for capability flex-pages.
C++ interface for capabilities.
bool is_valid() const
Return true if this Cap is valid.
Opt(T value)
Make a present optional argument with the given value.
Cap(Cap< O > const &o)
Make copy with conversion.
unsigned long l4_addr_t
Address type.
bool id_received() const
Check if a label was received instead of a mapping.
Full rights for capability flex-pages.
Read right for capability flex-pages.
Flag as usual map operation.
Cacheability option to enable buffered writes for the mapping.
static Cap from_ci(l4_cap_idx_t c)
Create an IPC capability from a C capability index plus rights.
Generic RPC wrapper for L4 flex-pages.
Cap(L4::Cap< O > cap)
Make IPC Cap from L4::Cap with conversion (and minimal rights).
Small_buf(l4_cap_idx_t cap, unsigned long flags=0)
Create a receive item from a C cap.