L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cap_alloc_impl.h
Go to the documentation of this file.
1// -*- Mode: C++ -*-
2// vim:ft=cpp
7/*
8 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
9 * economic rights: Technische Universität Dresden (Germany)
10 *
11 * License: see LICENSE.spdx (in this directory or the directories above)
12 */
13
14#pragma once
15
16#include <l4/bid_config.h>
17#include <l4/re/cap_alloc>
18
19#if defined(CONFIG_L4RE_BITMAP_CAP_ALLOC)
20
22
23namespace L4Re { namespace Util {
24
25using _Cap_alloc_impl = Cap_alloc_base;
26
27}}
28
29#elif defined(CONFIG_L4RE_COUNTING_CAP_ALLOC)
30
32#include <l4/re/util/debug>
33
34namespace L4Re { namespace Util {
35
36// RISC-V does not natively support subword atomics, such as __atomic_load_1.
37// The RISC-V gcc developers have decided to emulate these via libatomic, which
38// is automatically linked against.
39#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(ARCH_arm) || defined(ARCH_riscv)
40using _Cap_alloc_impl
41 = Counting_cap_alloc<L4Re::Util::Counter_atomic<unsigned char>,
42 L4Re::Util::Dbg>;
43#elif defined(ARCH_sparc)
44using _Cap_alloc_impl
45 = Counting_cap_alloc<L4Re::Util::Counter<unsigned char>,
46 L4Re::Util::Dbg>;
47#warning "Thread-safe capability allocator not available!"
48#else
49#error "Unsupported platform"
50#endif
51
52}}
53
54#else
55#error "No supported capability allocator selected"
56#endif
57
58namespace L4Re { namespace Util {
59
66class _Cap_alloc final : public L4Re::Cap_alloc, private _Cap_alloc_impl
67{
68public:
69 template <unsigned COUNT>
70 using Storage = _Cap_alloc_impl::Storage<COUNT>;
71
72 using _Cap_alloc_impl::_Cap_alloc_impl; // Expose underlying constructor
73 void operator delete(void *) {} // Prevent global operator delete reference
74
75 L4::Cap<void> alloc() noexcept override
76 { return _Cap_alloc_impl::alloc(); }
77
78 template< typename T >
79 L4::Cap<T> alloc() noexcept
80 { return L4::cap_cast<T>(alloc()); }
81
82 void take(L4::Cap<void> cap) noexcept override
83 { _Cap_alloc_impl::take(cap); }
84
86 unsigned unmap_flags = L4_FP_ALL_SPACES) noexcept override
87 { _Cap_alloc_impl::free(cap, task, unmap_flags); }
88
89 bool release(L4::Cap<void> cap, l4_cap_idx_t task,
90 unsigned unmap_flags) noexcept override
91 { return _Cap_alloc_impl::release(cap, task, unmap_flags); }
92
93 using _Cap_alloc_impl::last;
94};
95
96}}
Bitmap capability allocator.
Abstract capability-allocator interface.
Capability allocator interface.
Definition cap_alloc:31
Adapter to expose the cap allocator implementation as L4Re::Cap_alloc compatible class.
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.
L4::Cap< T > alloc() noexcept
Allocate a capability.
C++ interface for capabilities.
Definition capability.h:219
Reference-counting capability allocator.
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:157
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to revoke permissions from all child mappings including the mapping ...
Definition consts.h:187
L4Re C++ Interfaces.
Definition cmd_control:14