L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
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
30#include <l4/sys/task>
31#include <l4/re/consts>
32
33namespace L4Re { namespace Util {
34
53extern _Cap_alloc &cap_alloc;
54
58template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
60{
61public:
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
98template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
100{
101public:
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
164template< typename T >
169
205template< typename T >
210
216template< typename T >
217typename Ref_cap<T>::Cap
218make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
219
225template< typename T >
226typename Ref_del_cap<T>::Cap
228{ return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
229
232}}
233
Capability allocator implementation.
Helper for Unique_cap and Unique_del_cap.
Definition cap_alloc:60
static void invalidate(L4::Cap_base &c)
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:77
static void free(L4::Cap_base &c)
Free operation for L4::Smart_cap.
Definition cap_alloc:65
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap.
Definition cap_alloc:86
Helper for Ref_cap and Ref_del_cap.
Definition cap_alloc:100
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 free(L4::Cap_base &c) noexcept
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition cap_alloc:106
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:118
Base class for all kinds of capabilities.
Definition capability.h:26
void invalidate() noexcept
Set this capability to invalid (L4_INVALID_CAP).
Definition capability.h:140
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
C++ interface for capabilities.
Definition capability.h:222
Smart capability class.
_Cap_alloc & cap_alloc
Capability allocator.
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
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition cap_alloc:218
L4Re C++ Interfaces.
Definition cmd_control:15
Constants.
L4::Capability class.
Automatic capability that implements automatic free and unmap of the capability selector.
Definition cap_alloc:166
Automatic capability that implements automatic free and unmap+delete of the capability selector.
Definition cap_alloc:207
Common task related definitions.