L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
13 */
14
15#pragma once
16
19#include <l4/sys/task>
20#include <l4/re/consts>
21
22namespace L4Re { namespace Util {
23
39extern _Cap_alloc &cap_alloc;
40
44template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
46{
47public:
51 static void free(L4::Cap_base &c)
52 {
53 if (c.is_valid())
54 {
55 cap_alloc.free(L4::Cap<void>(c.cap()), This_task, Unmap_flags);
56 c.invalidate();
57 }
58 }
59
63 static void invalidate(L4::Cap_base &c)
64 {
65 if (c.is_valid())
66 c.invalidate();
67 }
68
69};
70
71
75template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
77{
78public:
83 static void free(L4::Cap_base &c) noexcept
84 {
85 if (c.is_valid())
86 {
87 if (cap_alloc.release(L4::Cap<void>(c.cap()), This_task, Unmap_flags))
88 c.invalidate();
89 }
90 }
91
95 static void invalidate(L4::Cap_base &c) noexcept
96 {
97 if (c.is_valid())
98 c.invalidate();
99 }
100
104 static L4::Cap_base copy(L4::Cap_base const &src)
105 {
106 cap_alloc.take(L4::Cap<void>(src.cap()));
107 return src;
108 }
109};
110
111
141template< typename T >
146
182template< typename T >
187
193template< typename T >
194typename Ref_cap<T>::Cap
195make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
196
202template< typename T >
203typename Ref_del_cap<T>::Cap
205{ return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
206
209}}
210
Capability allocator implementation.
Helper for Unique_cap and Unique_del_cap.
Definition cap_alloc:46
static void invalidate(L4::Cap_base &c)
Invalidate the provided capability.
Definition cap_alloc:63
static void free(L4::Cap_base &c)
Free the provided capability.
Definition cap_alloc:51
Helper for Ref_cap and Ref_del_cap.
Definition cap_alloc:77
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap (increment ref count).
Definition cap_alloc:104
static void free(L4::Cap_base &c) noexcept
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition cap_alloc:83
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:95
L4::Cap< void > alloc() noexcept override
Allocate a capability.
void free(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept override
Free a capability.
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:204
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition cap_alloc:195
L4Re C++ Interfaces.
Definition cmd_control:14
Constants.
L4::Capability class.
Automatic capability that implements automatic free and unmap of the capability selector.
Definition cap_alloc:143
Automatic capability that implements automatic free and unmap+delete of the capability selector.
Definition cap_alloc:184
Common task related definitions.