16namespace L4 {
namespace Detail {
18template<
typename T,
typename IMPL >
19class Smart_cap_base :
public Cap_base,
protected IMPL
23 static IMPL &impl(Smart_cap_base<X, IMPL> &o) {
return o; }
26 static IMPL
const &impl(Smart_cap_base<X, IMPL>
const &o) {
return o; }
29 template<
typename X,
typename I>
30 friend class ::L4::Detail::Smart_cap_base;
32 Smart_cap_base(Smart_cap_base
const &) =
delete;
33 Smart_cap_base &operator = (Smart_cap_base
const &) =
delete;
42 explicit constexpr Smart_cap_base(Cap<O> c) noexcept
47 explicit constexpr Smart_cap_base(Cap<O> c, IMPL
const &impl) noexcept
51 Cap<T> release() noexcept
54 IMPL::invalidate(*
this);
61 IMPL::invalidate(*
this);
64 Cap<T> operator -> () const noexcept {
return Cap<T>(this->
cap()); }
65 Cap<T> get() const noexcept {
return Cap<T>(this->
cap()); }
66 ~Smart_cap_base() noexcept { IMPL::free(*
this); }
70template<
typename T,
typename IMPL >
71class Unique_cap_impl final :
public Smart_cap_base<T, IMPL>
74 using Base = Smart_cap_base<T, IMPL>;
78 Unique_cap_impl() noexcept = default;
80 Unique_cap_impl(Unique_cap_impl &&o) noexcept
81 : Base(o.release(), Base::impl(o))
85 Unique_cap_impl(Unique_cap_impl<O, IMPL> &&o) noexcept
86 : Base(o.release(), Base::impl(o))
87 { Cap<T>::template check_convertible_from<O>(); }
89 Unique_cap_impl &operator = (Unique_cap_impl &&o)
noexcept
95 this->
_c = o.release().cap();
96 this->IMPL::operator = (Base::impl(o));
101 Unique_cap_impl &operator = (Unique_cap_impl<O, IMPL> &&o)
noexcept
103 Cap<T>::template check_convertible_from<O>();
106 this->
_c = o.release().cap();
107 this->IMPL::operator = (Base::impl(o));
112template<
typename T,
typename IMPL>
113class Shared_cap_impl final :
public Smart_cap_base<T, IMPL>
116 using Base = Smart_cap_base<T, IMPL>;
120 Shared_cap_impl() noexcept = default;
122 Shared_cap_impl(Shared_cap_impl &&o) noexcept
123 : Base(o.release(), Base::impl(o))
127 Shared_cap_impl(Shared_cap_impl<O, IMPL> &&o) noexcept
128 : Base(o.release(), Base::impl(o))
129 { Cap<T>::template check_convertible_from<O>(); }
132 Shared_cap_impl(Shared_cap_impl<O, IMPL> &&o, Cap<T>
cap) noexcept
133 : Base(
cap, Base::impl(o))
136 Shared_cap_impl &operator = (Shared_cap_impl &&o)
noexcept
142 this->
_c = o.release().cap();
143 this->IMPL::operator = (Base::impl(o));
148 Shared_cap_impl &operator = (Shared_cap_impl<O, IMPL> &&o)
noexcept
150 Cap<T>::template check_convertible_from<O>();
153 this->
_c = o.release().cap();
154 this->IMPL::operator = (Base::impl(o));
158 Shared_cap_impl(Shared_cap_impl
const &o) noexcept
161 this->IMPL::operator = (Base::impl(o));
162 this->
_c = IMPL::copy(o).cap();
166 Shared_cap_impl(Shared_cap_impl<O, IMPL>
const &o) noexcept
169 Cap<T>::template check_convertible_from<O>();
170 this->IMPL::operator = (Base::impl(o));
171 this->
_c = IMPL::copy(o).cap();
175 Shared_cap_impl(Shared_cap_impl<O, IMPL>
const &o, Cap<T>
cap) noexcept
178 this->IMPL::operator = (Base::impl(o));
179 this->
_c = IMPL::copy(
cap).cap();
182 Shared_cap_impl &operator = (Shared_cap_impl
const &o)
noexcept
188 this->IMPL::operator = (
static_cast<IMPL
const &
>(o));
189 this->
_c = this->IMPL::copy(o).cap();
194 Shared_cap_impl &operator = (Shared_cap_impl<O, IMPL>
const &o)
noexcept
196 Cap<T>::template check_convertible_from<O>();
198 this->IMPL::operator = (
static_cast<IMPL
const &
>(o));
199 this->
_c = this->IMPL::copy(o).cap();
L4::Cap related definitions.
l4_cap_idx_t _c
The C representation of a capability selector.
l4_cap_idx_t cap() const noexcept
Return capability selector.
Cap_type
Invalid capability type.
@ Invalid
Invalid capability selector.
Cap_base(l4_cap_idx_t c) noexcept
Generate a capability from its C representation.
Cap_base() noexcept
Create an uninitialized instance.
unsigned long l4_cap_idx_t
Capability selector type.
L4 low-level kernel interface.