Loading...
Searching...
No Matches
capability.h
#pragma once
#include <l4/sys/consts.h>
#include <l4/sys/types.h>
#include <l4/sys/task.h>
namespace L4 {
class Task;
class Kobject;
template< typename T > class L4_EXPORT Cap;
class L4_EXPORT Cap_base
{
public:
enum No_init_type
{
No_init
};
enum Cap_type
{
Invalid = L4_INVALID_CAP
};
l4_cap_idx_t cap() const noexcept { return _c; }
bool is_valid() const noexcept { return !(_c & L4_INVALID_CAP_BIT); }
int invalid_cap_error() const noexcept { return _c & ~L4_INVALID_CAP_BIT; }
explicit operator bool () const noexcept
{ return !(_c & L4_INVALID_CAP_BIT); }
l4_fpage_t fpage(unsigned rights = L4_CAP_FPAGE_RWS) const noexcept
{ return l4_obj_fpage(_c, 0, rights); }
l4_umword_t snd_base(unsigned grant = L4_MAP_ITEM_MAP,
l4_cap_idx_t base = L4_INVALID_CAP) const noexcept
{
if (base == L4_INVALID_CAP)
base = _c;
return l4_map_obj_control(base, grant);
}
bool operator == (Cap_base const &o) const noexcept
{ return _c == o._c; }
bool operator != (Cap_base const &o) const noexcept
{ return _c != o._c; }
inline l4_msgtag_t validate(l4_utcb_t *u = l4_utcb()) const noexcept;
inline l4_msgtag_t validate(Cap<Task> task,
l4_utcb_t *u = l4_utcb()) const noexcept;
void invalidate() noexcept { _c = L4_INVALID_CAP; }
protected:
explicit Cap_base(l4_cap_idx_t c) noexcept : _c(c) {}
explicit Cap_base(Cap_type cap) noexcept : _c(cap) {}
explicit Cap_base(l4_default_caps_t cap) noexcept : _c(cap) {}
explicit Cap_base() noexcept {}
void move(Cap_base const &src) const
{
if (!is_valid() || !src.is_valid())
return;
l4_task_map(L4_BASE_TASK_CAP, L4_BASE_TASK_CAP, src.fpage(L4_CAP_FPAGE_RWSD),
snd_base(L4_MAP_ITEM_GRANT) | L4_FPAGE_C_OBJ_RIGHTS);
}
void copy(Cap_base const &src) const
{
if (!is_valid() || !src.is_valid())
return;
l4_task_map(L4_BASE_TASK_CAP, L4_BASE_TASK_CAP, src.fpage(L4_CAP_FPAGE_RWSD),
snd_base() | L4_FPAGE_C_OBJ_RIGHTS);
}
l4_cap_idx_t _c;
};
template< typename T >
class L4_EXPORT Cap : public Cap_base
{
private:
friend class L4::Kobject;
explicit Cap(T const *p) noexcept
: Cap_base(reinterpret_cast< l4_cap_idx_t >(p)) {}
public:
template< typename From >
static void check_convertible_from() noexcept
{
using To = T;
[[maybe_unused]] To* t = static_cast<From*>(nullptr);
}
template< typename From >
static void check_castable_from() noexcept
{
using To = T;
[[maybe_unused]] To *t = static_cast<To *>(static_cast<From *>(nullptr));
}
template< typename O >
Cap(Cap<O> const &o) noexcept : Cap_base(o.cap())
{ check_convertible_from<O>(); }
Cap(Cap_type cap) noexcept : Cap_base(cap) {}
Cap(l4_default_caps_t cap) noexcept : Cap_base(cap) {}
explicit Cap(l4_cap_idx_t idx = L4_INVALID_CAP) noexcept : Cap_base(idx) {}
explicit Cap(No_init_type) noexcept {}
Cap move(Cap const &src) const
{
Cap_base::move(src);
return *this;
}
Cap copy(Cap const &src) const
{
Cap_base::copy(src);
return *this;
}
T *operator -> () const noexcept { return reinterpret_cast<T*>(_c); }
};
template<>
class L4_EXPORT Cap<void> : public Cap_base
{
public:
explicit Cap(void const *p) noexcept
: Cap_base(reinterpret_cast< l4_cap_idx_t >(p)) {}
Cap(Cap_type cap) noexcept : Cap_base(cap) {}
Cap(l4_default_caps_t cap) noexcept : Cap_base(cap) {}
explicit Cap(l4_cap_idx_t idx = L4_INVALID_CAP) noexcept : Cap_base(idx) {}
explicit Cap(No_init_type) noexcept {}
template< typename From >
static void check_convertible_from() noexcept {}
template< typename From >
static void check_castable_from() noexcept {}
Cap move(Cap const &src) const
{
Cap_base::move(src);
return *this;
}
Cap copy(Cap const &src) const
{
Cap_base::copy(src);
return *this;
}
template< typename T >
Cap(Cap<T> const &o) noexcept : Cap_base(o.cap()) {}
};
template< typename T, typename F >
inline
Cap<T> cap_cast(Cap<F> const &c) noexcept
{
Cap<T>::template check_castable_from<F>();
return Cap<T>(c.cap());
}
// gracefully deal with L4::Kobject ambiguity
template< typename T >
inline
Cap<T> cap_cast(Cap<L4::Kobject> const &c) noexcept
{
return Cap<T>(c.cap());
}
template< typename T, typename F >
inline
Cap<T> cap_reinterpret_cast(Cap<F> const &c) noexcept
{
return Cap<T>(c.cap());
}
}
L4::Cap_base::copy
void copy(Cap_base const &src) const
Copy a capability.
Definition capability.h:192
L4::Cap_base::Cap_base
Cap_base(l4_default_caps_t cap) noexcept
Initialize capability with one of the default capabilities.
Definition capability.h:160
L4::Cap_base::invalidate
void invalidate() noexcept
Set this capability to invalid (L4_INVALID_CAP).
Definition capability.h:142
L4::Cap_base::Cap_base
Cap_base(Cap_type cap) noexcept
Constructor to create an invalid capability.
Definition capability.h:153
L4::Cap_base::fpage
l4_fpage_t fpage(unsigned rights=L4_CAP_FPAGE_RWS) const noexcept
Return flexpage for the capability.
Definition capability.h:74
L4::Cap_base::_c
l4_cap_idx_t _c
The C representation of a capability selector.
Definition capability.h:203
L4::Cap_base::cap
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
L4::Cap_base::is_valid
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
L4::Cap_base::move
void move(Cap_base const &src) const
Replace this capability with the contents of src.
Definition capability.h:176
L4::Cap_base::Cap_type
Cap_type
Invalid capability type.
Definition capability.h:41
L4::Cap_base::Invalid
@ Invalid
Invalid capability selector.
Definition capability.h:42
L4::Cap_base::invalid_cap_error
int invalid_cap_error() const noexcept
Return the transported error code in an invalid capability index.
Definition capability.h:62
L4::Cap_base::No_init_type
No_init_type
Special value for uninitialized capability objects.
Definition capability.h:30
L4::Cap_base::No_init
@ No_init
Special value for constructing uninitialized Cap objects.
Definition capability.h:34
L4::Cap_base::Cap_base
Cap_base(l4_cap_idx_t c) noexcept
Generate a capability from its C representation.
Definition capability.h:149
L4::Cap_base::Cap_base
Cap_base() noexcept
Create an uninitialized instance.
Definition capability.h:165
L4::Cap_base::snd_base
l4_umword_t snd_base(unsigned grant=L4_MAP_ITEM_MAP, l4_cap_idx_t base=L4_INVALID_CAP) const noexcept
Return send base.
Definition capability.h:86
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Cap::copy
Cap copy(Cap const &src) const
Copy a capability to this cap slot.
Definition capability.h:317
L4::Cap::Cap
Cap(l4_cap_idx_t idx=L4_INVALID_CAP) noexcept
Initialize capability, defaults to the invalid capability selector.
Definition capability.h:294
L4::Cap::Cap
Cap(No_init_type) noexcept
Create an uninitialized cap selector.
Definition capability.h:299
L4::Cap::Cap
Cap(Cap_type cap) noexcept
Constructor to create an invalid capability selector.
Definition capability.h:282
L4::Cap::check_castable_from
static void check_castable_from() noexcept
Perform the type conversion that needs to compile in order for a capability of type From te be castab...
Definition capability.h:264
L4::Cap::Cap
Cap(l4_default_caps_t cap) noexcept
Initialize capability with one of the default capability selectors.
Definition capability.h:288
L4::Cap::Cap
Cap(Cap< O > const &o) noexcept
Create a copy from o, supporting implicit type casting.
Definition capability.h:275
L4::Cap::move
Cap move(Cap const &src) const
Move a capability to this cap slot.
Definition capability.h:307
L4::Cap::check_convertible_from
static void check_convertible_from() noexcept
Perform the type conversion that needs to compile in order for a capability of type From to be conver...
Definition capability.h:251
L4::Kobject
Base class for all kinds of kernel objects and remote objects, referenced by capabilities.
Definition kobject:37
L4::Task
C++ interface of the Task kernel object, see Task for the C interface.
Definition task:36
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
l4_default_caps_t
l4_default_caps_t
Default capabilities setup for the initial tasks.
Definition consts.h:325
L4_BASE_TASK_CAP
@ L4_BASE_TASK_CAP
Capability selector for the current task.
Definition consts.h:327
L4_INVALID_CAP
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:153
l4_obj_fpage
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flexpage.
Definition __l4_fpage.h:715
L4_CAP_FPAGE_RWSD
@ L4_CAP_FPAGE_RWSD
Full rights for capability flexpages.
Definition __l4_fpage.h:212
L4_CAP_FPAGE_RWS
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flexpages.
Definition __l4_fpage.h:206
l4_map_obj_control
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item that is a send item for the object space.
Definition __l4_fpage.h:749
L4_MAP_ITEM_GRANT
@ L4_MAP_ITEM_GRANT
Flag as grant instead of map operation.
Definition consts.h:245
L4_MAP_ITEM_MAP
@ L4_MAP_ITEM_MAP
Flag as usual map operation.
Definition consts.h:247
L4_FPAGE_C_OBJ_RIGHTS
@ L4_FPAGE_C_OBJ_RIGHTS
All Object-type specific right bits.
Definition __l4_fpage.h:270
l4_task_map
l4_msgtag_t l4_task_map(l4_cap_idx_t dst_task, l4_cap_idx_t src_task, l4_fpage_t snd_fpage, l4_umword_t snd_base) L4_NOTHROW
Map resources available in the source task to a destination task.
Definition task.h:433
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4_EXPORT
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:214
consts.h
Common constants.
task.h
Common task related definitions.
types.h
Common L4 ABI Data Types.
L4
L4 low-level kernel interface.
Definition l4sys-l4f-groups.dox:50
L4::cap_reinterpret_cast
Cap< T > cap_reinterpret_cast(Cap< F > const &c) noexcept
reinterpret_cast for capabilities.
Definition capability.h:447
L4::cap_cast
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
Definition capability.h:416
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_fpage_t
L4 flexpage type.
Definition __l4_fpage.h:76