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 noexcept {
return v; }
134 operator T & () noexcept {
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
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; }
182 template<
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;
189 template<
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;
198 template<
typename T,
typename CLASS>
199 struct 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(),
222 template<
typename T>
struct Elem< Opt<T> > : Elem<T>
224 enum { Is_optional =
true };
225 typedef Opt<T> arg_type;
228 template<
typename T>
struct Elem< Opt<T const *> > : Elem<T const *>
230 enum { Is_optional =
true };
231 typedef Opt<T const *> arg_type;
237 template<
typename T,
typename CLASS>
238 struct 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()),
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
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)); }
438 bool cap_received() const noexcept {
return (T::_base & 0x3e) == 0x38; }
450 bool id_received() const noexcept {
return (T::_base & 0x3e) == 0x3c; }
481 #ifdef L4_CXX_IPC_SUPPORT_STRINGS
482 template <
typename T,
typename B>
483 class Gen_string :
public T
486 Gen_string() noexcept : T(0, 0) {}
487 Gen_string(B buf,
unsigned long size) noexcept
491 unsigned long len()
const noexcept {
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 };
517 template<>
struct Class<
L4::Ipc::Small_buf> : Cls_buffer {};
520 template<>
struct Elem<
L4::Ipc::Small_buf>
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;
565 Cap(
Cap<O> const &o) noexcept : _cap_n_rights(o._cap_n_rights)
566 { T *x = (O*)1; (void)x; }
577 { T *x = (O*)1; (void)x; }
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) noexcept : _value(value) {}
671 Opt(
L4::Cap<T> value) noexcept : _value(value) {}
672 Opt &operator = (Cap<T> value) noexcept
673 { this->_value = value; }
675 { this->_value = value; }
677 Cap<T> value() const noexcept {
return this->_value; }
678 bool is_valid() const noexcept {
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 };
691 typedef Cap<A> arg_type;
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) noexcept
718 return msg_add(msg, offset, limit, arg.fpage());
723 struct Elem<Out<
L4::Cap<A> > >
725 enum { Is_optional =
false };
727 typedef Ipc::Cap<A> svr_type;
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) noexcept
760 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>).
L4::Cap< T > cap() const noexcept
Return the L4::Cap<T> of this Cap.
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.
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 the 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 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.
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
unsigned long l4_umword_t
Unsigned machine word.
unsigned long l4_addr_t
Address type.
unsigned long l4_cap_idx_t
L4 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_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 capability.
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
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_rws(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RWS 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_full(L4::Cap< T > cap) noexcept
Make an L4::IPC::Cap<T> for the given capability with full fpage and object-specific 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.
bool _valid
True if the optional argument is present, false else.
T & value() noexcept
Get the value.
Mark an argument as a output value in an RPC signature.