Loading...
Searching...
No Matches
cap_alloc
Go to the documentation of this file.
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 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/sys/task>
#include <l4/sys/smart_capability>
#include <l4/re/consts>
#include <l4/cxx/type_traits>
namespace L4Re {
class Cap_alloc
{
private:
void operator = (Cap_alloc const &);
protected:
Cap_alloc(Cap_alloc const &) {}
Cap_alloc() {}
public:
virtual L4::Cap<void> alloc() noexcept = 0;
virtual void take(L4::Cap<void> cap) noexcept = 0;
template< typename T >
L4::Cap<T> alloc() noexcept
{ return L4::cap_cast<T>(alloc()); }
virtual void free(L4::Cap<void> cap, l4_cap_idx_t task = L4_INVALID_CAP,
unsigned unmap_flags = L4_FP_ALL_SPACES) noexcept = 0;
virtual bool release(L4::Cap<void> cap, l4_cap_idx_t task = L4_INVALID_CAP,
unsigned unmap_flags = L4_FP_ALL_SPACES) noexcept = 0;
virtual ~Cap_alloc() = 0;
};
template<typename ALLOC>
struct Cap_alloc_t : ALLOC, L4Re::Cap_alloc
{
template<typename ...ARGS>
Cap_alloc_t(ARGS &&...args) : ALLOC(cxx::forward<ARGS>(args)...) {}
L4::Cap<void> alloc() noexcept override { return ALLOC::alloc(); }
void take(L4::Cap<void> cap) noexcept override { ALLOC::take(cap); }
template <typename T>
L4::Cap<T> alloc() noexcept
{
return L4::cap_cast<T>(alloc());
}
void free(L4::Cap<void> cap, l4_cap_idx_t task = L4_INVALID_CAP,
unsigned unmap_flags = L4_FP_ALL_SPACES) noexcept override
{ ALLOC::free(cap, task, unmap_flags); }
bool release(L4::Cap<void> cap, l4_cap_idx_t task,
unsigned unmap_flags) noexcept override
{ return ALLOC::release(cap, task, unmap_flags); }
void operator delete(void *) {}
};
inline
Cap_alloc::~Cap_alloc()
{}
extern Cap_alloc *virt_cap_alloc;
template< unsigned long Unmap_flags = L4_FP_ALL_SPACES >
class Smart_cap_auto
{
private:
Cap_alloc *_ca;
public:
Smart_cap_auto() : _ca(0) {}
Smart_cap_auto(Cap_alloc *ca) : _ca(ca) {}
void free(L4::Cap_base &c)
{
if (c.is_valid() && _ca)
_ca->free(L4::Cap<void>(c.cap()), This_task, Unmap_flags);
invalidate(c);
}
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
{
private:
Cap_alloc *_ca;
public:
Smart_count_cap() : _ca(nullptr) {}
Smart_count_cap(Cap_alloc *ca) : _ca(ca) {}
void free(L4::Cap_base &c) noexcept
{
if (c.is_valid())
{
if (_ca && _ca->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();
}
L4::Cap_base copy(L4::Cap_base const &src)
{
if (src.is_valid())
_ca->take(L4::Cap<void>(src.cap()));
return src;
}
};
}
L4Re::Cap_alloc
Capability allocator interface.
Definition cap_alloc:31
L4Re::Cap_alloc::alloc
virtual L4::Cap< void > alloc() noexcept=0
Allocate a capability.
L4Re::Cap_alloc::free
virtual void free(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept=0
Free a capability.
L4Re::Smart_count_cap::copy
L4::Cap_base copy(L4::Cap_base const &src)
Copy operation for L4::Smart_cap (increment ref count).
Definition cap_alloc:172
L4Re::Smart_count_cap::free
void free(L4::Cap_base &c) noexcept
Free operation for L4::Smart_cap (decrement ref count and delete if 0).
Definition cap_alloc:151
L4Re::Smart_count_cap::invalidate
static void invalidate(L4::Cap_base &c) noexcept
Invalidate operation for L4::Smart_cap.
Definition cap_alloc:163
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_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
L4_INVALID_CAP
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:153
L4_FP_ALL_SPACES
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to revoke permissions from all child mappings including the mapping ...
Definition consts.h:183
L4Re::Cap_alloc::~Cap_alloc
virtual ~Cap_alloc()=0
Destructor.
Definition cap_alloc:100
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4
L4 low-level kernel interface.
Definition l4sys-l4f-groups.dox:50
L4::cap_cast
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
Definition capability.h:416
consts
Constants.
smart_capability
L4::Capability class.
task
Common task related definitions.