L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
capability.h
1
2#pragma once
3
4#include <l4/sys/consts.h>
5#include <l4/sys/types.h>
6#include <l4/sys/task.h>
7
8namespace L4 {
9
10class Task;
11class Kobject;
12
13template< typename T > class L4_EXPORT Cap;
14
26{
27private:
28 struct Invalid_conversion;
29
30public:
33 {
37 No_init
38 };
39
44 {
45 Invalid = L4_INVALID_CAP
46 };
47
52 l4_cap_idx_t cap() const noexcept { return _c; }
53
60 bool is_valid() const noexcept { return !(_c & L4_INVALID_CAP_BIT); }
61
62 operator Invalid_conversion * () const noexcept
63 { return (Invalid_conversion*)(!(_c & L4_INVALID_CAP_BIT)); }
64
72 l4_fpage_t fpage(unsigned rights = L4_CAP_FPAGE_RWS) const noexcept
73 { return l4_obj_fpage(_c, 0, rights); }
74
85 l4_cap_idx_t base = L4_INVALID_CAP) const noexcept
86 {
87 if (base == L4_INVALID_CAP)
88 base = _c;
89 return l4_map_obj_control(base, grant);
90 }
91
92
96 bool operator == (Cap_base const &o) const noexcept
97 { return _c == o._c; }
98
102 bool operator != (Cap_base const &o) const noexcept
103 { return _c != o._c; }
104
118 inline l4_msgtag_t validate(l4_utcb_t *u = l4_utcb()) const noexcept;
119
134 inline l4_msgtag_t validate(Cap<Task> task,
135 l4_utcb_t *u = l4_utcb()) const noexcept;
136
140 void invalidate() noexcept { _c = L4_INVALID_CAP; }
141protected:
147 explicit Cap_base(l4_cap_idx_t c) noexcept : _c(c) {}
151 explicit Cap_base(Cap_type cap) noexcept : _c(cap) {}
152
158 explicit Cap_base(l4_default_caps_t cap) noexcept : _c(cap) {}
159
163 explicit Cap_base() noexcept {}
164
174 void move(Cap_base const &src) const
175 {
176 if (!is_valid() || !src.is_valid())
177 return;
178
181 }
182
190 void copy(Cap_base const &src) const
191 {
192 if (!is_valid() || !src.is_valid())
193 return;
194
196 snd_base() | L4_FPAGE_C_OBJ_RIGHTS);
197 }
198
202};
203
204
220template< typename T >
221class L4_EXPORT Cap : public Cap_base
222{
223private:
224 friend class L4::Kobject;
225
237 explicit Cap(T const *p) noexcept
238 : Cap_base(reinterpret_cast<l4_cap_idx_t>(p)) {}
239
240public:
241
246 template< typename O >
247 Cap(Cap<O> const &o) noexcept : Cap_base(o.cap())
248 { T* __t = ((O*)100); (void)__t; }
249
254 Cap(Cap_type cap) noexcept : Cap_base(cap) {}
255
260 Cap(l4_default_caps_t cap) noexcept : Cap_base(cap) {}
261
266 explicit Cap(l4_cap_idx_t idx = L4_INVALID_CAP) noexcept : Cap_base(idx) {}
267
271 explicit Cap(No_init_type) noexcept {}
272
279 Cap move(Cap const &src) const
280 {
281 Cap_base::move(src);
282 return *this;
283 }
284
289 Cap copy(Cap const &src) const
290 {
291 Cap_base::copy(src);
292 return *this;
293 }
294
298 T *operator -> () const noexcept { return reinterpret_cast<T*>(_c); }
299};
300
301
312template<>
313class L4_EXPORT Cap<void> : public Cap_base
314{
315public:
316
317 explicit Cap(void const *p) noexcept
318 : Cap_base(reinterpret_cast<l4_cap_idx_t>(p)) {}
319
323 Cap(Cap_type cap) noexcept : Cap_base(cap) {}
324
329 Cap(l4_default_caps_t cap) noexcept : Cap_base(cap) {}
330
335 explicit Cap(l4_cap_idx_t idx = L4_INVALID_CAP) noexcept : Cap_base(idx) {}
336 explicit Cap(No_init_type) noexcept {}
337
344 Cap move(Cap const &src) const
345 {
346 Cap_base::move(src);
347 return *this;
348 }
349
354 Cap copy(Cap const &src) const
355 {
356 Cap_base::copy(src);
357 return *this;
358 }
359
360 template< typename T >
361 Cap(Cap<T> const &o) noexcept : Cap_base(o.cap()) {}
362};
363
380template< typename T, typename F >
381inline
382Cap<T> cap_cast(Cap<F> const &c) noexcept
383{
384 (void)static_cast<T const *>(reinterpret_cast<F const *>(100));
385 return Cap<T>(c.cap());
386}
387
388// gracefully deal with L4::Kobject ambiguity
389template< typename T >
390inline
391Cap<T> cap_cast(Cap<L4::Kobject> const &c) noexcept
392{
393 return Cap<T>(c.cap());
394}
395
411template< typename T, typename F >
412inline
414{
415 return Cap<T>(c.cap());
416}
417
418}
Base class for all kinds of capabilities.
Definition capability.h:26
void copy(Cap_base const &src) const
Copy a capability.
Definition capability.h:190
Cap_base(l4_default_caps_t cap) noexcept
Initialize capability with one of the default capabilities.
Definition capability.h:158
Cap_base(Cap_type cap) noexcept
Constructor to create an invalid capability.
Definition capability.h:151
l4_fpage_t fpage(unsigned rights=L4_CAP_FPAGE_RWS) const noexcept
Return flex-page for the capability.
Definition capability.h:72
l4_cap_idx_t _c
The C representation of a capability selector.
Definition capability.h:201
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:52
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:60
void move(Cap_base const &src) const
Replace this capability with the contents of src.
Definition capability.h:174
Cap_type
Invalid capability type.
Definition capability.h:44
No_init_type
Special value for uninitialized capability objects.
Definition capability.h:33
Cap_base(l4_cap_idx_t c) noexcept
Generate a capability from its C representation.
Definition capability.h:147
Cap_base() noexcept
Create an uninitialized instance.
Definition capability.h:163
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:84
C++ interface for capabilities.
Definition capability.h:222
Cap copy(Cap const &src) const
Copy a capability to this cap slot.
Definition capability.h:289
Cap(l4_cap_idx_t idx=L4_INVALID_CAP) noexcept
Initialize capability, defaults to the invalid capability selector.
Definition capability.h:266
Cap(No_init_type) noexcept
Create an uninitialized cap selector.
Definition capability.h:271
Cap(Cap_type cap) noexcept
Constructor to create an invalid capability selector.
Definition capability.h:254
Cap(l4_default_caps_t cap) noexcept
Initialize capability with one of the default capability selectors.
Definition capability.h:260
Cap(Cap< O > const &o) noexcept
Create a copy from o, supporting implicit type casting.
Definition capability.h:247
Cap move(Cap const &src) const
Move a capability to this cap slot.
Definition capability.h:279
Base class for all kinds of kernel objects and remote objects, referenced by capabilities.
Definition kobject:47
C++ interface of the Task kernel object, see Task for the C interface.
Definition task:47
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:358
l4_default_caps_t
Default capabilities setup for the initial tasks.
Definition consts.h:314
@ L4_BASE_TASK_CAP
Capability selector for the current task.
Definition consts.h:316
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:168
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.
Definition __l4_fpage.h:680
@ L4_FPAGE_C_OBJ_RIGHTS
All Object-type specific right bits.
Definition __l4_fpage.h:271
@ L4_CAP_FPAGE_RWSD
Full rights for capability flex-pages.
Definition __l4_fpage.h:215
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flex-pages.
Definition __l4_fpage.h:209
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item for the object space.
Definition __l4_fpage.h:714
@ L4_MAP_ITEM_GRANT
Flag as grant instead of map operation.
Definition consts.h:257
@ L4_MAP_ITEM_MAP
Flag as usual map operation.
Definition consts.h:259
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:395
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:221
Common L4 ABI Data Types.
L4 low-level kernel interface.
Cap< T > cap_reinterpret_cast(Cap< F > const &c) noexcept
reinterpret_cast for capabilities.
Definition capability.h:413
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
Definition capability.h:382
Message tag data structure.
Definition types.h:163
L4 flexpage type.
Definition __l4_fpage.h:85