L4Re - L4 Runtime Environment
capability
Go to the documentation of this file.
1 // vim:set ft=cpp: -*- Mode: C++ -*-
9 /*
10  * (c) 2008-2009,2015 Author(s)
11  * economic rights: Technische Universit├Ąt Dresden (Germany)
12  *
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU General Public License 2.
15  * Please see the COPYING-GPL-2 file for details.
16  *
17  * As a special exception, you may use this file as part of a free software
18  * library without restriction. Specifically, if other files instantiate
19  * templates or use macros or inline functions from this file, or you compile
20  * this file and link it with other files to produce an executable, this
21  * file does not by itself cause the resulting executable to be covered by
22  * the GNU General Public License. This exception does not however
23  * invalidate any other reasons why the executable file might be covered by
24  * the GNU General Public License.
25  */
26 #pragma once
27 
28 #include <l4/sys/consts.h>
29 #include <l4/sys/types.h>
30 #include <l4/sys/kobject>
31 #include <l4/sys/task.h>
32 
33 namespace L4
34 {
35 
36 /* Forward declarations for our kernel object classes. */
37 class Task;
38 class Thread;
39 class Factory;
40 class Irq;
41 class Log;
42 class Vm;
43 class Kobject;
44 
60 #if __cplusplus >= 201103L
61 # define L4_DISABLE_COPY(_class) \
62  public: \
63  _class(_class const &) = delete; \
64  _class operator = (_class const &) = delete; \
65  private:
66 #else
67 # define L4_DISABLE_COPY(_class) \
68  private: \
69  _class(_class const &); \
70  _class operator = (_class const &);
71 #endif
72 
73 
74 #define L4_KOBJECT_DISABLE_COPY(_class) \
75  protected: \
76  _class(); \
77  L4_DISABLE_COPY(_class)
78 
79 
80 #define L4_KOBJECT(_class) L4_KOBJECT_DISABLE_COPY(_class)
81 
82 inline l4_msgtag_t
83 Cap_base::validate(Cap<Task> task, l4_utcb_t *u) const noexcept
84 {
85  return is_valid() ? l4_task_cap_valid_u(task.cap(), _c, u)
86  : l4_msgtag(0, 0, 0, 0);
87 }
88 
89 inline l4_msgtag_t
90 Cap_base::validate(l4_utcb_t *u) const noexcept
91 {
92  return is_valid() ? l4_task_cap_valid_u(L4_BASE_TASK_CAP, _c, u)
93  : l4_msgtag(0, 0, 0, 0);
94 }
95 
96 }; // namespace L4
97 
98 #include <l4/sys/meta>
99 
100 namespace L4 {
101 
123 template< typename T, typename F >
124 inline
125 Cap<T> cap_dynamic_cast(Cap<F> const &c) noexcept
126 {
127  if (!c.is_valid())
128  return Cap<T>::Invalid;
129 
131  Type_info const *m = kobject_typeid<T>();
132  if (m->proto() && l4_error(mc->supports(m->proto())) > 0)
133  return Cap<T>(c.cap());
134 
135  // FIXME: use generic checker
136 #if 0
137  if (l4_error(mc->supports(T::kobject_proto())) > 0)
138  return Cap<T>(c.cap());
139 #endif
140 
141  return Cap<T>::Invalid;
142 }
143 
144 }
Cap< T > cap_dynamic_cast(Cap< F > const &c) noexcept
dynamic_cast for capabilities.
Definition: capability:125
Common L4 ABI Data Types.
l4_msgtag_t supports(l4_mword_t protocol)
Figure out if the object supports the given protocol (number).
l4_msgtag_t validate(l4_utcb_t *u=l4_utcb()) const noexcept
Check whether a capability is present (refers to an object).
Definition: capability:90
L4 low-level kernel interface.
Capability selector for the current task.
Definition: consts.h:243
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
Cap< T > cap_reinterpret_cast(Cap< F > const &c) noexcept
reinterpret_cast for capabilities.
Definition: capability.h:410
Meta interface that shall be implemented by each L4Re object and gives access to the dynamic type inf...
Definition: meta:37
Dynamic Type Information for L4Re Interfaces.
Definition: __typeinfo.h:509
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
Meta interface for getting dynamic type information about objects behind capabilities.
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag or the tag label.
Definition: ipc.h:520
C++ interface for capabilities.
Definition: capability.h:13
Message tag data structure.
Definition: types.h:159