Loading...
Searching...
No Matches
cap_alloc
Go to the documentation of this file.
// -*- Mode: C++ -*-
// vim:ft=cpp
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/re/util/cap_alloc_impl.h>
#include <l4/sys/smart_capability>
#include <l4/sys/task>
#include <l4/re/consts>
namespace L4Re { namespace Util {
extern _Cap_alloc &cap_alloc;
template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
class Smart_cap_auto
{
public:
static void free(L4::Cap_base &c)
{
if (c.is_valid())
{
cap_alloc.free(L4::Cap<void>(c.cap()), This_task, Unmap_flags);
c.invalidate();
}
}
static void invalidate(L4::Cap_base &c)
{
if (c.is_valid())
c.invalidate();
}
};
template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
class Smart_count_cap
{
public:
static void free(L4::Cap_base &c) noexcept
{
if (c.is_valid())
{
if (cap_alloc.release(L4::Cap<void>(c.cap()), This_task, Unmap_flags))
c.invalidate();
}
}
static void invalidate(L4::Cap_base &c) noexcept
{
if (c.is_valid())
c.invalidate();
}
static L4::Cap_base copy(L4::Cap_base const &src)
{
cap_alloc.take(L4::Cap<void>(src.cap()));
return src;
}
};
template< typename T >
struct Ref_cap
{
typedef L4::Smart_cap<T, Smart_count_cap<L4_FP_ALL_SPACES> > Cap;
};
template< typename T >
struct Ref_del_cap
{
typedef L4::Smart_cap<T, Smart_count_cap<L4_FP_DELETE_OBJ> > Cap;
};
template< typename T >
typename Ref_cap<T>::Cap
make_ref_cap() { return typename Ref_cap<T>::Cap(cap_alloc.alloc<T>()); }
template< typename T >
typename Ref_del_cap<T>::Cap
make_ref_del_cap()
{ return typename Ref_del_cap<T>::Cap(cap_alloc.alloc<T>()); }
}}
cap_alloc_impl.h
Capability allocator implementation.
L4Re::Util::Smart_cap_auto
Helper for Unique_cap and Unique_del_cap.
Definition cap_alloc:46
L4Re::Util::Smart_cap_auto::invalidate
static void invalidate(L4::Cap_base &c)
Invalidate the provided capability.
Definition cap_alloc:63
L4Re::Util::Smart_cap_auto::free
static void free(L4::Cap_base &c)
Free the provided capability.
Definition cap_alloc:51
L4Re::Util::Smart_count_cap
Helper for Ref_cap and Ref_del_cap.
Definition cap_alloc:77
L4Re::Util::Smart_count_cap::copy
static L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap (increment ref count).
Definition cap_alloc:104
L4Re::Util::Smart_count_cap::free
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
L4Re::Util::Smart_count_cap::invalidate
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:95
L4Re::Util::_Cap_alloc
Adapter to expose the cap allocator implementation as L4Re::Cap_alloc compatible class.
Definition cap_alloc_impl.h:67
L4::Cap_base
Base class for all kinds of capabilities.
Definition capability.h:26
L4::Cap_base::invalidate
void invalidate() noexcept
Set this capability to invalid (L4_INVALID_CAP).
Definition capability.h:142
L4::Cap_base::cap
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
L4::Cap_base::is_valid
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Smart_cap
Smart capability class.
Definition smart_capability:26
L4Re::Util::cap_alloc
_Cap_alloc & cap_alloc
Capability allocator.
L4Re::Util::make_ref_del_cap
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
L4Re::Util::make_ref_cap
Ref_cap< T >::Cap make_ref_cap()
Allocate a capability slot and wrap it in a Ref_cap.
Definition cap_alloc:195
L4Re::Util
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
consts
Constants.
smart_capability
L4::Capability class.
L4Re::Util::Ref_cap
Automatic capability that implements automatic free and unmap of the capability selector.
Definition cap_alloc:143
L4Re::Util::Ref_del_cap
Automatic capability that implements automatic free and unmap+delete of the capability selector.
Definition cap_alloc:184
task
Common task related definitions.