L4Re - L4 Runtime Environment
cap_alloc
Go to the documentation of this file.
1 // -*- Mode: C++ -*-
2 // vim:ft=cpp
7 /*
8  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9  * Alexander Warg <warg@os.inf.tu-dresden.de>
10  * economic rights: Technische Universität Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction. Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License. This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 
26 #pragma once
27 
29 #include <l4/sys/smart_capability>
30 #include <l4/sys/task>
31 #include <l4/re/consts>
32 
33 namespace L4Re { namespace Util {
34 
53 extern _Cap_alloc &cap_alloc;
54 
58 template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
60 {
61 public:
65  static void free(L4::Cap_base &c)
66  {
67  if (c.is_valid())
68  {
69  cap_alloc.free(L4::Cap<void>(c.cap()), This_task, Unmap_flags);
70  c.invalidate();
71  }
72  }
73 
77  static void invalidate(L4::Cap_base &c)
78  {
79  if (c.is_valid())
80  c.invalidate();
81  }
82 
86  static L4::Cap_base copy(L4::Cap_base const &src)
87  {
88  L4::Cap_base r = src;
89  invalidate(const_cast<L4::Cap_base &>(src));
90  return r;
91  }
92 };
93 
94 
98 template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
100 {
101 public:
106  static void free(L4::Cap_base &c) throw()
107  {
108  if (c.is_valid())
109  {
110  if (cap_alloc.release(L4::Cap<void>(c.cap()), This_task, Unmap_flags))
111  c.invalidate();
112  }
113  }
114 
118  static void invalidate(L4::Cap_base &c) throw()
119  {
120  if (c.is_valid())
121  c.invalidate();
122  }
123 
127  static L4::Cap_base copy(L4::Cap_base const &src)
128  {
129  cap_alloc.take(L4::Cap<void>(src.cap()));
130  return src;
131  }
132 };
133 
134 
162 template< typename T >
163 struct Auto_cap
164 {
166 } L4_DEPRECATED("use L4Re::Util::Unique_cap");
167 
199 template< typename T >
201 {
203 } L4_DEPRECATED("use L4Re::Util::Unique_cap");
204 
234 template< typename T >
235 struct Ref_cap
236 {
238 };
239 
275 template< typename T >
277 {
279 };
280 
288 #pragma GCC diagnostic push
289 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
290 template< typename T >
291 typename Auto_cap<T>::Cap
292 L4_DEPRECATED("use make_unique_cap")
294 { return typename Auto_cap<T>::Cap(cap_alloc.alloc<T>()); }
295 
303 template< typename T >
304 typename Auto_del_cap<T>::Cap
306 { return typename Auto_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
307 #pragma GCC diagnostic pop
308 
314 template< typename T >
315 typename Ref_cap<T>::Cap
316 make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
317 
323 template< typename T >
324 typename Ref_del_cap<T>::Cap
326 { return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
327 
330 }}
331 
Smart capability class.
static void free(L4::Cap_base &c)
Free operation for L4::Smart_cap.
Definition: cap_alloc:65
Automatic capability that implements automatic free and unmap of the capability selector.
Definition: cap_alloc:163
L4::Capability class.
Automatic capability that implements automatic free and unmap of the capability selector.
Definition: cap_alloc:235
Constants.
Helper for Ref_cap and Ref_del_cap.
Definition: cap_alloc:99
Auto_del_cap< T >::Cap make_auto_del_cap()
Allocate a capability slot and wrap it in an Auto_del_cap.
Definition: cap_alloc:305
L4Re C++ Interfaces.
Definition: cmd_control:15
Common task related definitions.
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap (increment ref count).
Definition: cap_alloc:127
static void invalidate(L4::Cap_base &c)
Invalidate operation for L4::Smart_cap.
Definition: cap_alloc:77
Auto_cap< T >::Cap make_auto_cap()
Allocate a capability slot and wrap it in an Auto_cap.
Definition: cap_alloc:293
Helper for Auto_cap and Auto_del_cap.
Definition: cap_alloc:59
void invalidate()
Set this capability to invalid (L4_INVALID_CAP).
Definition: capability.h:137
static void free(L4::Cap_base &c)
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition: cap_alloc:106
l4_cap_idx_t cap() const
Return capability selector.
Definition: capability.h:52
_Cap_alloc & cap_alloc
Capability allocator.
Automatic capability that implements automatic free and unmap+delete of the capability selector...
Definition: cap_alloc:200
Base class for all kinds of capabilities.
Definition: capability.h:25
bool is_valid() const
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition: capability.h:60
Ref_del_cap< T >::Cap make_ref_del_cap()
Allocate a capability slot and wrap it in a Ref_del_cap.
Definition: cap_alloc:325
static void invalidate(L4::Cap_base &c)
Invalidate operation for L4::Smart_cap.
Definition: cap_alloc:118
Capability allocator implementation.
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition: cap_alloc:316
C++ interface for capabilities.
Definition: capability.h:13
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap.
Definition: cap_alloc:86
Automatic capability that implements automatic free and unmap+delete of the capability selector...
Definition: cap_alloc:276
#define L4_DEPRECATED(s)
Mark symbol deprecated.
Definition: compiler.h:239