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) noexcept
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) noexcept
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 
164 template< typename T >
165 struct Ref_cap
166 {
168 };
169 
205 template< typename T >
207 {
209 };
210 
216 template< typename T >
217 typename Ref_cap<T>::Cap
218 make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
219 
225 template< typename T >
226 typename Ref_del_cap<T>::Cap
228 { return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
229 
232 }}
233 
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition: capability.h:52
Smart capability class.
Constants.
static void free(L4::Cap_base &c)
Free operation for L4::Smart_cap.
Definition: cap_alloc:65
L4::Capability class.
Automatic capability that implements automatic free and unmap of the capability selector.
Definition: cap_alloc:165
Helper for Ref_cap and Ref_del_cap.
Definition: cap_alloc:99
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
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition: cap_alloc:118
Helper for Unique_cap and Unique_del_cap.
Definition: cap_alloc:59
_Cap_alloc & cap_alloc
Capability allocator.
Base class for all kinds of capabilities.
Definition: capability.h:25
bool is_valid() const noexcept
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:227
Capability allocator implementation.
void invalidate() noexcept
Set this capability to invalid (L4_INVALID_CAP).
Definition: capability.h:137
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition: cap_alloc:218
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:206
static void free(L4::Cap_base &c) noexcept
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition: cap_alloc:106