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
50extern _Cap_alloc &cap_alloc;
51
55template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
57{
58public:
62 static void free(L4::Cap_base &c)
63 {
64 if (c.is_valid())
65 {
66 cap_alloc.free(L4::Cap<void>(c.cap()), This_task, Unmap_flags);
67 c.invalidate();
68 }
69 }
70
74 static void invalidate(L4::Cap_base &c)
75 {
76 if (c.is_valid())
77 c.invalidate();
78 }
79
80};
81
82
86template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
88{
89public:
94 static void free(L4::Cap_base &c) noexcept
95 {
96 if (c.is_valid())
97 {
98 if (cap_alloc.release(L4::Cap<void>(c.cap()), This_task, Unmap_flags))
99 c.invalidate();
100 }
101 }
102
106 static void invalidate(L4::Cap_base &c) noexcept
107 {
108 if (c.is_valid())
109 c.invalidate();
110 }
111
115 static L4::Cap_base copy(L4::Cap_base const &src)
116 {
117 cap_alloc.take(L4::Cap<void>(src.cap()));
118 return src;
119 }
120};
121
122
152template< typename T >
157
193template< typename T >
198
204template< typename T >
205typename Ref_cap<T>::Cap
206make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
207
213template< typename T >
214typename Ref_del_cap<T>::Cap
216{ return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
217
220}}
221
Capability allocator implementation.
Helper for Unique_cap and Unique_del_cap.
Definition cap_alloc:57
static void invalidate(L4::Cap_base &c)
Invalidate the provided capability.
Definition cap_alloc:74
static void free(L4::Cap_base &c)
Free the provided capability.
Definition cap_alloc:62
Helper for Ref_cap and Ref_del_cap.
Definition cap_alloc:88
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap (increment ref count).
Definition cap_alloc:115
static void free(L4::Cap_base &c) noexcept
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition cap_alloc:94
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:106
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:137
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
C++ interface for capabilities.
Definition capability.h:219
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:215
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition cap_alloc:206
L4Re C++ Interfaces.
Definition l4re.dox:17
Constants.
L4::Capability class.
Automatic capability that implements automatic free and unmap of the capability selector.
Definition cap_alloc:154
Automatic capability that implements automatic free and unmap+delete of the capability selector.
Definition cap_alloc:195
Common task related definitions.