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> {};
333 : _base(base), _data(data)
336 Gen_fpage(Type type,
l4_addr_t base,
int order,
337 unsigned char rights,
340 Cacheopt cache, Continue cont) noexcept
346 unsigned order() const noexcept {
return (_data >> 6) & 0x3f; }
347 unsigned snd_order() const noexcept {
return (_data >> 6) & 0x3f; }
348 unsigned rcv_order() const noexcept {
return (_base >> 6) & 0x3f; }
349 l4_addr_t base() const noexcept {
return _data & (~0UL << 12); }
350 l4_addr_t snd_base() const noexcept {
return _base & (~0UL << 12); }
351 void snd_base(
l4_addr_t b)
noexcept { _base = (_base & ~(~0UL << 12)) | (b & (~0UL << 12)); }
377 bool id_received() const noexcept {
return (_base & 0x3e) == 0x3c; }
416 Cacheopt cache = None, Continue cont = Last) noexcept
428 unsigned char rights,
431 Continue cont = Last)
noexcept
434 map_type, None, cont);
438 unsigned char rights,
441 Cacheopt cache = None, Continue cont = Last)
noexcept
447 static Snd_fpage io(
unsigned long base,
int order,
448 unsigned char rights,
451 Continue cont = Last)
noexcept
454 snd_base, map_type, None, cont);
506struct Clnt_val_ops<
L4::Ipc::Rcv_fpage, Dir_in, Cls_buffer>
507 : Clnt_noops<L4::Ipc::Rcv_fpage>
511 static int to_msg(
char *msg,
unsigned offs,
unsigned limit,
514 offs = align_to<l4_umword_t>(offs);
515 unsigned words = arg.is_compound() ? 3 : 2;
516 if (
L4_UNLIKELY(!check_size<l4_umword_t>(offs, limit, words)))
518 auto *buf =
reinterpret_cast<l4_umword_t*
>(msg + offs);
519 *buf++ = arg.base_x();
521 if (arg.is_compound())
522 *buf++ = arg.rcv_task();
529template<>
struct Elem<
L4::Ipc::Rcv_fpage>
532 typedef void svr_type;
533 typedef void svr_arg_type;
534 enum { Is_optional =
false };
538template<>
struct Class<
L4::Ipc::Small_buf> : Cls_buffer {};
541template<>
struct Elem<
L4::Ipc::Small_buf>
544 typedef void svr_type;
545 typedef void svr_arg_type;
546 enum { Is_optional =
false };
562template<
typename T>
class Cap
564 template<
typename O>
friend class Cap;
586 Cap(
Cap<O> const &o) noexcept : _cap_n_rights(o._cap_n_rights)
639 {
return !(_cap_n_rights & L4_INVALID_CAP_BIT); }
650{
return Cap<T>(cap, rights); }
695 Opt(Cap<T> value) noexcept : _value(value) {}
696 Opt(
L4::Cap<T> value) noexcept : _value(value) {}
697 Opt &operator = (Cap<T> value)
noexcept
698 { this->_value = value; }
700 { this->_value = value; }
702 Cap<T> value() const noexcept {
return this->_value; }
703 bool is_valid() const noexcept {
return this->_value.
is_valid(); }
712template<
typename A>
struct Class< Cap<A> > : Cls_item {};
713template<
typename A>
struct Elem< Cap<A> >
715 enum { Is_optional =
false };
716 typedef Cap<A> arg_type;
722template<
typename A,
typename CLASS>
723struct Svr_val_ops<Cap<A>, Dir_in, CLASS> :
724 Svr_val_ops<L4::Ipc::Snd_fpage, Dir_in, CLASS>
727template<
typename A,
typename CLASS>
728struct Clnt_val_ops<Cap<A>, Dir_in, CLASS> :
731 using Clnt_noops< Cap<A> >::to_msg;
733 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
734 Cap<A> arg, Dir_in, Cls_item)
noexcept
743 return msg_add(msg, offset, limit, arg.fpage());
748struct Elem<Out<
L4::Cap<A> > >
750 enum { Is_optional =
false };
752 typedef Ipc::Cap<A> svr_type;
753 typedef svr_type &svr_arg_type;
756template<
typename A>
struct Direction< Out<
L4::Cap<A> > > : Dir_out {};
757template<
typename A>
struct Class< Out<
L4::Cap<A> > > : Cls_item {};
760struct Clnt_val_ops<
L4::Cap<A>, Dir_out, Cls_item > :
761 Clnt_noops< L4::Cap<A> >
764 static int to_msg(
char *msg,
unsigned offset,
unsigned limit,
769 return msg_add(msg, offset, limit, Small_buf(arg));
774struct Svr_val_ops<
L4::Ipc::Cap<A>, Dir_out, Cls_item > :
777 using Svr_noops<Cap<A> &>::from_svr;
778 static int from_svr(
char *msg,
unsigned offset,
unsigned limit,
long,
779 Cap<A> arg, Dir_out, Cls_item)
noexcept
785 return msg_add(msg, offset, limit, arg.fpage());
l4_fpage_t fpage(unsigned rights=L4_CAP_FPAGE_RWS) const noexcept
Return flex-page for the capability.
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
C++ interface for capabilities.
Capability type for RPC interfaces (see L4::Cap<T>).
@ Rights_mask
Mask for rights bits stored internally.
@ Cap_mask
Mask for significant capability bits.
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.
Generic RPC base for L4 flex-pages.
bool is_valid() const noexcept
Check if the capability is valid.
bool id_received() const noexcept
Check if a label was received instead of a mapping.
l4_umword_t base_x() const noexcept
Return the raw base descriptor.
Cacheopt
Caching options, see l4_fpage_cacheability_opt_t.
bool is_compound() const noexcept
Check if the received item has the compound bit set.
Type
Type of mapping object, see L4_fpage_type.
bool cap_received() const noexcept
Check if at least one capability has been mapped.
bool local_id_received() const noexcept
Check if a local capability id has been received.
l4_umword_t data() const noexcept
Return the raw flex page descriptor.
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.
unsigned long l4_umword_t
Unsigned machine word.
unsigned long l4_addr_t
Address type.
unsigned long l4_cap_idx_t
Capability selector type.
unsigned l4_is_valid_cap(l4_cap_idx_t c) L4_NOTHROW
Test if a capability selector is a valid selector.
@ 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_EMSGTOOLONG
Message too long.
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flex page.
l4_fpage_t l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
Create a memory flex page.
l4_fpage_t l4_fpage_set_rights(l4_fpage_t src, unsigned char new_rights) L4_NOTHROW
Set new right in a flex page.
l4_fpage_t l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW
Create an IO-port flex page.
@ 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.
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.
l4_umword_t raw
Raw value.