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 * License: see LICENSE.spdx (in this directory or the directories above)
13 */
14
15#pragma once
16
18#include <l4/re/util/item_alloc>
20#include <l4/sys/task>
21#include <l4/re/consts>
22
23namespace L4Re { namespace Util {
24
30
31template<unsigned Num_caps>
32class Reply_cap_alloc final : public L4::Reply_cap_alloc
33{
34public:
35 static constexpr unsigned Capacity = Num_caps;
36
37 explicit Reply_cap_alloc(unsigned bias) noexcept
38 : _bias(bias)
39 {}
40
41 L4::Reply_cap alloc() noexcept override
42 {
43 if (long slot = _alloc.alloc(); slot >= 0) [[likely]]
44 {
45 auto idx = (static_cast<l4_cap_idx_t>(slot) + _bias) << L4_CAP_SHIFT;
46 return L4::Reply_cap(L4::Reply_cap_idx(idx), this);
47 }
48 else
49 return L4::Reply_cap();
50 }
51
52protected:
53 void free(L4::Reply_cap_idx cap) noexcept override
54 { _alloc.free((cap.cap() >> L4_CAP_SHIFT) - _bias); }
55
56private:
57 unsigned _bias;
58 Item_alloc<Capacity> _alloc;
59};
60
61using Def_reply_cap_alloc = Reply_cap_alloc<CONFIG_L4RE_CAP_DFL_ALLOCATOR_MAX>;
62
74
81extern Def_reply_cap_alloc reply_cap_alloc;
82
86template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
88{
89public:
93 static void free(L4::Cap_base &c)
94 {
95 if (c.is_valid())
96 {
97 cap_alloc.free(L4::Cap<void>(c.cap()), This_task, Unmap_flags);
98 c.invalidate();
99 }
100 }
101
105 static void invalidate(L4::Cap_base &c)
106 {
107 if (c.is_valid())
108 c.invalidate();
109 }
110
111};
112
113
117template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
119{
120public:
125 static void free(L4::Cap_base &c) noexcept
126 {
127 if (c.is_valid())
128 {
129 if (cap_alloc.release(L4::Cap<void>(c.cap()), This_task, Unmap_flags))
130 c.invalidate();
131 }
132 }
133
137 static void invalidate(L4::Cap_base &c) noexcept
138 {
139 if (c.is_valid())
140 c.invalidate();
141 }
142
146 static L4::Cap_base copy(L4::Cap_base const &src)
147 {
148 cap_alloc.take(L4::Cap<void>(src.cap()));
149 return src;
150 }
151};
152
153
183template< typename T >
188
224template< typename T >
229
235template< typename T >
236typename Ref_cap<T>::Cap
237make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
238
244template< typename T >
245typename Ref_del_cap<T>::Cap
247{ return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
248
250
251}}
252
Capability allocator implementation.
Helper for Unique_cap and Unique_del_cap.
Definition cap_alloc:88
static void invalidate(L4::Cap_base &c)
Invalidate the provided capability.
Definition cap_alloc:105
static void free(L4::Cap_base &c)
Free the provided capability.
Definition cap_alloc:93
Helper for Ref_cap and Ref_del_cap.
Definition cap_alloc:119
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap (increment ref count).
Definition cap_alloc:146
static void free(L4::Cap_base &c) noexcept
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition cap_alloc:125
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:137
Adapter to expose the cap allocator implementation as L4Re::Cap_alloc compatible class.
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:142
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:224
virtual Reply_cap alloc() noexcept=0
Allocate new reply capability slot.
Smart capability class.
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:357
#define L4_CAP_SHIFT
Capability index shift.
Definition consts.h:137
Def_reply_cap_alloc reply_cap_alloc
Reply capability allocator.
_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:246
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition cap_alloc:237
Item allocator.
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
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:185
Automatic capability that implements automatic free and unmap+delete of the capability selector.
Definition cap_alloc:226
Common task related definitions.